diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 4d52e3aab4..01c734524f 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -322,6 +322,7 @@ proc genComputedGoto(p: BProc; n: PNode) = gotoArray.appf("&&TMP$#};$n", (id+arraySize).toRope) line(p, cpsLocals, gotoArray) + for j in 0 .. casePos-1: genStmts(p, n.sons[j]) let caseStmt = n.sons[casePos] var a: TLoc initLocExpr(p, caseStmt.sons[0], a) @@ -329,6 +330,7 @@ proc genComputedGoto(p: BProc; n: PNode) = lineF(p, cpsStmts, "goto *$#[$#];$n", tmp, a.rdLoc) for i in 1 .. `_ diff --git a/tests/compile/tcomputedgoto.nim b/tests/compile/tcomputedgoto.nim index 661f70743e..2c3b4bbd4a 100644 --- a/tests/compile/tcomputedgoto.nim +++ b/tests/compile/tcomputedgoto.nim @@ -31,7 +31,8 @@ proc vm() = var pc = 0 while true: {.computedGoto.} - case instructions[pc] + let instr = instructions[pc] + case instr of enumA: echo "yeah A" of enumC, enumD: @@ -39,7 +40,7 @@ proc vm() = of enumB: echo "yeah B" of enumE: - return + break inc(pc) vm() diff --git a/web/news.txt b/web/news.txt index 56919d56cd..896cf9941a 100644 --- a/web/news.txt +++ b/web/news.txt @@ -37,6 +37,8 @@ Compiler Additions - The compiler now enforces the ``not nil`` constraint. - The compiler now supports a ``codegenDecl`` pragma for even more control over the generated code. +- The compiler now supports a ``computedGoto`` pragma to support very fast + dispatching for interpreters and the like. Language Additions