diff options
author | Araq <rumpf_a@web.de> | 2013-10-10 00:45:15 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-10-10 00:45:15 +0200 |
commit | f9861e1fab22ec3591313dcbfb8716b03716caa4 (patch) | |
tree | 1d30ee334807ca909106b62b74042789d066d227 | |
parent | 67e9f2861e3e3139d26b2b0aba4c16508f3111a3 (diff) | |
download | Nim-f9861e1fab22ec3591313dcbfb8716b03716caa4.tar.gz |
cooler quote for c2nim
-rw-r--r-- | compiler/vm.nim | 29 | ||||
-rw-r--r-- | compiler/vmdef.nim | 3 | ||||
-rw-r--r-- | doc/c2nim.txt | 8 |
3 files changed, 16 insertions, 24 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index 42303b321..7705746de 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -842,9 +842,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame) = inc pc proc execute(c: PCtx, start: int) = - var pc = start - var regs: TNodeSeq # alias to tos.slots for performance - var tos: PStackFrame + var tos = PStackFrame(prc: nil, comesFrom: 0, next: nil) newSeq(tos.slots, c.prc.maxSlots) rawExecute(c, start, tos) @@ -899,9 +897,6 @@ proc setupMacroParam(x: PNode): PNode = result = x if result.kind in {nkHiddenSubConv, nkHiddenStdConv}: result = result.sons[1] -type - PEvalContext* = PCtx - proc evalMacroCall(c: PEvalContext, n, nOrig: PNode, sym: PSym): PNode = # XXX GlobalError() is ugly here, but I don't know a better solution for now inc(evalTemplateCounter) @@ -909,21 +904,21 @@ proc evalMacroCall(c: PEvalContext, n, nOrig: PNode, sym: PSym): PNode = GlobalError(n.info, errTemplateInstantiationTooNested) c.callsite = nOrig - var s = newStackFrame() - s.call = n - s.prc = sym + let body = optBody(c, sym) + let start = genStmt(c, body) + + var tos = PStackFrame(prc: sym, comesFrom: 0, next: nil) + newSeq(tos.slots, c.prc.maxSlots) + # setup arguments: var L = n.safeLen if L == 0: L = 1 - setlen(s.slots, L) + InternalAssert tos.slots.len >= L # return value: - s.slots[0] = newNodeIT(nkNilLit, n.info, sym.typ.sons[0]) + tos.slots[0] = newNodeIT(nkNilLit, n.info, sym.typ.sons[0]) # setup parameters: - for i in 1 .. < L: s.slots[i] = setupMacroParam(n.sons[i]) - pushStackFrame(c, s) - discard eval(c, optBody(c, sym)) - result = s.slots[0] - popStackFrame(c) + for i in 1 .. < L: tos.slots[i] = setupMacroParam(n.sons[i]) + rawExecute(c, start, tos) + result = tos.slots[0] if cyclicTree(result): GlobalError(n.info, errCyclicTree) dec(evalTemplateCounter) c.callsite = nil - diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index 515f2975b..d4b3d891d 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -162,6 +162,9 @@ type callsite*: PNode TPosition* = distinct int + + PEvalContext* = PCtx + proc newCtx*(module: PSym): PCtx = PCtx(code: @[], debug: @[], diff --git a/doc/c2nim.txt b/doc/c2nim.txt index f894c2f92..7dec8b995 100644 --- a/doc/c2nim.txt +++ b/doc/c2nim.txt @@ -10,13 +10,7 @@ Introduction ============ -.. raw:: html - <blockquote><p> - "Ich bin der König aller Blinden. - Glaubt ihr wirklich ihr selbst könnt sehen? - Kniet euch alle nieder in den Dreck, - bis ich befehle aufzustehen." - </p></blockquote> + "We all make choices. But in the end our choices make us." c2nim is a tool to translate Ansi C code to Nimrod. The output is |