diff options
Diffstat (limited to 'vm.d')
| -rw-r--r-- | vm.d | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -145,6 +145,11 @@ class VM { return high | low; } + Seq nil() { + List nil = new List(0); + return nil; + } + bool isNumber(Value value) { return value.type == ValueType.NUMBER; } @@ -155,6 +160,13 @@ class VM { value.type == ValueType.SEQ; // WRONG } + bool isNebString(Value value) { + if (value.type != ValueType.SEQ) { + return false; + } + return value.as.seq.type == SeqType.STRING; + } + bool isType(Value value) { return value.type == ValueType.TYPE; } @@ -527,7 +539,11 @@ class VM { this.popA(); // function this.frameCount--; if (this.frameCount == 1) { - writefln("returned %s", printableValue(ret)); + if (DEBUG) { + writefln("returned %s", printableValue(ret)); + } else if (REPL) { + writefln("=> %s", printableValue(ret)); + } return InterpretResult.OK; } // do something with the stack top/frame slots?? @@ -548,6 +564,15 @@ class VM { this.popA(); // throw this one away this.pushA(val); break; + case OpCode.OP_PRINT: + Value val = this.popA(); + if (isNebString(val)) { + writefln("%s", tr(asNebString(val).str, `\`, "")); + } else { + writefln("%s", printableValue(val)); + } + this.pushA(makeSeqValue(nil())); + break; case OpCode.OP_JUMP_TO: uint addr = this.readShort(); //this.current.ip -= offset; |
