old pointer deref operator completely removed

This commit is contained in:
Araq
2011-07-23 20:19:05 +02:00
parent 246b8d18a1
commit a6daf71520
12 changed files with 83 additions and 20 deletions

View File

@@ -339,7 +339,7 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) =
of tokKeywordLow..tokKeywordHigh:
dispA(result, "<span class=\"Keyword\">$1</span>", "\\spanKeyword{$1}",
[toRope(literal)])
of tkOpr, tkHat:
of tkOpr:
dispA(result, "<span class=\"Operator\">$1</span>", "\\spanOperator{$1}",
[toRope(esc(literal))])
of tkStrLit..tkTripleStrLit:

View File

@@ -49,7 +49,7 @@ type
tkCurlyDotLe, tkCurlyDotRi, # {. and .}
tkParDotLe, tkParDotRi, # (. and .)
tkComma, tkSemiColon, tkColon, tkColonColon, tkEquals, tkDot, tkDotDot,
tkHat, tkOpr, tkComment, tkAccent, tkInd, tkSad,
tkOpr, tkComment, tkAccent, tkInd, tkSad,
tkDed, # pseudo token types used by the source renderers:
tkSpaces, tkInfixOpr, tkPrefixOpr, tkPostfixOpr
TTokTypes* = set[TTokType]
@@ -74,7 +74,7 @@ const
"tkTripleStrLit", "tkGStrLit", "tkGTripleStrLit", "tkCharLit", "(",
")", "[", "]", "{", "}", "[.", ".]", "{.", ".}", "(.", ".)", ",", ";",
":", "::",
"=", ".", "..", "^", "tkOpr", "tkComment", "`", "[new indentation]",
"=", ".", "..", "tkOpr", "tkComment", "`", "[new indentation]",
"[same indentation]", "[dedentation]", "tkSpaces", "tkInfixOpr",
"tkPrefixOpr", "tkPostfixOpr"]

View File

@@ -450,11 +450,6 @@ proc primary(p: var TParser): PNode =
optInd(p, result)
addSon(result, parseSymbol(p))
result = parseGStrLit(p, result)
of tkHat:
var a = result
result = newNodeP(nkDerefExpr, p)
addSon(result, a)
getTok(p)
of tkBracketLe:
result = indexExprList(p, result)
else: break

View File

@@ -819,7 +819,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
gsub(g, n.sons[1])
of nkDerefExpr:
gsub(g, n.sons[0])
putWithSpace(g, tkHat, "^")
putWithSpace(g, tkOpr, "^")
# unfortunately this requires a space, because ^. would be only one operator
of nkAccQuoted:
put(g, tkAccent, "`")

View File

@@ -237,8 +237,8 @@ proc changeType(n: PNode, newType: PType) =
of nkPar:
if newType.kind != tyTuple:
InternalError(n.info, "changeType: no tuple type for constructor")
if newType.n == nil: InternalError(n.info, "changeType: no tuple fields")
if (sonsLen(n) > 0) and (n.sons[0].kind == nkExprColonExpr):
if newType.n == nil: nil
elif (sonsLen(n) > 0) and (n.sons[0].kind == nkExprColonExpr):
for i in countup(0, sonsLen(n) - 1):
var m = n.sons[i].sons[0]
if m.kind != nkSym:

View File

@@ -286,9 +286,9 @@ proc analyseOp(c: PProcCtx, n: PNode): TThreadOwner =
proc analyse(c: PProcCtx, n: PNode): TThreadOwner =
case n.kind
of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand,
of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand,
nkCallStrLit, nkHiddenCallConv:
result = analyseOp(c, n)
result = analyseOp(c, n)
of nkAsgn, nkFastAsgn:
analyseAssign(c, n)
result = toVoid
@@ -299,9 +299,9 @@ proc analyse(c: PProcCtx, n: PNode): TThreadOwner =
of nkDotExpr, nkBracketExpr, nkDerefExpr, nkHiddenDeref:
# field access:
# pointer deref or array access:
result = analyse(c, n.sons[0])
result = analyse(c, n.sons[0])
of nkBind: result = analyse(c, n.sons[0])
of nkPar, nkCurly, nkBracket:
of nkPar, nkCurly, nkBracket, nkRange:
# container construction:
result = toNil # nothing until later
for i in 0..n.len-1: aggregateOwner(result, analyse(c, n[i]))

