diff options
Diffstat (limited to 'vm.d')
| -rw-r--r-- | vm.d | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -396,6 +396,18 @@ class VM { //bStack[bTop + slot - 1] = peekA(0); this.popA(); break; + case OpCode.OP_UNGROUP: + Seq seq = asSeq(this.popA()); + Value length = makeNumberValue(seq.length()); + Value tmp = makeSeqValue(seq); + while (!isNil(tmp)) { + //tmp = seq.first(); + this.pushA(asSeq(tmp).first()); + tmp = makeSeqValue(asSeq(tmp).rest()); + } + // push the length + this.pushA(length); + break; case OpCode.OP_LIST_N: Value lengthVal = this.popA(); int length = to!int(asNumber(lengthVal)); @@ -638,6 +650,29 @@ class VM { } this.current = &this.frames[this.frameCount - 1]; break; + case OpCode.OP_CALL_N: + double argCount = asNumber(this.popA()); + // TODO i think i need to move the arguments from stack A to stack B (preserving order) + int cnt = to!int(argCount) - 1; + Value[] tmp; + while (cnt >= 0) { + tmp ~= this.popA(); + cnt--; + } + + for (int i = to!int(tmp.length) - 1; i >= 0; i--) { + this.pushB(tmp[i]); + } + + //if (!callValue(peekA(argCount), argCount)) { // i'm allocating variables wrong + if (!this.callValue(this.peekA(0), to!int(argCount))) { // i'm allocating variables wrong + return InterpretResult.RUNTIME_ERROR; + } + this.current = &this.frames[this.frameCount - 1]; + break; + + + default: writeln("unknown opcode to run"); break; |
