new VM supports 'getAst'
This commit is contained in:
parent
4ffe6a8282
commit
430c8d8b52
2 changed files with 26 additions and 4 deletions
|
|
@ -17,6 +17,7 @@ import
|
||||||
parser, vmdeps, idents, trees, renderer, options
|
parser, vmdeps, idents, trees, renderer, options
|
||||||
|
|
||||||
from semfold import leValueConv, ordinalValToString
|
from semfold import leValueConv, ordinalValToString
|
||||||
|
from evaltempl import evalTemplate
|
||||||
|
|
||||||
when hasFFI:
|
when hasFFI:
|
||||||
import evalffi
|
import evalffi
|
||||||
|
|
@ -625,7 +626,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode =
|
||||||
regs[ra] = newValue
|
regs[ra] = newValue
|
||||||
else:
|
else:
|
||||||
globalError(c.debug[pc], errGenerated, "VM not built with FFI support")
|
globalError(c.debug[pc], errGenerated, "VM not built with FFI support")
|
||||||
else:
|
elif prc.kind != skTemplate:
|
||||||
let newPc = compile(c, prc)
|
let newPc = compile(c, prc)
|
||||||
#echo "new pc ", newPc, " calling: ", prc.name.s
|
#echo "new pc ", newPc, " calling: ", prc.name.s
|
||||||
var newFrame = PStackFrame(prc: prc, comesFrom: pc, next: tos)
|
var newFrame = PStackFrame(prc: prc, comesFrom: pc, next: tos)
|
||||||
|
|
@ -644,6 +645,18 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode =
|
||||||
move(regs, newFrame.slots)
|
move(regs, newFrame.slots)
|
||||||
# -1 for the following 'inc pc'
|
# -1 for the following 'inc pc'
|
||||||
pc = newPc-1
|
pc = newPc-1
|
||||||
|
else:
|
||||||
|
# for 'getAst' support we need to support template expansion here:
|
||||||
|
let genSymOwner = if tos.next != nil and tos.next.prc != nil:
|
||||||
|
tos.next.prc
|
||||||
|
else:
|
||||||
|
c.module
|
||||||
|
var macroCall = newNodeI(nkCall, c.debug[pc])
|
||||||
|
macroCall.add(newSymNode(prc))
|
||||||
|
for i in 1 .. rc-1: macroCall.add(regs[rb+i].skipMeta)
|
||||||
|
let a = evalTemplate(macroCall, prc, genSymOwner)
|
||||||
|
ensureKind(nkMetaNode)
|
||||||
|
setMeta(regs[ra], a)
|
||||||
of opcTJmp:
|
of opcTJmp:
|
||||||
# jump Bx if A != 0
|
# jump Bx if A != 0
|
||||||
let rbx = instr.regBx - wordExcess - 1 # -1 for the following 'inc pc'
|
let rbx = instr.regBx - wordExcess - 1 # -1 for the following 'inc pc'
|
||||||
|
|
|
||||||
|
|
@ -711,8 +711,6 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest) =
|
||||||
genUnaryABC(c, n, dest, opcParseExprToAst)
|
genUnaryABC(c, n, dest, opcParseExprToAst)
|
||||||
of mParseStmtToAst:
|
of mParseStmtToAst:
|
||||||
genUnaryABC(c, n, dest, opcParseStmtToAst)
|
genUnaryABC(c, n, dest, opcParseStmtToAst)
|
||||||
of mExpandToAst:
|
|
||||||
InternalError(n.info, "cannot generate code for: " & $m)
|
|
||||||
of mTypeTrait:
|
of mTypeTrait:
|
||||||
let tmp = c.genx(n.sons[1])
|
let tmp = c.genx(n.sons[1])
|
||||||
if dest < 0: dest = c.getTemp(n.typ)
|
if dest < 0: dest = c.getTemp(n.typ)
|
||||||
|
|
@ -786,6 +784,16 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest) =
|
||||||
of mNGenSym: genBinaryABC(c, n, dest, opcGenSym)
|
of mNGenSym: genBinaryABC(c, n, dest, opcGenSym)
|
||||||
of mMinI, mMaxI, mMinI64, mMaxI64, mAbsF64, mMinF64, mMaxF64, mAbsI, mAbsI64:
|
of mMinI, mMaxI, mMinI64, mMaxI64, mAbsF64, mMinF64, mMaxF64, mAbsI, mAbsI64:
|
||||||
c.genCall(n, dest)
|
c.genCall(n, dest)
|
||||||
|
of mExpandToAst:
|
||||||
|
if n.len != 2:
|
||||||
|
globalError(n.info, errGenerated, "expandToAst requires 1 argument")
|
||||||
|
let arg = n.sons[1]
|
||||||
|
if arg.kind in nkCallKinds:
|
||||||
|
#if arg[0].kind != nkSym or arg[0].sym.kind notin {skTemplate, skMacro}:
|
||||||
|
# "ExpandToAst: expanded symbol is no macro or template"
|
||||||
|
c.genCall(arg, dest)
|
||||||
|
else:
|
||||||
|
globalError(n.info, "expandToAst requires a call expression")
|
||||||
else:
|
else:
|
||||||
# mGCref, mGCunref,
|
# mGCref, mGCunref,
|
||||||
InternalError(n.info, "cannot generate code for: " & $m)
|
InternalError(n.info, "cannot generate code for: " & $m)
|
||||||
|
|
@ -1140,7 +1148,8 @@ proc gen(c: PCtx; n: PNode; dest: var TDest) =
|
||||||
case s.kind
|
case s.kind
|
||||||
of skVar, skForVar, skTemp, skLet, skParam, skResult:
|
of skVar, skForVar, skTemp, skLet, skParam, skResult:
|
||||||
genRdVar(c, n, dest)
|
genRdVar(c, n, dest)
|
||||||
of skProc, skConverter, skMacro, skMethod, skIterator:
|
of skProc, skConverter, skMacro, skTemplate, skMethod, skIterator:
|
||||||
|
# 'skTemplate' is only allowed for 'getAst' support:
|
||||||
if sfImportc in s.flags: c.importcSym(n.info, s)
|
if sfImportc in s.flags: c.importcSym(n.info, s)
|
||||||
genLit(c, n, dest)
|
genLit(c, n, dest)
|
||||||
of skConst:
|
of skConst:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue