From 1bdc0d1dd301a275a9cd5362018714a8fa2ee12e Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 29 Jun 2013 10:04:18 +0200 Subject: [PATCH] fixes lots of regressions --- compiler/evals.nim | 11 ++++++----- compiler/semexprs.nim | 5 +++-- compiler/semstmts.nim | 3 ++- compiler/transf.nim | 2 +- tests/run/tpegs.nim | 14 ++++++++------ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/compiler/evals.nim b/compiler/evals.nim index e33b091d50..9655ef9524 100644 --- a/compiler/evals.nim +++ b/compiler/evals.nim @@ -947,7 +947,7 @@ proc evalTypeTrait*(n: PNode, context: PSym): PNode = let typ = n.sons[1].sym.typ.skipTypes({tyTypeDesc}) case n.sons[0].sym.name.s.normalize of "name": - result = newStrNode(nkStrLit, typ.typeToString(preferName)) + result = newStrNode(nkStrLit, typ.typeToString(preferExported)) result.typ = newType(tyString, context) result.info = n.info else: @@ -1493,20 +1493,21 @@ proc eval*(c: PEvalContext, n: PNode): PNode = else: stackTrace(c, result, errCannotInterpretNodeX, renderTree(n)) -proc evalConstExprAux(module: PSym, e: PNode, mode: TEvalMode): PNode = +proc evalConstExprAux(module, prc: PSym, e: PNode, mode: TEvalMode): PNode = var p = newEvalContext(module, mode) var s = newStackFrame() s.call = e + s.prc = prc pushStackFrame(p, s) result = tryEval(p, e) if result != nil and result.kind == nkExceptBranch: result = nil popStackFrame(p) proc evalConstExpr*(module: PSym, e: PNode): PNode = - result = evalConstExprAux(module, e, emConst) + result = evalConstExprAux(module, nil, e, emConst) -proc evalStaticExpr*(module: PSym, e: PNode): PNode = - result = evalConstExprAux(module, e, emStatic) +proc evalStaticExpr*(module: PSym, e: PNode, prc: PSym): PNode = + result = evalConstExprAux(module, prc, e, emStatic) proc setupMacroParam(x: PNode): PNode = result = x diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 94453be150..ff68d6b8e0 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -590,7 +590,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode = call.add(a) #echo "NOW evaluating at compile time: ", call.renderTree if sfCompileTime in callee.flags: - result = evalStaticExpr(c.module, call) + result = evalStaticExpr(c.module, call, c.p.owner) if result.isNil: LocalError(n.info, errCannotInterpretNodeX, renderTree(call)) else: @@ -601,9 +601,10 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode = proc semStaticExpr(c: PContext, n: PNode): PNode = let a = semExpr(c, n.sons[0]) - result = evalStaticExpr(c.module, a) + result = evalStaticExpr(c.module, a, c.p.owner) if result.isNil: LocalError(n.info, errCannotInterpretNodeX, renderTree(n)) + result = emptyNode proc semOverloadedCallAnalyseEffects(c: PContext, n: PNode, nOrig: PNode, flags: TExprFlags): PNode = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 64ef7f4d6b..dc5c9341e9 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1139,9 +1139,10 @@ proc semPragmaBlock(c: PContext, n: PNode): PNode = proc semStaticStmt(c: PContext, n: PNode): PNode = let a = semStmt(c, n.sons[0]) - result = evalStaticExpr(c.module, a) + result = evalStaticExpr(c.module, a, c.p.owner) if result.isNil: LocalError(n.info, errCannotInterpretNodeX, renderTree(n)) + result = emptyNode elif result.kind == nkEmpty: result = newNodeI(nkDiscardStmt, n.info, 1) result.sons[0] = emptyNode diff --git a/compiler/transf.nim b/compiler/transf.nim index 82122d7761..a81457b39d 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -702,7 +702,7 @@ proc openTransf(module: PSym, filename: string): PTransf = result.module = module proc transformBody*(module: PSym, n: PNode, prc: PSym): PNode = - if nfTransf in n.flags or prc.kind in {skTemplate, skMacro}: + if nfTransf in n.flags or prc.kind in {skTemplate}: result = n else: #when useEffectSystem: trackProc(prc, n) diff --git a/tests/run/tpegs.nim b/tests/run/tpegs.nim index efc6a8fa44..bdd8db0f8e 100644 --- a/tests/run/tpegs.nim +++ b/tests/run/tpegs.nim @@ -1733,12 +1733,14 @@ when isMainModule: doAssert matches[0] == "a" else: doAssert false - - if match("abcdefg", peg"c {d} ef {g}", matches, 2): - doAssert matches[0] == "d" - doAssert matches[1] == "g" - else: - doAssert false + + block: + var matches: array[0..2, string] + if match("abcdefg", peg"c {d} ef {g}", matches, 2): + doAssert matches[0] == "d" + doAssert matches[1] == "g" + else: + doAssert false for x in findAll("abcdef", peg"{.}", 3): echo x