version 0.8.6

This commit is contained in:
Andreas Rumpf
2009-12-22 01:28:20 +01:00
parent 9dda24e475
commit 2169fd63bd
34 changed files with 748 additions and 776 deletions

3
contributors.txt Normal file → Executable file
View File

@@ -1,4 +1,5 @@
Mario Ray Mahardhika
Philippe Lhoste
Alexander R<>dseth
Alexander R<>dseth
Jonathan Plona

View File

@@ -1111,7 +1111,7 @@ algorithm (in pseudo-code) determines type equality:
.. code-block:: nimrod
proc typeEqualsAux(a, b: PType,
s: var set[tuple[PType, PType]]): bool =
s: var set[PType * PType]): bool =
if (a,b) in s: return true
incl(s, (a,b))
if a.kind == b.kind:
@@ -1140,7 +1140,7 @@ algorithm (in pseudo-code) determines type equality:
a.callingConvention == b.callingConvention
proc typeEquals(a, b: PType): bool =
var s: set[tuple[PType, PType]] = {}
var s: set[PType * PType] = {}
result = typeEqualsAux(a, b, s)
Since types are graphs which can have cycles, the above algorithm needs an
@@ -1216,8 +1216,8 @@ algorithm returns true:
return false
Assignment compability
~~~~~~~~~~~~~~~~~~~~~~
Assignment compatibility
~~~~~~~~~~~~~~~~~~~~~~~~
An expression ``b`` can be assigned to an expression ``a`` iff ``a`` is an
`l-value` and ``isImplicitlyConvertible(b.typ, a.typ)`` holds.
@@ -1727,23 +1727,26 @@ Procedures
What most programming languages call `methods`:idx: or `functions`:idx: are
called `procedures`:idx: in Nimrod (which is the correct terminology). A
procedure declaration defines an identifier and associates it with a block
of code. A procedure may call itself recursively. The syntax is::
of code.
A procedure may call itself recursively. A parameter may be given a default
value that is used if the caller does not provide a value for this parameter.
The syntax is::
param ::= symbol (comma symbol)* [comma] ':' typeDesc
paramList ::= ['(' [param (comma param)* [comma]] ')'] [':' typeDesc]
param ::= symbol (comma symbol)* (':' typeDesc ['=' expr] | '=' expr)
paramList ::= ['(' [param (comma param)*] optPar ')'] [':' typeDesc]
genericParam ::= symbol [':' typeDesc]
genericParams ::= '[' genericParam (comma genericParam)* [comma] ']'
genericParam ::= symbol [':' typeDesc] ['=' expr]
genericParams ::= '[' genericParam (comma genericParam)* optPar ']'
routineDecl := symbol ['*'] [genericParams] paramList [pragma] ['=' stmt]
procDecl ::= 'proc' routineDecl
procDecl ::= 'proc' symbol ['*'] [genericParams] paramList [pragma]
['=' stmt]
If the ``= stmt`` part is missing, it is a `forward`:idx: declaration. If
the proc returns a value, the procedure body can access an implicit declared
the proc returns a value, the procedure body can access an implicitly declared
variable named `result`:idx: that represents the return value. Procs can be
overloaded. The overloading resolution algorithm tries to find the proc that is
the best match for the arguments. A parameter may be given a default value that
is used if the caller does not provide a value for this parameter. Example:
the best match for the arguments. Example:
.. code-block:: nimrod
@@ -1785,7 +1788,7 @@ type `var`).
Operators with one parameter are prefix operators, operators with two
parameters are infix operators. (However, the parser distinguishes these from
the operators position within an expression.) There is no way to declare
the operator's position within an expression.) There is no way to declare
postfix operators: all postfix operators are built-in and handled by the
grammar explicitly.

File diff suppressed because it is too large Load Diff

View File

@@ -79,7 +79,6 @@ const
bootOptions = "" # options to pass to the bootstrap process
proc findStartNimrod: string =
const buildScript = "build.sh"
# we try several things before giving up:
# * bin/nimrod
# * $PATH/nimrod
@@ -95,6 +94,7 @@ proc findStartNimrod: string =
result = "bin" / "nim".exe
if ExistsFile(result): return
when defined(Posix):
const buildScript = "build.sh"
if ExistsFile(buildScript):
if tryExec("./" & buildScript): return "bin" / nimrod
@@ -102,16 +102,20 @@ proc findStartNimrod: string =
echo("Found no nimrod compiler and every attempt to build one failed!")
quit("FAILURE")
proc safeRemove(filename: string) =
if existsFile(filename): removeFile(filename)
proc bootIteration(args: string): bool =
var nimrod1 = "rod" / "nimrod1".exe
moveFile nimrod1, "rod" / "nimrod".exe
safeRemove(nimrod1)
moveFile(nimrod1, "rod" / "nimrod".exe)
exec "rod" / "nimrod1 cc $# $# rod/nimrod.nim" % [bootOptions, args]
# Nimrod does not produce an executable again if nothing changed. That's ok:
result = sameFileContent("rod" / "nimrod".exe, nimrod1)
if result:
moveFile "bin" / "nimrod".exe, "rod" / "nimrod".exe
echo "executables are equal: SUCCESS!"
removeFile nimrod1
safeRemove("bin" / "nimrod".exe)
copyFile("bin" / "nimrod".exe, "rod" / "nimrod".exe)
safeRemove(nimrod1)
if result: echo "executables are equal: SUCCESS!"
proc boot(args: string) =
echo "iteration: 1"

View File

@@ -370,6 +370,6 @@ proc getCookie*(name: string): string =
proc existsCookie*(name: string): bool =
## Checks if a cookie of `name` exists.
if cookies == nil: cookies = parseCookies(getHttpCookie())
result = hasKey(cookies)
result = hasKey(cookies, name)

View File

@@ -370,6 +370,7 @@ begin
while x <> nil do begin
if sfResult in sym.flags then begin
result := x.params[0];
if result = nil then result := emptyNode;
exit
end;
result := IdNodeTableGet(x.mapping, sym);

7
rod/ast.nim Normal file → Executable file
View File

@@ -355,8 +355,6 @@ type
sym*: PSym
of nkIdent:
ident*: PIdent
of nkMetaNode:
nodePtr*: PNodePtr
else:
sons*: TNodeSeq
@@ -885,7 +883,6 @@ proc copyNode(src: PNode): PNode =
of nkSym: result.sym = src.sym
of nkIdent: result.ident = src.ident
of nkStrLit..nkTripleStrLit: result.strVal = src.strVal
of nkMetaNode: result.nodePtr = src.nodePtr
else: nil
proc copyTree(src: PNode): PNode =
@@ -902,7 +899,6 @@ proc copyTree(src: PNode): PNode =
of nkSym: result.sym = src.sym
of nkIdent: result.ident = src.ident
of nkStrLit..nkTripleStrLit: result.strVal = src.strVal
of nkMetaNode: result.nodePtr = src.nodePtr
else:
result.sons = nil
newSons(result, sonsLen(src))
@@ -1018,8 +1014,7 @@ proc IntSetEnlarge(t: var TIntSet) =
swap(t.data, n)
proc IntSetPut(t: var TIntSet, key: int): PTrunk =
var h: int
h = key and t.max
var h = key and t.max
while t.data[h] != nil:
if t.data[h].key == key:
return t.data[h]

0
rod/ccgexprs.nim Normal file → Executable file
View File

0
rod/cgen.nim Normal file → Executable file
View File

0
rod/condsyms.nim Normal file → Executable file
View File

209
rod/evals.nim Normal file → Executable file
View File

@@ -84,7 +84,10 @@ proc stackTrace(c: PEvalContext, n: PNode, msg: TMsgKind, arg: string = "") =
liMessage(n.info, msg, arg)
proc isSpecial(n: PNode): bool =
result = (n.kind == nkExceptBranch) or (n.kind == nkEmpty)
result = (n.kind == nkExceptBranch)
# or (n.kind == nkEmpty)
# XXX this does not work yet! Better to compile too much than to compile to
# few programs
proc evalIf(c: PEvalContext, n: PNode): PNode =
var i = 0
@@ -131,7 +134,7 @@ proc evalWhile(c: PEvalContext, n: PNode): PNode =
if result.sons[0] == nil:
result = emptyNode # consume ``break`` token
break
of nkExceptBranch, nkReturnToken, nkEmpty:
of nkExceptBranch, nkReturnToken:
break
else:
nil
@@ -247,7 +250,7 @@ proc evalCall(c: PEvalContext, n: PNode): PNode =
if n.typ != nil: d.params[0] = getNullValue(n.typ, n.info)
pushStackFrame(c, d)
result = evalAux(c, prc)
if isSpecial(result): return
if result.kind == nkExceptBranch: return
if n.typ != nil: result = d.params[0]
popStackFrame(c)
@@ -257,7 +260,9 @@ proc evalVariable(c: PStackFrame, sym: PSym): PNode =
var x = c
while x != nil:
if sfResult in sym.flags:
return x.params[0]
result = x.params[0]
if result == nil: result = emptyNode
return
result = IdNodeTableGet(x.mapping, sym)
if result != nil: return
x = x.next
@@ -289,14 +294,11 @@ proc evalFieldAccess(c: PEvalContext, n: PNode): PNode =
# a real field access; proc calls have already been
# transformed
# XXX: field checks!
var
x: PNode
field: PSym
result = evalAux(c, n.sons[0])
if isSpecial(result): return
x = result
var x = result
if x.kind != nkPar: InternalError(n.info, "evalFieldAccess")
field = n.sons[1].sym
var field = n.sons[1].sym
for i in countup(0, sonsLen(n) - 1):
if x.sons[i].kind != nkExprColonExpr:
InternalError(n.info, "evalFieldAccess")
@@ -306,10 +308,9 @@ proc evalFieldAccess(c: PEvalContext, n: PNode): PNode =
result = emptyNode
proc evalAsgn(c: PEvalContext, n: PNode): PNode =
var x: PNode
result = evalAux(c, n.sons[0])
if isSpecial(result): return
x = result
var x = result
result = evalAux(c, n.sons[1])
if isSpecial(result): return
x.kind = result.kind
@@ -328,15 +329,9 @@ proc evalAsgn(c: PEvalContext, n: PNode): PNode =
result = emptyNode
proc evalSwap(c: PEvalContext, n: PNode): PNode =
var
x: PNode
tmpi: biggestInt
tmpf: biggestFloat
tmps: string
tmpn: PNode
result = evalAux(c, n.sons[0])
if isSpecial(result): return
x = result
var x = result
result = evalAux(c, n.sons[1])
if isSpecial(result): return
if (x.kind != result.kind):
@@ -344,19 +339,19 @@ proc evalSwap(c: PEvalContext, n: PNode): PNode =
else:
case x.kind
of nkCharLit..nkInt64Lit:
tmpi = x.intVal
var tmpi = x.intVal
x.intVal = result.intVal
result.intVal = tmpi
of nkFloatLit..nkFloat64Lit:
tmpf = x.floatVal
var tmpf = x.floatVal
x.floatVal = result.floatVal
result.floatVal = tmpf
of nkStrLit..nkTripleStrLit:
tmps = x.strVal
var tmps = x.strVal
x.strVal = result.strVal
result.strVal = tmps
else:
tmpn = copyTree(x)
var tmpn = copyTree(x)
discardSons(x)
for i in countup(0, sonsLen(result) - 1): addSon(x, result.sons[i])
discardSons(result)
@@ -375,13 +370,12 @@ proc evalSym(c: PEvalContext, n: PNode): PNode =
if result == nil: stackTrace(c, n, errCannotInterpretNodeX, n.sym.name.s)
proc evalIncDec(c: PEvalContext, n: PNode, sign: biggestInt): PNode =
var a, b: PNode
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
case a.kind
of nkCharLit..nkInt64Lit: a.intval = a.intVal + sign * getOrdValue(b)
else: internalError(n.info, "evalIncDec")
@@ -466,16 +460,15 @@ proc evalUpConv(c: PEvalContext, n: PNode): PNode =
stackTrace(c, n, errInvalidConversionFromTypeX, typeToString(src))
proc evalRangeChck(c: PEvalContext, n: PNode): PNode =
var x, a, b: PNode
result = evalAux(c, n.sons[0])
if isSpecial(result): return
x = result
var x = result
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
if leValueConv(a, x) and leValueConv(x, b):
result = x # a <= x and x <= b
result.typ = n.typ
@@ -494,11 +487,10 @@ proc evalConvCStrToStr(c: PEvalContext, n: PNode): PNode =
result.typ = n.typ
proc evalRaise(c: PEvalContext, n: PNode): PNode =
var a: PNode
if n.sons[0] != nil:
result = evalAux(c, n.sons[0])
if isSpecial(result): return
a = result
var a = result
result = newNodeIT(nkExceptBranch, n.info, a.typ)
addSon(result, a)
c.lastException = result
@@ -516,14 +508,18 @@ proc evalReturn(c: PEvalContext, n: PNode): PNode =
result = newNodeIT(nkReturnToken, n.info, nil)
proc evalProc(c: PEvalContext, n: PNode): PNode =
var v: PSym
if n.sons[genericParamsPos] == nil:
if (resultPos < sonsLen(n)) and (n.sons[resultPos] != nil):
v = n.sons[resultPos].sym
var v = n.sons[resultPos].sym
result = getNullValue(v.typ, n.info)
IdNodeTablePut(c.tos.mapping, v, result)
result = evalAux(c, n.sons[codePos])
if result.kind == nkReturnToken: result = IdNodeTableGet(c.tos.mapping, v)
result = evalAux(c, n.sons[codePos])
if result.kind == nkReturnToken:
result = IdNodeTableGet(c.tos.mapping, v)
else:
result = evalAux(c, n.sons[codePos])
if result.kind == nkReturnToken:
result = emptyNode
else:
result = emptyNode
@@ -541,51 +537,42 @@ proc evalIs(c: PEvalContext, n: PNode): PNode =
result = newIntNodeT(ord(inheritanceDiff(result.typ, n.sons[2].typ) >= 0), n)
proc evalSetLengthStr(c: PEvalContext, n: PNode): PNode =
var
a, b: PNode
oldLen, newLen: int
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
case a.kind
of nkStrLit..nkTripleStrLit:
newLen = int(getOrdValue(b))
var newLen = int(getOrdValue(b))
setlen(a.strVal, newLen)
else: InternalError(n.info, "evalSetLengthStr")
result = emptyNode
proc evalSetLengthSeq(c: PEvalContext, n: PNode): PNode =
var
a, b: PNode
newLen, oldLen: int
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
if a.kind != nkBracket: InternalError(n.info, "evalSetLengthSeq")
newLen = int(getOrdValue(b))
oldLen = sonsLen(a)
var newLen = int(getOrdValue(b))
var oldLen = sonsLen(a)
setlen(a.sons, newLen)
for i in countup(oldLen, newLen - 1):
a.sons[i] = getNullValue(skipTypes(n.sons[1].typ, abstractVar), n.info)
result = emptyNode
proc evalNewSeq(c: PEvalContext, n: PNode): PNode =
var
a, b: PNode
t: PType
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
t = skipTypes(n.sons[1].typ, abstractVar)
var b = result
var t = skipTypes(n.sons[1].typ, abstractVar)
if a.kind == nkEmpty: InternalError(n.info, "first parameter is empty")
a.kind = nkBracket
a.info = n.info
@@ -601,38 +588,35 @@ proc evalAssert(c: PEvalContext, n: PNode): PNode =
else: stackTrace(c, n, errAssertionFailed)
proc evalIncl(c: PEvalContext, n: PNode): PNode =
var a, b: PNode
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
if not inSet(a, b): addSon(a, copyTree(b))
result = emptyNode
proc evalExcl(c: PEvalContext, n: PNode): PNode =
var a, b, r: PNode
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = newNodeIT(nkCurly, n.info, n.sons[1].typ)
var b = newNodeIT(nkCurly, n.info, n.sons[1].typ)
addSon(b, result)
r = diffSets(a, b)
var r = diffSets(a, b)
discardSons(a)
for i in countup(0, sonsLen(r) - 1): addSon(a, r.sons[i])
result = emptyNode
proc evalAppendStrCh(c: PEvalContext, n: PNode): PNode =
var a, b: PNode
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
case a.kind
of nkStrLit..nkTripleStrLit: add(a.strVal, chr(int(getOrdValue(b))))
else: InternalError(n.info, "evalAppendStrCh")
@@ -640,10 +624,9 @@ proc evalAppendStrCh(c: PEvalContext, n: PNode): PNode =
proc evalConStrStr(c: PEvalContext, n: PNode): PNode =
# we cannot use ``evalOp`` for this as we can here have more than 2 arguments
var a: PNode
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
for i in countup(2, sonsLen(n) - 1):
result = evalAux(c, n.sons[i])
if isSpecial(result): return
@@ -651,26 +634,24 @@ proc evalConStrStr(c: PEvalContext, n: PNode): PNode =
result = a
proc evalAppendStrStr(c: PEvalContext, n: PNode): PNode =
var a, b: PNode
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
case a.kind
of nkStrLit..nkTripleStrLit: a.strVal = a.strVal & getStrValue(b)
else: InternalError(n.info, "evalAppendStrStr")
result = emptyNode
proc evalAppendSeqElem(c: PEvalContext, n: PNode): PNode =
var a, b: PNode
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
if a.kind == nkBracket: addSon(a, copyTree(b))
else: InternalError(n.info, "evalAppendSeqElem")
result = emptyNode
@@ -684,11 +665,7 @@ proc isEmpty(n: PNode): bool =
result = (n != nil) and (n.kind == nkEmpty)
proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
var
m: TMagic
a, b, cc: PNode
k: biggestInt
m = getMagic(n)
var m = getMagic(n)
case m
of mNone: result = evalCall(c, n)
of mIs: result = evalIs(c, n)
@@ -714,7 +691,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNLen:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = newNodeIT(nkIntLit, n.info, n.typ)
case a.kind
of nkEmpty..nkNilLit:
@@ -723,10 +700,10 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNChild:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
k = getOrdValue(result)
var k = getOrdValue(result)
if not (a.kind in {nkEmpty..nkNilLit}) and (k >= 0) and (k < sonsLen(a)):
result = a.sons[int(k)]
if result == nil: result = newNode(nkEmpty)
@@ -736,13 +713,13 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNSetChild:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
result = evalAux(c, n.sons[3])
if isSpecial(result): return
k = getOrdValue(b)
var k = getOrdValue(b)
if (k >= 0) and (k < sonsLen(a)) and not (a.kind in {nkEmpty..nkNilLit}):
if result.kind == nkEmpty: a.sons[int(k)] = nil
else: a.sons[int(k)] = result
@@ -752,7 +729,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNAdd:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
addSon(a, result)
@@ -760,7 +737,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNAddMultiple:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
for i in countup(0, sonsLen(result) - 1): addSon(a, result.sons[i])
@@ -768,10 +745,10 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNDel:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
result = evalAux(c, n.sons[3])
if isSpecial(result): return
for i in countup(0, int(getOrdValue(result)) - 1):
@@ -780,13 +757,13 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNKind:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = newNodeIT(nkIntLit, n.info, n.typ)
result.intVal = ord(a.kind)
of mNIntVal:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = newNodeIT(nkIntLit, n.info, n.typ)
case a.kind
of nkCharLit..nkInt64Lit: result.intVal = a.intVal
@@ -794,7 +771,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNFloatVal:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = newNodeIT(nkFloatLit, n.info, n.typ)
case a.kind
of nkFloatLit..nkFloat64Lit: result.floatVal = a.floatVal
@@ -811,7 +788,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNStrVal:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = newNodeIT(nkStrLit, n.info, n.typ)
case a.kind
of nkStrLit..nkTripleStrLit: result.strVal = a.strVal
@@ -819,7 +796,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNSetIntVal:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
a.intVal = result.intVal # XXX: exception handling?
@@ -827,7 +804,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNSetFloatVal:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
a.floatVal = result.floatVal # XXX: exception handling?
@@ -835,7 +812,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNSetSymbol:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
a.sym = result.sym # XXX: exception handling?
@@ -843,7 +820,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNSetIdent:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
a.ident = result.ident # XXX: exception handling?
@@ -851,7 +828,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNSetType:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
a.typ = result.typ # XXX: exception handling?
@@ -859,7 +836,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNSetStrVal:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
a.strVal = result.strVal # XXX: exception handling?
@@ -867,14 +844,14 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNNewNimNode:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
k = getOrdValue(result)
var k = getOrdValue(result)
result = evalAux(c, n.sons[2])
if isSpecial(result): return
a = result
if result.kind == nkExceptBranch: return
var a = result
if (k < 0) or (k > ord(high(TNodeKind))):
internalError(n.info, "request to create a NimNode with invalid kind")
if a.kind == nkNilLit: result = newNodeI(TNodeKind(int(k)), n.info)
else: result = newNodeI(TNodeKind(int(k)), a.info)
result = newNodeI(TNodeKind(int(k)),
if a.kind == nkNilLit: n.info else: a.info)
of mNCopyNimNode:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
@@ -888,33 +865,33 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
if isSpecial(result): return
if not (result.kind in {nkStrLit..nkTripleStrLit}):
InternalError(n.info, "no string node")
a = result
var a = result
result = newNodeIT(nkIdent, n.info, n.typ)
result.ident = getIdent(a.strVal)
of mIdentToStr:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
if result.kind != nkIdent: InternalError(n.info, "no ident node")
a = result
var a = result
result = newNodeIT(nkStrLit, n.info, n.typ)
result.strVal = a.ident.s
of mEqIdent:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
result = newNodeIT(nkIntLit, n.info, n.typ)
if (a.kind == nkIdent) and (b.kind == nkIdent):
if a.ident.id == b.ident.id: result.intVal = 1
of mEqNimrodNode:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = evalAux(c, n.sons[2])
if isSpecial(result): return
b = result
var b = result
result = newNodeIT(nkIntLit, n.info, n.typ)
if (a == b) or
(b.kind in {nkNilLit, nkEmpty}) and (a.kind in {nkNilLit, nkEmpty}):
@@ -941,15 +918,15 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
of mNewString:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
var a = result
result = newNodeIT(nkStrLit, n.info, n.typ)
result.strVal = newString(int(getOrdValue(a)))
else:
result = evalAux(c, n.sons[1])
if isSpecial(result): return
a = result
b = nil
cc = nil
var a = result
var b: PNode = nil
var cc: PNode = nil
if sonsLen(n) > 2:
result = evalAux(c, n.sons[2])
if isSpecial(result): return
@@ -962,7 +939,6 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
else: result = evalOp(m, n, a, b, cc)
proc evalAux(c: PEvalContext, n: PNode): PNode =
var a: PNode
result = emptyNode
dec(gNestedEvals)
if gNestedEvals <= 0: stackTrace(c, n, errTooManyIterations)
@@ -974,14 +950,14 @@ proc evalAux(c: PEvalContext, n: PNode): PNode =
of nkCall, nkHiddenCallConv, nkMacroStmt, nkCommand, nkCallStrLit:
result = evalMagicOrCall(c, n)
of nkCurly, nkBracket, nkRange:
a = copyNode(n)
var a = copyNode(n)
for i in countup(0, sonsLen(n) - 1):
result = evalAux(c, n.sons[i])
if isSpecial(result): return
addSon(a, result)
result = a
of nkPar:
a = copyTree(n)
var a = copyTree(n)
for i in countup(0, sonsLen(n) - 1):
result = evalAux(c, n.sons[i].sons[1])
if isSpecial(result): return
@@ -1015,8 +991,7 @@ proc evalAux(c: PEvalContext, n: PNode): PNode =
result = evalAux(c, n.sons[i])
case result.kind
of nkExceptBranch, nkReturnToken, nkBreakStmt: break
else:
nil
else: nil
of nkProcDef, nkMethodDef, nkMacroDef, nkCommentStmt, nkPragma, nkTypeSection,
nkTemplateDef, nkConstSection, nkIteratorDef, nkConverterDef,
nkIncludeStmt, nkImportStmt, nkFromStmt:

