Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
commit
4f22326b24
11 changed files with 32 additions and 34 deletions
|
|
@ -619,7 +619,7 @@ proc parseParamList(p: var TParser, retColon = true): PNode =
|
||||||
while true:
|
while true:
|
||||||
case p.tok.tokType #optInd(p, a);
|
case p.tok.tokType #optInd(p, a);
|
||||||
of tkSymbol, tkAccent:
|
of tkSymbol, tkAccent:
|
||||||
a = parseIdentColonEquals(p, {})
|
a = parseIdentColonEquals(p, {withBothOptional})
|
||||||
of tkParRi:
|
of tkParRi:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -918,7 +918,7 @@ proc semAsgn(c: PContext, n: PNode): PNode =
|
||||||
let nOrig = n.copyTree
|
let nOrig = n.copyTree
|
||||||
a = builtinFieldAccess(c, a, {efLValue})
|
a = builtinFieldAccess(c, a, {efLValue})
|
||||||
if a == nil:
|
if a == nil:
|
||||||
return propertyWriteAccess(c, n, nOrig, a)
|
return propertyWriteAccess(c, n, nOrig, n[0])
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
# a[i] = x
|
# a[i] = x
|
||||||
# --> `[]=`(a, i, x)
|
# --> `[]=`(a, i, x)
|
||||||
|
|
@ -1028,7 +1028,7 @@ proc semExpandToAst(c: PContext, n: PNode, magicSym: PSym,
|
||||||
|
|
||||||
# Preserve the magic symbol in order to be handled in evals.nim
|
# Preserve the magic symbol in order to be handled in evals.nim
|
||||||
n.sons[0] = newSymNode(magicSym, n.info)
|
n.sons[0] = newSymNode(magicSym, n.info)
|
||||||
n.typ = expandedSym.getReturnType
|
n.typ = getSysSym("PNimrodNode").typ # expandedSym.getReturnType
|
||||||
result = n
|
result = n
|
||||||
else:
|
else:
|
||||||
result = semDirectOp(c, n, flags)
|
result = semDirectOp(c, n, flags)
|
||||||
|
|
|
||||||
|
|
@ -523,8 +523,7 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
|
||||||
proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
prev: PType, kind: TSymKind): PType =
|
prev: PType, kind: TSymKind): PType =
|
||||||
var
|
var
|
||||||
def, res: PNode
|
res: PNode
|
||||||
typ: PType
|
|
||||||
cl: TIntSet
|
cl: TIntSet
|
||||||
checkMinSonsLen(n, 1)
|
checkMinSonsLen(n, 1)
|
||||||
result = newOrPrevType(tyProc, prev, c)
|
result = newOrPrevType(tyProc, prev, c)
|
||||||
|
|
@ -541,20 +540,18 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
if a.kind != nkIdentDefs: IllFormedAst(a)
|
if a.kind != nkIdentDefs: IllFormedAst(a)
|
||||||
checkMinSonsLen(a, 3)
|
checkMinSonsLen(a, 3)
|
||||||
var length = sonsLen(a)
|
var
|
||||||
if a.sons[length-2].kind != nkEmpty:
|
typ: PType = nil
|
||||||
|
def: PNode = nil
|
||||||
|
length = sonsLen(a)
|
||||||
|
hasType = a.sons[length-2].kind != nkEmpty
|
||||||
|
hasDefault = a.sons[length-1].kind != nkEmpty
|
||||||
|
|
||||||
|
if hasType:
|
||||||
typ = paramType(c, a.sons[length-2], genericParams, cl)
|
typ = paramType(c, a.sons[length-2], genericParams, cl)
|
||||||
#if matchType(typ, [(tyVar, 0)], tyGenericInvokation):
|
#if matchType(typ, [(tyVar, 0)], tyGenericInvokation):
|
||||||
# debug a.sons[length-2][0][1]
|
# debug a.sons[length-2][0][1]
|
||||||
else:
|
if hasDefault:
|
||||||
typ = nil
|
|
||||||
# consider:
|
|
||||||
# template T(x)
|
|
||||||
# it's wrong, but the parser might not generate a fatal error (when in
|
|
||||||
# 'check' mode for example), so we need to check again here:
|
|
||||||
if unlikely(a.sons[length-1].kind == nkEmpty): continue
|
|
||||||
|
|
||||||
if a.sons[length-1].kind != nkEmpty:
|
|
||||||
def = semExprWithType(c, a.sons[length-1])
|
def = semExprWithType(c, a.sons[length-1])
|
||||||
# check type compability between def.typ and typ:
|
# check type compability between def.typ and typ:
|
||||||
if typ == nil:
|
if typ == nil:
|
||||||
|
|
@ -565,15 +562,16 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
# proc sort[T](cmp: proc(a, b: T): int = cmp)
|
# proc sort[T](cmp: proc(a, b: T): int = cmp)
|
||||||
if not containsGenericType(typ):
|
if not containsGenericType(typ):
|
||||||
def = fitNode(c, typ, def)
|
def = fitNode(c, typ, def)
|
||||||
else:
|
if not (hasType or hasDefault):
|
||||||
def = ast.emptyNode
|
typ = newTypeS(tyExpr, c)
|
||||||
|
|
||||||
if skipTypes(typ, {tyGenericInst}).kind == tyEmpty: continue
|
if skipTypes(typ, {tyGenericInst}).kind == tyEmpty: continue
|
||||||
for j in countup(0, length-3):
|
for j in countup(0, length-3):
|
||||||
var arg = newSymS(skParam, a.sons[j], c)
|
var arg = newSymS(skParam, a.sons[j], c)
|
||||||
arg.typ = typ
|
arg.typ = typ
|
||||||
arg.position = counter
|
arg.position = counter
|
||||||
inc(counter)
|
inc(counter)
|
||||||
if def.kind != nkEmpty: arg.ast = copyTree(def)
|
if def != nil and def.kind != nkEmpty: arg.ast = copyTree(def)
|
||||||
if ContainsOrIncl(check, arg.name.id):
|
if ContainsOrIncl(check, arg.name.id):
|
||||||
LocalError(a.sons[j].info, errAttemptToRedefine, arg.name.s)
|
LocalError(a.sons[j].info, errAttemptToRedefine, arg.name.s)
|
||||||
addSon(result.n, newSymNode(arg))
|
addSon(result.n, newSymNode(arg))
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
# Hello world program
|
# Hello world program
|
||||||
|
|
||||||
echo "Hello World!"
|
echo "Hello World"
|
||||||
|
|
|
||||||
|
|
@ -194,15 +194,15 @@ proc lineinfo*(n: PNimrodNode): string {.magic: "NLineInfo".}
|
||||||
## returns the position the node appears in the original source file
|
## returns the position the node appears in the original source file
|
||||||
## in the form filename(line, col)
|
## in the form filename(line, col)
|
||||||
|
|
||||||
proc parseExpr*(s: string): expr {.magic: "ParseExprToAst".}
|
proc parseExpr*(s: string): PNimrodNode {.magic: "ParseExprToAst".}
|
||||||
## Compiles the passed string to its AST representation.
|
## Compiles the passed string to its AST representation.
|
||||||
## Expects a single expression.
|
## Expects a single expression.
|
||||||
|
|
||||||
proc parseStmt*(s: string): stmt {.magic: "ParseStmtToAst".}
|
proc parseStmt*(s: string): PNimrodNode {.magic: "ParseStmtToAst".}
|
||||||
## Compiles the passed string to its AST representation.
|
## Compiles the passed string to its AST representation.
|
||||||
## Expects one or more statements.
|
## Expects one or more statements.
|
||||||
|
|
||||||
proc getAst*(macroOrTemplate: expr): expr {.magic: "ExpandToAst".}
|
proc getAst*(macroOrTemplate: expr): PNimrodNode {.magic: "ExpandToAst".}
|
||||||
## Obtains the AST nodes returned from a macro or template invocation.
|
## Obtains the AST nodes returned from a macro or template invocation.
|
||||||
## Example:
|
## Example:
|
||||||
##
|
##
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ template fail* =
|
||||||
|
|
||||||
macro check*(conditions: stmt): stmt =
|
macro check*(conditions: stmt): stmt =
|
||||||
proc standardRewrite(e: PNimrodNode): PNimrodNode =
|
proc standardRewrite(e: PNimrodNode): PNimrodNode =
|
||||||
template rewrite(Exp, lineInfoLit: expr, expLit: string): PNimrodNode =
|
template rewrite(Exp, lineInfoLit: expr, expLit: string): stmt =
|
||||||
if not Exp:
|
if not Exp:
|
||||||
checkpoint(lineInfoLit & ": Check failed: " & expLit)
|
checkpoint(lineInfoLit & ": Check failed: " & expLit)
|
||||||
fail()
|
fail()
|
||||||
|
|
@ -107,7 +107,7 @@ macro check*(conditions: stmt): stmt =
|
||||||
of nnkInfix:
|
of nnkInfix:
|
||||||
proc rewriteBinaryOp(op: PNimrodNode): PNimrodNode =
|
proc rewriteBinaryOp(op: PNimrodNode): PNimrodNode =
|
||||||
template rewrite(op, left, right, lineInfoLit: expr, opLit,
|
template rewrite(op, left, right, lineInfoLit: expr, opLit,
|
||||||
leftLit, rightLit: string, printLhs, printRhs: bool): PNimrodNode =
|
leftLit, rightLit: string, printLhs, printRhs: bool): stmt =
|
||||||
block:
|
block:
|
||||||
var
|
var
|
||||||
lhs = left
|
lhs = left
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ const
|
||||||
IDLE_EVENTS* = 1 shl 5 # WAS 0x10 ???? *
|
IDLE_EVENTS* = 1 shl 5 # WAS 0x10 ???? *
|
||||||
ALL_EVENTS* = not DONT_WAIT
|
ALL_EVENTS* = not DONT_WAIT
|
||||||
VOLATILE* = 1
|
VOLATILE* = 1
|
||||||
STATIC* = 0
|
TCL_STATIC* = 0
|
||||||
DYNAMIC* = 3 # Channel
|
DYNAMIC* = 3 # Channel
|
||||||
TCL_STDIN* = 1 shl 1
|
TCL_STDIN* = 1 shl 1
|
||||||
TCL_STDOUT* = 1 shl 2
|
TCL_STDOUT* = 1 shl 2
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ template plus(a, b: expr): expr =
|
||||||
a + b
|
a + b
|
||||||
|
|
||||||
macro call(e: expr): expr =
|
macro call(e: expr): expr =
|
||||||
return newCall("foo", newStrLitNode("bar"))
|
result = newCall("foo", newStrLitNode("bar"))
|
||||||
|
|
||||||
macro dumpAST(n: stmt): stmt =
|
macro dumpAST(n: stmt): stmt =
|
||||||
# dump AST as a side-effect and return the inner node
|
# dump AST as a side-effect and return the inner node
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ macro formatStyleInterpolation(e: expr): expr =
|
||||||
proc addString(s: string) =
|
proc addString(s: string) =
|
||||||
formatString.add(s)
|
formatString.add(s)
|
||||||
|
|
||||||
proc addExpr(e: expr) =
|
proc addExpr(e: PNimrodNode) =
|
||||||
arrayNode.add(e)
|
arrayNode.add(e)
|
||||||
formatString.add("$" & $(idx))
|
formatString.add("$" & $(idx))
|
||||||
inc idx
|
inc idx
|
||||||
|
|
@ -44,9 +44,9 @@ macro concatStyleInterpolation(e: expr): expr =
|
||||||
var args: seq[PNimrodNode]
|
var args: seq[PNimrodNode]
|
||||||
newSeq(args, 0)
|
newSeq(args, 0)
|
||||||
|
|
||||||
proc addString(s: string) = args.add(newStrLitNode(s))
|
proc addString(s: string) = args.add(newStrLitNode(s))
|
||||||
proc addExpr(e: expr) = args.add(e)
|
proc addExpr(e: PNimrodNode) = args.add(e)
|
||||||
proc addDollar() = args.add(newStrLitNode"$")
|
proc addDollar() = args.add(newStrLitNode"$")
|
||||||
|
|
||||||
ProcessInterpolations(e)
|
ProcessInterpolations(e)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import
|
||||||
# `opened` here could be an overloaded proc which any type can define.
|
# `opened` here could be an overloaded proc which any type can define.
|
||||||
# A common practice can be returing an Optional[Resource] obj for which
|
# A common practice can be returing an Optional[Resource] obj for which
|
||||||
# `opened` is defined to `optional.hasValue`
|
# `opened` is defined to `optional.hasValue`
|
||||||
macro using(e: expr) : stmt =
|
macro using(e: expr): stmt =
|
||||||
if e.len != 2:
|
if e.len != 2:
|
||||||
error "Using statement: unexpected number of arguments. Got " &
|
error "Using statement: unexpected number of arguments. Got " &
|
||||||
$e.len & ", expected: 1 or more variable assignments and a block"
|
$e.len & ", expected: 1 or more variable assignments and a block"
|
||||||
|
|
@ -81,7 +81,7 @@ macro using(e: expr) : stmt =
|
||||||
targetAst[0][1][1][0] = body
|
targetAst[0][1][1][0] = body
|
||||||
targetAst[0][1][1][1][0] = finallyBlock
|
targetAst[0][1][1][1][0] = finallyBlock
|
||||||
|
|
||||||
return targetAst
|
result = targetAst
|
||||||
|
|
||||||
type
|
type
|
||||||
TResource* = object
|
TResource* = object
|
||||||
|
|
|
||||||
|
|
@ -391,7 +391,7 @@ proc srcdist(c: var TConfigData) =
|
||||||
if existsDir(dir): removeDir(dir)
|
if existsDir(dir): removeDir(dir)
|
||||||
createDir(dir)
|
createDir(dir)
|
||||||
var cmd = ("nimrod compile -f --symbolfiles:off --compileonly " &
|
var cmd = ("nimrod compile -f --symbolfiles:off --compileonly " &
|
||||||
"--gen_mapping " &
|
"--gen_mapping --cc:gcc" &
|
||||||
" --os:$# --cpu:$# $# $#") %
|
" --os:$# --cpu:$# $# $#") %
|
||||||
[c.oses[osA-1], c.cpus[cpuA-1], c.nimrodArgs,
|
[c.oses[osA-1], c.cpus[cpuA-1], c.nimrodArgs,
|
||||||
changeFileExt(c.infile, "nim")]
|
changeFileExt(c.infile, "nim")]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue