From 6ea538cec3f2da832873252d0ec3810b9dbfede4 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 25 Oct 2013 13:30:34 +0200 Subject: [PATCH] computed goto now works; some progress on the new VM --- compiler/ccgstmts.nim | 19 +++++++++++++++++-- compiler/vm.nim | 17 ++++++++++++++--- compiler/vmdeps.nim | 2 +- tests/compile/tcomputedgoto.nim | 31 ++++++++++++++++--------------- todo.txt | 7 +++++-- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 75cabf4143..d71d65cebf 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -322,8 +322,20 @@ proc genComputedGoto(p: BProc; n: PNode) = gotoArray.appf("&&TMP$#, ", (id+i).toRope) gotoArray.appf("&&TMP$#};$n", (id+arraySize).toRope) line(p, cpsLocals, gotoArray) + + let topBlock = p.blocks.len-1 + let oldBody = p.blocks[topBlock].sections[cpsStmts] + p.blocks[topBlock].sections[cpsStmts] = nil + for j in casePos+1 .. = 0) of opcSetLenSeq, - opcSwap, opcIsNil, opcOf, + opcSwap, opcIsNil, opcCast, opcReset: internalError(c.debug[pc], "too implement") of opcNBindSym: @@ -868,6 +873,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode = regs[ra].strVal = typ.typeToString(preferExported) inc pc +proc fixType(result, n: PNode) {.inline.} = + # XXX do it deeply for complex values + if result.typ.isNil: result.typ = n.typ + proc execute(c: PCtx, start: int): PNode = var tos = PStackFrame(prc: nil, comesFrom: 0, next: nil) newSeq(tos.slots, c.prc.maxSlots) @@ -885,6 +894,7 @@ proc evalExpr*(c: PCtx, n: PNode): PNode = let start = genExpr(c, n) assert c.code[start].opcode != opcEof result = execute(c, start) + fixType(result, n) # for now we share the 'globals' environment. XXX Coming soon: An API for # storing&loading the 'globals' environment to get what a component system @@ -928,6 +938,7 @@ proc evalConstExprAux(module, prc: PSym, n: PNode, mode: TEvalMode): PNode = newSeq(tos.slots, c.prc.maxSlots) for i in 0 ..