diff options
author | Aman Gupta <aman@tmm1.net> | 2015-10-06 11:06:41 -0700 |
---|---|---|
committer | Aman Gupta <aman@tmm1.net> | 2015-10-06 11:06:41 -0700 |
commit | eea8d604d07aae569843ebccc5bd7791cff40567 (patch) | |
tree | dbb652a24acbf0dfd28e2921f72b0d92fe4a858d /compiler/vm.nim | |
parent | a01fd5e93f58a2bf9dea4f577218b8ff7d874bbf (diff) | |
parent | 2e413d3186455bf92ee9bae04304cb34cf1f2557 (diff) | |
download | Nim-eea8d604d07aae569843ebccc5bd7791cff40567.tar.gz |
Merge remote-tracking branch 'origin/devel' into fix-test-failures
Diffstat (limited to 'compiler/vm.nim')
-rw-r--r-- | compiler/vm.nim | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index ad4aa1017..ded66d3d0 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1411,6 +1411,31 @@ proc execute(c: PCtx, start: int): PNode = newSeq(tos.slots, c.prc.maxSlots) result = rawExecute(c, start, tos).regToNode +proc execProc*(c: PCtx; sym: PSym; args: openArray[PNode]): PNode = + if sym.kind in routineKinds: + if sym.typ.len-1 != args.len: + localError(sym.info, + "NimScript: expected $# arguments, but got $#" % [ + $(sym.typ.len-1), $args.len]) + else: + let start = genProc(c, sym) + + var tos = PStackFrame(prc: sym, comesFrom: 0, next: nil) + let maxSlots = sym.offset + newSeq(tos.slots, maxSlots) + + # setup parameters: + if not isEmptyType(sym.typ.sons[0]) or sym.kind == skMacro: + putIntoReg(tos.slots[0], getNullValue(sym.typ.sons[0], sym.info)) + # XXX We could perform some type checking here. + for i in 1.. <sym.typ.len: + putIntoReg(tos.slots[i], args[i-1]) + + result = rawExecute(c, start, tos).regToNode + else: + localError(sym.info, + "NimScript: attempt to call non-routine: " & sym.name.s) + proc evalStmt*(c: PCtx, n: PNode) = let n = transformExpr(c.module, n) let start = genStmt(c, n) |