View File

@@ -32,7 +32,7 @@ type
wShl, wShr, wTemplate, wTry, wTuple, wType, wVar, wWhen, wWhile, wWith,
wWithout, wXor, wYield,
wColon, wColonColon, wEquals, wDot, wDotDot, wHat, wStar, wMinus,
wColon, wColonColon, wEquals, wDot, wDotDot, wStar, wMinus,
wMagic, wThread, wFinal, wProfiler, wObjChecks,
wImportCompilerProc,
wImportc, wExportc, wExtern,
@@ -65,7 +65,7 @@ type
const
oprLow* = ord(wColon)
oprHigh* = ord(wHat)
oprHigh* = ord(wDotDot)
specialWords*: array[low(TSpecialWord)..high(TSpecialWord), string] = ["",
"addr", "and", "as", "asm", "atomic",
@@ -79,7 +79,7 @@ const
"try", "tuple", "type", "var", "when", "while", "with", "without", "xor",
"yield",
":", "::", "=", ".", "..", "^", "*", "-",
":", "::", "=", ".", "..", "*", "-",
"magic", "thread", "final", "profiler", "objchecks",
"importcompilerproc", "importc", "exportc", "extern",
"align", "nodecl", "pure", "volatile", "register", "sideeffect",

View File

@@ -33,7 +33,6 @@ primaryPrefix ::= (prefixOperator | 'bind') optInd
primarySuffix ::= '.' optInd symbol [generalizedLit]
| '(' optInd namedExprList optPar ')'
| '[' optInd [indexExpr (comma indexExpr)* [comma]] optPar ']'
| '^'
| pragma
primary ::= primaryPrefix* (symbol [generalizedLit] |

View File

@@ -0,0 +1,53 @@
# -*- nimrod -*-
import math
import os
import strutils
type TComplex = tuple[re, im: float]
proc `+` (a, b: TComplex): TComplex =
return (a.re + b.re, a.im + b.im)
proc `*` (a, b: TComplex): TComplex =
result.re = a.re * b.re - a.im * b.im
result.im = a.re * b.im + a.im * b.re
proc abs2 (a: TComplex): float =
return a.re * a.re + a.im * a.im
var size = parseInt (paramStr (1))
var bit = 128
var byteAcc = 0
stdout.writeln ("P4")
stdout.write ($size)
stdout.write (" ")
stdout.writeln ($size)
var fsize = float (size)
for y in 0 .. size-1:
var fy = 2.0 * float (y) / fsize - 1.0
for x in 0 .. size-1:
var z = (0.0, 0.0)
var c = (float (2*x) / fsize - 1.5, fy)
block iter:
for i in 0 .. 49:
z = z*z + c
if abs2 (z) >= 4.0:
break iter
byteAcc = byteAcc + bit
if bit > 1:
bit = bit div 2
else:
stdout.write (chr (byteAcc))
bit = 128
byteAcc = 0
if bit != 128:
stdout.write (chr (byteAcc))
bit = 128
byteAcc = 0

View File

@@ -0,0 +1,15 @@
discard """
output: "61, 125"
"""
proc `^` (a, b: int): int =
result = 1
for i in 1..b: result = result * a
var m = (0, 5)
var n = (56, 3)
m = (n[0] + m[1], m[1] ^ n[1])
echo m[0], ", ", m[1]

View File

@@ -4,7 +4,6 @@ Version 0.8.14
- ``var T`` as a return type; easy to prove that location does not escape its
stack frame
- document Nimrod's two phase symbol lookup for generics
- make ^ available as operator
- optional indentation for 'case' statement
- make threadvar efficient again on linux after testing
- test the sort implementation again

View File

@@ -25,6 +25,8 @@ Changes affecting backwards compatibility
``osproc.executeCommand``.
- Removed deprecated ``parseopt.init``, ``parseopt.getRestOfCommandLine``.
- Moved ``strutils.validEmailAddress`` to ``matchers.validEmailAddress``.
- The pointer dereference operator ``^`` has been removed, so that ``^``
can now be a user-defined operator.
Language Additions