From d8746398c43cae51d80b32ac182ab12a64710286 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 9 Oct 2017 21:11:53 +0200 Subject: [PATCH] allow macros to produce nnkGotoState and nkState --- compiler/ccgstmts.nim | 5 ++++- compiler/ccgtypes.nim | 2 +- compiler/semexprs.nim | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index eb32e7dd0f..74779f598c 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -156,7 +156,10 @@ proc genGotoState(p: BProc, n: PNode) = lineF(p, cpsStmts, "switch ($1) {$n", [rdLoc(a)]) p.beforeRetNeeded = true lineF(p, cpsStmts, "case -1: goto BeforeRet_;$n", []) - for i in 0 .. lastOrd(n.sons[0].typ): + var statesCounter = lastOrd(n.sons[0].typ) + if n.len == 2 and n[1].kind == nkIntLit: + statesCounter = n[1].intVal + for i in 0 .. statesCounter: lineF(p, cpsStmts, "case $1: goto STATE$1;$n", [rope(i)]) lineF(p, cpsStmts, "}$n", []) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 254b134294..c9705e784b 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -92,7 +92,7 @@ proc mangleParamName(m: BModule; s: PSym): Rope = proc mangleLocalName(p: BProc; s: PSym): Rope = assert s.kind in skLocalVars+{skTemp} - assert sfGlobal notin s.flags + #assert sfGlobal notin s.flags result = s.loc.r if result == nil: var key = s.name.s.mangle diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 439f2772a3..c336afc89d 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -2357,6 +2357,10 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = if not n.sons[0].typ.isEmptyType and not implicitlyDiscardable(n.sons[0]): localError(n.info, errGenerated, "'defer' takes a 'void' expression") #localError(n.info, errGenerated, "'defer' not allowed in this context") + of nkGotoState, nkState: + if n.len != 1 and n.len != 2: illFormedAst(n) + for i in 0 ..< n.len: + n.sons[i] = semExpr(c, n.sons[i]) else: localError(n.info, errInvalidExpressionX, renderTree(n, {renderNoComments}))