old pointer deref operator completely removed

This commit is contained in:
Araq 2011-07-23 20:19:05 +02:00
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: of tokKeywordLow..tokKeywordHigh:
dispA(result, "<span class=\"Keyword\">$1</span>", "\\spanKeyword{$1}", dispA(result, "<span class=\"Keyword\">$1</span>", "\\spanKeyword{$1}",
[toRope(literal)]) [toRope(literal)])
of tkOpr, tkHat: of tkOpr:
dispA(result, "<span class=\"Operator\">$1</span>", "\\spanOperator{$1}", dispA(result, "<span class=\"Operator\">$1</span>", "\\spanOperator{$1}",
[toRope(esc(literal))]) [toRope(esc(literal))])
of tkStrLit..tkTripleStrLit: of tkStrLit..tkTripleStrLit:

View file

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

View file

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

View file

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

View file

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

View file

@ -301,7 +301,7 @@ proc analyse(c: PProcCtx, n: PNode): TThreadOwner =
# pointer deref or array 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 nkBind: result = analyse(c, n.sons[0])
of nkPar, nkCurly, nkBracket: of nkPar, nkCurly, nkBracket, nkRange:
# container construction: # container construction:
result = toNil # nothing until later result = toNil # nothing until later
for i in 0..n.len-1: aggregateOwner(result, analyse(c, n[i])) 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, wShl, wShr, wTemplate, wTry, wTuple, wType, wVar, wWhen, wWhile, wWith,
wWithout, wXor, wYield, wWithout, wXor, wYield,
wColon, wColonColon, wEquals, wDot, wDotDot, wHat, wStar, wMinus, wColon, wColonColon, wEquals, wDot, wDotDot, wStar, wMinus,
wMagic, wThread, wFinal, wProfiler, wObjChecks, wMagic, wThread, wFinal, wProfiler, wObjChecks,
wImportCompilerProc, wImportCompilerProc,
wImportc, wExportc, wExtern, wImportc, wExportc, wExtern,
@ -65,7 +65,7 @@ type
const const
oprLow* = ord(wColon) oprLow* = ord(wColon)
oprHigh* = ord(wHat) oprHigh* = ord(wDotDot)
specialWords*: array[low(TSpecialWord)..high(TSpecialWord), string] = ["", specialWords*: array[low(TSpecialWord)..high(TSpecialWord), string] = ["",
"addr", "and", "as", "asm", "atomic", "addr", "and", "as", "asm", "atomic",
@ -79,7 +79,7 @@ const
"try", "tuple", "type", "var", "when", "while", "with", "without", "xor", "try", "tuple", "type", "var", "when", "while", "with", "without", "xor",
"yield", "yield",
":", "::", "=", ".", "..", "^", "*", "-", ":", "::", "=", ".", "..", "*", "-",
"magic", "thread", "final", "profiler", "objchecks", "magic", "thread", "final", "profiler", "objchecks",
"importcompilerproc", "importc", "exportc", "extern", "importcompilerproc", "importc", "exportc", "extern",
"align", "nodecl", "pure", "volatile", "register", "sideeffect", "align", "nodecl", "pure", "volatile", "register", "sideeffect",

View file

@ -33,7 +33,6 @@ primaryPrefix ::= (prefixOperator | 'bind') optInd
primarySuffix ::= '.' optInd symbol [generalizedLit] primarySuffix ::= '.' optInd symbol [generalizedLit]
| '(' optInd namedExprList optPar ')' | '(' optInd namedExprList optPar ')'
| '[' optInd [indexExpr (comma indexExpr)* [comma]] optPar ']' | '[' optInd [indexExpr (comma indexExpr)* [comma]] optPar ']'
| '^'
| pragma | pragma
primary ::= primaryPrefix* (symbol [generalizedLit] | 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 - ``var T`` as a return type; easy to prove that location does not escape its
stack frame stack frame
- document Nimrod's two phase symbol lookup for generics - document Nimrod's two phase symbol lookup for generics
- make ^ available as operator
- optional indentation for 'case' statement - optional indentation for 'case' statement
- make threadvar efficient again on linux after testing - make threadvar efficient again on linux after testing
- test the sort implementation again - test the sort implementation again

View file

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