View File

@@ -39,6 +39,7 @@ Files: "*.nim"
Files: "rod/readme.txt"
Files: "rod/nimrod.ini"
Files: "rod/nimrod.cfg"
Files: "rod/*.nim"
Files: "build/empty.txt"
Files: "bin/empty.txt"
Files: "nim/*.*"

0
rod/nimrod.nim Normal file → Executable file
View File

View File

@@ -15,6 +15,6 @@ const
defaultAsmMarkerSymbol* = '!'
VersionMajor* = 0
VersionMinor* = 8
VersionPatch* = 5
VersionPatch* = 6
VersionAsString* = $VersionMajor & "." & $VersionMinor & "." & $VersionPatch

0
rod/options.nim Normal file → Executable file
View File

0
rod/pbraces.nim Normal file → Executable file
View File

0
rod/pnimsyn.nim Normal file → Executable file
View File

0
rod/pragmas.nim Normal file → Executable file
View File

0
rod/rodread.nim Normal file → Executable file
View File

0
rod/rodwrite.nim Normal file → Executable file
View File

0
rod/sem.nim Normal file → Executable file
View File

0
rod/semdata.nim Normal file → Executable file
View File

0
rod/semfold.nim Normal file → Executable file
View File

View File

@@ -28,16 +28,16 @@ proc semWhen(c: PContext, n: PNode): PNode =
result = semStmt(c, it.sons[0]) # do not open a new scope!
else: illFormedAst(n)
if result == nil:
result = newNodeI(nkNilLit, n.info) # The ``when`` statement implements the mechanism for platform dependant
# code. Thus we try to ensure here consistent ID allocation after the
# ``when`` statement.
result = newNodeI(nkNilLit, n.info)
# The ``when`` statement implements the mechanism for platform dependant
# code. Thus we try to ensure here consistent ID allocation after the
# ``when`` statement.
IDsynchronizationPoint(200)
proc semIf(c: PContext, n: PNode): PNode =
var it: PNode
result = n
for i in countup(0, sonsLen(n) - 1):
it = n.sons[i]
var it = n.sons[i]
if it == nil: illFormedAst(n)
case it.kind
of nkElifBranch:
@@ -58,19 +58,17 @@ proc semDiscard(c: PContext, n: PNode): PNode =
n.sons[0] = semExprWithType(c, n.sons[0])
if n.sons[0].typ == nil: liMessage(n.info, errInvalidDiscard)
proc semBreakOrContinue(c: PContext, n: PNode): PNode =
var
s: PSym
x: PNode
proc semBreakOrContinue(c: PContext, n: PNode): PNode =
result = n
checkSonsLen(n, 1)
if n.sons[0] != nil:
var s: PSym
case n.sons[0].kind
of nkIdent: s = lookUp(c, n.sons[0])
of nkSym: s = n.sons[0].sym
else: illFormedAst(n)
if (s.kind == skLabel) and (s.owner.id == c.p.owner.id):
x = newSymNode(s)
var x = newSymNode(s)
x.info = n.info
incl(s.flags, sfUsed)
n.sons[0] = x
@@ -80,13 +78,12 @@ proc semBreakOrContinue(c: PContext, n: PNode): PNode =
liMessage(n.info, errInvalidControlFlowX, renderTree(n, {renderNoComments}))
proc semBlock(c: PContext, n: PNode): PNode =
var labl: PSym
result = n
Inc(c.p.nestedBlockCounter)
checkSonsLen(n, 2)
openScope(c.tab) # BUGFIX: label is in the scope of block!
if n.sons[0] != nil:
labl = newSymS(skLabel, n.sons[0], c)
var labl = newSymS(skLabel, n.sons[0], c)
addDecl(c, labl)
n.sons[0] = newSymNode(labl) # BUGFIX
n.sons[1] = semStmt(c, n.sons[1])
@@ -109,7 +106,8 @@ proc semAsm(con: PContext, n: PNode): PNode =
result = copyNode(n)
str = n.sons[1].strVal
if str == "":
liMessage(n.info, errEmptyAsm) # now parse the string literal and substitute symbols:
liMessage(n.info, errEmptyAsm)
# now parse the string literal and substitute symbols:
a = 0
while true:
b = strutils.find(str, marker, a)
@@ -143,18 +141,13 @@ proc semWhile(c: PContext, n: PNode): PNode =
closeScope(c.tab)
proc semCase(c: PContext, n: PNode): PNode =
var
length: int
covered: biggestint # for some types we count to check if all cases have been covered
chckCovered: bool
x: PNode
# check selector:
result = n
checkMinSonsLen(n, 2)
openScope(c.tab)
n.sons[0] = semExprWithType(c, n.sons[0])
chckCovered = false
covered = 0
var chckCovered = false
var covered: biggestint = 0
case skipTypes(n.sons[0].Typ, abstractVarRange).Kind
of tyInt..tyInt64, tyChar, tyEnum:
chckCovered = true
@@ -162,12 +155,12 @@ proc semCase(c: PContext, n: PNode): PNode =
nil
else: liMessage(n.info, errSelectorMustBeOfCertainTypes)
for i in countup(1, sonsLen(n) - 1):
x = n.sons[i]
var x = n.sons[i]
case x.kind
of nkOfBranch:
checkMinSonsLen(x, 2)
semCaseBranch(c, n, x, i, covered)
length = sonsLen(x)
var length = sonsLen(x)
x.sons[length - 1] = semStmtScope(c, x.sons[length - 1])
of nkElifBranch:
chckCovered = false
@@ -313,8 +306,9 @@ proc semVar(c: PContext, n: PNode): PNode =
if a.sons[length - 2] != nil: typ = semTypeNode(c, a.sons[length - 2], nil)
else: typ = nil
if a.sons[length - 1] != nil:
def = semExprWithType(c, a.sons[length - 1]) # BUGFIX: ``fitNode`` is needed here!
# check type compability between def.typ and typ:
def = semExprWithType(c, a.sons[length - 1])
# BUGFIX: ``fitNode`` is needed here!
# check type compability between def.typ and typ:
if (typ != nil): def = fitNode(c, typ, def)
else: typ = def.typ
else:
@@ -369,7 +363,8 @@ proc semConst(c: PContext, n: PNode): PNode =
v = semIdentWithPragma(c, skConst, a.sons[0], {})
if a.sons[1] != nil: typ = semTypeNode(c, a.sons[1], nil)
else: typ = nil
def = semAndEvalConstExpr(c, a.sons[2]) # check type compability between def.typ and typ:
def = semAndEvalConstExpr(c, a.sons[2])
# check type compability between def.typ and typ:
if (typ != nil):
def = fitRemoveHiddenConv(c, typ, def)
else:
@@ -397,7 +392,8 @@ proc semFor(c: PContext, n: PNode): PNode =
length = sonsLen(n)
openScope(c.tab)
if n.sons[length - 2].kind == nkRange:
checkSonsLen(n.sons[length - 2], 2) # convert ``in 3..5`` to ``in countup(3, 5)``
checkSonsLen(n.sons[length - 2], 2)
# convert ``in 3..5`` to ``in countup(3, 5)``
countupNode = newNodeI(nkCall, n.sons[length - 2].info)
countUp = StrTableGet(magicsys.systemModule.Tab, getIdent("countup"))
if (countUp == nil): liMessage(countupNode.info, errSystemNeeds, "countup")
@@ -431,32 +427,27 @@ proc semFor(c: PContext, n: PNode): PNode =
Dec(c.p.nestedLoopCounter)
proc semRaise(c: PContext, n: PNode): PNode =
var typ: PType
result = n
checkSonsLen(n, 1)
if n.sons[0] != nil:
n.sons[0] = semExprWithType(c, n.sons[0])
typ = n.sons[0].typ
var typ = n.sons[0].typ
if (typ.kind != tyRef) or (typ.sons[0].kind != tyObject):
liMessage(n.info, errExprCannotBeRaised)
proc semTry(c: PContext, n: PNode): PNode =
var
length: int
a: PNode
typ: PType
check: TIntSet
var check: TIntSet
result = n
checkMinSonsLen(n, 2)
n.sons[0] = semStmtScope(c, n.sons[0])
IntSetInit(check)
for i in countup(1, sonsLen(n) - 1):
a = n.sons[i]
var a = n.sons[i]
checkMinSonsLen(a, 1)
length = sonsLen(a)
var length = sonsLen(a)
if a.kind == nkExceptBranch:
for j in countup(0, length - 2):
typ = semTypeNode(c, a.sons[j], nil)
var typ = semTypeNode(c, a.sons[j], nil)
if typ.kind == tyRef: typ = typ.sons[0]
if (typ.kind != tyObject):
liMessage(a.sons[j].info, errExprCannotBeRaised)
@@ -465,26 +456,24 @@ proc semTry(c: PContext, n: PNode): PNode =
if IntSetContainsOrIncl(check, typ.id):
liMessage(a.sons[j].info, errExceptionAlreadyHandled)
elif a.kind != nkFinally:
illFormedAst(n) # last child of an nkExcept/nkFinally branch is a statement:
illFormedAst(n)
# last child of an nkExcept/nkFinally branch is a statement:
a.sons[length - 1] = semStmtScope(c, a.sons[length - 1])
proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
var
L: int
s: PSym
a, def: PNode
typ: PType
result = copyNode(n)
if n.kind != nkGenericParams: InternalError(n.info, "semGenericParamList")
for i in countup(0, sonsLen(n) - 1):
a = n.sons[i]
var a = n.sons[i]
if a.kind != nkIdentDefs: illFormedAst(n)
L = sonsLen(a)
def = a.sons[L - 1]
var L = sonsLen(a)
var def = a.sons[L - 1]
var typ: PType
if a.sons[L - 2] != nil: typ = semTypeNode(c, a.sons[L - 2], nil)
elif def != nil: typ = newTypeS(tyExpr, c)
else: typ = nil
for j in countup(0, L - 3):
var s: PSym
if (typ == nil) or (typ.kind == tyTypeDesc):
s = newSymS(skType, a.sons[j], c)
s.typ = newTypeS(tyGenericParam, c)
@@ -499,11 +488,10 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
addDecl(c, s)
proc addGenericParamListToScope(c: PContext, n: PNode) =
var a: PNode
if n.kind != nkGenericParams:
InternalError(n.info, "addGenericParamListToScope")
for i in countup(0, sonsLen(n) - 1):
a = n.sons[i]
var a = n.sons[i]
if a.kind != nkSym: internalError(a.info, "addGenericParamListToScope")
addDecl(c, a.sym)
@@ -512,8 +500,9 @@ proc SemTypeSection(c: PContext, n: PNode): PNode =
s: PSym
t, body: PType
a: PNode
result = n # process the symbols on the left side for the whole type section, before
# we even look at the type definitions on the right
result = n
# process the symbols on the left side for the whole type section, before
# we even look at the type definitions on the right
for i in countup(0, sonsLen(n) - 1):
a = n.sons[i]
if a.kind == nkCommentStmt: continue
@@ -528,7 +517,8 @@ proc SemTypeSection(c: PContext, n: PNode): PNode =
s.typ = newTypeS(tyForward, c)
s.typ.sym = s # process pragmas:
if a.sons[0].kind == nkPragmaExpr:
pragma(c, s, a.sons[0].sons[1], typePragmas) # add it here, so that recursive types are possible:
pragma(c, s, a.sons[0].sons[1], typePragmas)
# add it here, so that recursive types are possible:
addInterfaceDecl(c, s)
a.sons[0] = newSymNode(s)
for i in countup(0, sonsLen(n) - 1):
@@ -571,7 +561,8 @@ proc SemTypeSection(c: PContext, n: PNode): PNode =
a = n.sons[i]
if a.kind == nkCommentStmt: continue
if (a.sons[0].kind != nkSym): IllFormedAst(a)
s = a.sons[0].sym # compute the type's size and check for illegal recursions:
s = a.sons[0].sym
# compute the type's size and check for illegal recursions:
if a.sons[1] == nil:
if (a.sons[2] != nil) and
(a.sons[2].kind in {nkSym, nkIdent, nkAccQuoted}):
@@ -592,9 +583,8 @@ proc addParams(c: PContext, n: PNode) =
addDecl(c, n.sons[i].sym)
proc semBorrow(c: PContext, n: PNode, s: PSym) =
var b: PSym
# search for the correct alias:
b = SearchForBorrowProc(c, s, c.tab.tos - 2)
var b = SearchForBorrowProc(c, s, c.tab.tos - 2)
if b == nil:
liMessage(n.info, errNoSymbolToBorrowFromFound) # store the alias:
n.sons[codePos] = newSymNode(b)
@@ -605,9 +595,8 @@ proc sideEffectsCheck(c: PContext, s: PSym) =
liMessage(s.info, errXhasSideEffects, s.name.s)
proc addResult(c: PContext, t: PType, info: TLineInfo) =
var s: PSym
if t != nil:
s = newSym(skVar, getIdent("result"), getCurrOwner())
var s = newSym(skVar, getIdent("result"), getCurrOwner())
s.info = info
s.typ = t
incl(s.flags, sfResult)
@@ -619,14 +608,11 @@ proc addResultNode(c: PContext, n: PNode) =
if c.p.resultSym != nil: addSon(n, newSymNode(c.p.resultSym))
proc semLambda(c: PContext, n: PNode): PNode =
var
s: PSym
oldP: PProcCon
result = n
checkSonsLen(n, codePos + 1)
s = newSym(skProc, getIdent(":anonymous"), getCurrOwner())
var s = newSym(skProc, getIdent(":anonymous"), getCurrOwner())
s.info = n.info
oldP = c.p # restore later
var oldP = c.p # restore later
s.ast = n
n.sons[namePos] = newSymNode(s)
pushOwner(s)
@@ -660,7 +646,6 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
validPragmas: TSpecialWords): PNode =
var
s, proto: PSym
oldP: PProcCon
gp: PNode
result = n
checkSonsLen(n, codePos + 1)
@@ -670,7 +655,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
else:
s = semIdentVis(c, kind, n.sons[0], {})
n.sons[namePos] = newSymNode(s)
oldP = c.p # restore later
var oldP = c.p # restore later
if sfStar in s.flags: incl(s.flags, sfInInterface)
s.ast = n
pushOwner(s)
@@ -693,8 +678,9 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
if oldP.owner.kind != skModule:
s.typ.callConv = ccClosure
else:
s.typ.callConv = lastOptionEntry(c).defaultCC # add it here, so that recursive procs are possible:
# -2 because we have a scope open for parameters
s.typ.callConv = lastOptionEntry(c).defaultCC
# add it here, so that recursive procs are possible:
# -2 because we have a scope open for parameters
if kind in OverloadableSyms:
addInterfaceOverloadableSymAt(c, s, c.tab.tos - 2)
else:
@@ -745,12 +731,9 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
c.p = oldP # restore
proc semIterator(c: PContext, n: PNode): PNode =
var
t: PType
s: PSym
result = semProcAux(c, n, skIterator, iteratorPragmas)
s = result.sons[namePos].sym
t = s.typ
var s = result.sons[namePos].sym
var t = s.typ
if t.sons[0] == nil: liMessage(n.info, errXNeedsReturnType, "iterator")
if n.sons[codePos] == nil: liMessage(n.info, errImplOfXexpected, s.name.s)
@@ -762,43 +745,34 @@ proc semMethod(c: PContext, n: PNode): PNode =
result = semProcAux(c, n, skMethod, methodPragmas)
proc semConverterDef(c: PContext, n: PNode): PNode =
var
t: PType
s: PSym
if not isTopLevel(c): liMessage(n.info, errXOnlyAtModuleScope, "converter")
checkSonsLen(n, codePos + 1)
if n.sons[genericParamsPos] != nil:
liMessage(n.info, errNoGenericParamsAllowedForX, "converter")
result = semProcAux(c, n, skConverter, converterPragmas)
s = result.sons[namePos].sym
t = s.typ
var s = result.sons[namePos].sym
var t = s.typ
if t.sons[0] == nil: liMessage(n.info, errXNeedsReturnType, "converter")
if sonsLen(t) != 2: liMessage(n.info, errXRequiresOneArgument, "converter")
addConverter(c, s)
proc semMacroDef(c: PContext, n: PNode): PNode =
var
t: PType
s: PSym
checkSonsLen(n, codePos + 1)
if n.sons[genericParamsPos] != nil:
liMessage(n.info, errNoGenericParamsAllowedForX, "macro")
result = semProcAux(c, n, skMacro, macroPragmas)
s = result.sons[namePos].sym
t = s.typ
var s = result.sons[namePos].sym
var t = s.typ
if t.sons[0] == nil: liMessage(n.info, errXNeedsReturnType, "macro")
if sonsLen(t) != 2: liMessage(n.info, errXRequiresOneArgument, "macro")
if n.sons[codePos] == nil: liMessage(n.info, errImplOfXexpected, s.name.s)
proc evalInclude(c: PContext, n: PNode): PNode =
var
fileIndex: int
f: string
result = newNodeI(nkStmtList, n.info)
addSon(result, n) # the rodwriter needs include information!
for i in countup(0, sonsLen(n) - 1):
f = getModuleFile(n.sons[i])
fileIndex = includeFilename(f)
var f = getModuleFile(n.sons[i])
var fileIndex = includeFilename(f)
if IntSetContainsOrIncl(c.includedFiles, fileIndex):
liMessage(n.info, errRecursiveDependencyX, f)
addSon(result, semStmt(c, gIncludeFile(f)))
@@ -806,26 +780,23 @@ proc evalInclude(c: PContext, n: PNode): PNode =
proc semCommand(c: PContext, n: PNode): PNode =
result = semExpr(c, n)
if result.typ != nil: liMessage(n.info, errDiscardValue)
if result.typ != nil and result.typ.kind != tyStmt:
liMessage(n.info, errDiscardValue)
proc SemStmt(c: PContext, n: PNode): PNode =
const # must be last statements in a block:
LastBlockStmts = {nkRaiseStmt, nkReturnStmt, nkBreakStmt, nkContinueStmt}
var length: int
result = n
if n == nil: return
if nfSem in n.flags: return
case n.kind
of nkAsgn:
result = semAsgn(c, n)
of nkAsgn: result = semAsgn(c, n)
of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkMacroStmt, nkCallStrLit:
result = semCommand(c, n)
of nkEmpty, nkCommentStmt, nkNilLit:
nil
of nkBlockStmt:
result = semBlock(c, n)
of nkEmpty, nkCommentStmt, nkNilLit: nil
of nkBlockStmt: result = semBlock(c, n)
of nkStmtList:
length = sonsLen(n)
var length = sonsLen(n)
for i in countup(0, length - 1):
n.sons[i] = semStmt(c, n.sons[i])
if (n.sons[i].kind in LastBlockStmts):
@@ -834,50 +805,28 @@ proc SemStmt(c: PContext, n: PNode): PNode =
of nkPragma, nkCommentStmt, nkNilLit, nkEmpty:
nil
else: liMessage(n.sons[j].info, errStmtInvalidAfterReturn)
of nkRaiseStmt:
result = semRaise(c, n)
of nkVarSection:
result = semVar(c, n)
of nkConstSection:
result = semConst(c, n)
of nkTypeSection:
result = SemTypeSection(c, n)
of nkIfStmt:
result = SemIf(c, n)
of nkWhenStmt:
result = semWhen(c, n)
of nkDiscardStmt:
result = semDiscard(c, n)
of nkWhileStmt:
result = semWhile(c, n)
of nkTryStmt:
result = semTry(c, n)
of nkBreakStmt, nkContinueStmt:
result = semBreakOrContinue(c, n)
of nkForStmt:
result = semFor(c, n)
of nkCaseStmt:
result = semCase(c, n)
of nkReturnStmt:
result = semReturn(c, n)
of nkAsmStmt:
result = semAsm(c, n)
of nkYieldStmt:
result = semYield(c, n)
of nkPragma:
pragma(c, c.p.owner, n, stmtPragmas)
of nkIteratorDef:
result = semIterator(c, n)
of nkProcDef:
result = semProc(c, n)
of nkMethodDef:
result = semMethod(c, n)
of nkConverterDef:
result = semConverterDef(c, n)
of nkMacroDef:
result = semMacroDef(c, n)
of nkTemplateDef:
result = semTemplateDef(c, n)
of nkRaiseStmt: result = semRaise(c, n)
of nkVarSection: result = semVar(c, n)
of nkConstSection: result = semConst(c, n)
of nkTypeSection: result = SemTypeSection(c, n)
of nkIfStmt: result = SemIf(c, n)
of nkWhenStmt: result = semWhen(c, n)
of nkDiscardStmt: result = semDiscard(c, n)
of nkWhileStmt: result = semWhile(c, n)
of nkTryStmt: result = semTry(c, n)
of nkBreakStmt, nkContinueStmt: result = semBreakOrContinue(c, n)
of nkForStmt: result = semFor(c, n)
of nkCaseStmt: result = semCase(c, n)
of nkReturnStmt: result = semReturn(c, n)
of nkAsmStmt: result = semAsm(c, n)
of nkYieldStmt: result = semYield(c, n)
of nkPragma: pragma(c, c.p.owner, n, stmtPragmas)
of nkIteratorDef: result = semIterator(c, n)
of nkProcDef: result = semProc(c, n)
of nkMethodDef: result = semMethod(c, n)
of nkConverterDef: result = semConverterDef(c, n)
of nkMacroDef: result = semMacroDef(c, n)
of nkTemplateDef: result = semTemplateDef(c, n)
of nkImportStmt:
if not isTopLevel(c): liMessage(n.info, errXOnlyAtModuleScope, "import")
result = evalImport(c, n)

0
rod/transf.nim Normal file → Executable file
View File

0
rod/trees.nim Normal file → Executable file
View File

View File

@@ -12,8 +12,8 @@ var
proc testA() =
var p = 0
map(myData, lambda (x: int): int =
result = x + 1 shl (lambda (y: int): int =
map(myData, proc (x: int): int =
result = x + 1 shl (proc (y: int): int =
return y + p
)(0)
inc(p))

View File

@@ -1,3 +1,4 @@
import strutils
const
HelpText = """
@@ -9,7 +10,7 @@ const
Compiled at: $2, $3
Usage:
koch.py [options] command [options for command]
koch [options] command [options for command]
Options:
--force, -f, -B, -b forces rebuild
--help, -h shows this help and quits
@@ -23,4 +24,5 @@ Possible Commands:
""" % [NimrodVersion & repeatChar(44-len(NimrodVersion)),
CompileDate, CompileTime]
echo helpText

View File

@@ -1,10 +0,0 @@
type
TCardPts = enum
North, West, South, East
TCardPts2 = enum of TCardPts
N, W, S, E
# If I do:
var y = W
echo($y & "=" & $ord(y)) #OUT W=5

View File

@@ -61,11 +61,15 @@ for x, y in items([(1, 2), (3, 4), (6, 1), (5, 2)]):
echo x
echo y
proc simpleConst(): int = return 34
# test constant evaluation:
const
const
constEval3 = simpleConst()
constEval = "abc".contains('b')
constEval2 = fac(7)
echo(constEval3)
echo(constEval)
echo(constEval2)
echo(1.`+`(2))

View File

@@ -1,4 +1,6 @@
# Test method call syntax for iterators:
import strutils
const lines = """abc xyz"""
for x in lines.split():

View File

@@ -3,8 +3,8 @@
Here you can download the latest version of the Nimrod Compiler.
Please choose your platform:
* source-based installation: `<download/nimrod_0.8.2.zip>`_
* installer for Windows XP/Vista (i386): `<download/nimrod_0.8.2.exe>`_
* source-based installation: `<download/nimrod_0.8.6.zip>`_
* installer for Windows XP/Vista (i386): `<download/nimrod_0.8.6.exe>`_
(includes GCC and everything else you need)
The source-based installation has been tested on these systems:

View File

@@ -3,7 +3,7 @@ News
====
2009-XX-XX Version 0.8.6 released
2009-12-21 Version 0.8.6 released
=================================
Version 0.8.6 has been released! Get it `here <download.html>`_. The version
@@ -15,8 +15,6 @@ Bugfixes
--------
- The pragmas ``hint[X]:off`` and ``warning[X]:off`` now work.
- Method call syntax for iterators works again (``for x in lines.split()``).
- Many bugfixes concerning macro evaluation.
- Many bugfixes concerning compile-time evaluation.
- Fixed a typo in ``removeDir`` for POSIX that lead to an infinite recursion.
- The compiler now checks that module filenames are valid identifiers.
- Empty patterns for the ``dynlib`` pragma are now possible.
@@ -34,11 +32,12 @@ Additions
- Grammar/parser: ``SAD|IND`` is allowed before any kind of closing bracket.
This allows for more flexible source code formating.
- The compiler now uses a *bind* table for symbol lookup within a ``bind``
context. (See `<manual/#templates>`_ for details.)
context. (See `<manual.html#templates>`_ for details.)
- ``discard """my long comment"""`` is now optimized away.
- New ``--floatChecks: on|off`` switches and pragmas for better debugging
of floating point operations. (See
`<manual/#pre-defined-floating-point-types>`_ for details.)
`<manual.html#pre-defined-floating-point-types>`_ for details.)
- The manual has been improved. (Many thanks to Philippe Lhoste!)
Changes affecting backwards compatibility

View File

@@ -1,6 +1,9 @@
| `2009-12-21`:newsdate:
| Nimrod version 0.8.6 has been released!
Get it `here <./download.html>`_. Merry Christmas!
| `2009-10-21`:newsdate:
| Nimrod version 0.8.2 has been released!
Get it `here <./download.html>`_.
| `2009-09-12`:newsdate:
| Nimrod version 0.8.0 has been released!