diff options
Diffstat (limited to 'vm.d')
| -rw-r--r-- | vm.d | 57 |
1 files changed, 3 insertions, 54 deletions
@@ -80,7 +80,6 @@ class VM { return this.aStack[this.aTop]; } - //InterpretResult push(Value value) { void pushA(Value value) { if (this.aStack.length > this.aTop) { this.aStack[this.aTop] = value; @@ -144,8 +143,6 @@ class VM { uint high = this.current.func.chunk.code[this.current.ip - 2] << 8; uint low = this.current.func.chunk.code[this.current.ip - 1]; return high | low; - - //return 0; } bool isNumber(Value value) { @@ -224,12 +221,6 @@ class VM { } */ - /* - CallFrame currentFrame() { - return frames[frameCount - 1]; - } - */ - bool callValue(Value callee, int argCount) { if (isObj(callee)) { switch (callee.as.obj.type) { @@ -259,7 +250,9 @@ class VM { } InterpretResult run() { - writeln("== VM running =="); + if (DEBUG) { + writeln("== VM running =="); + } while (true) { if (DEBUG) { writeln(" Stacks:"); @@ -270,7 +263,6 @@ class VM { write("\n B> "); for (int i = 0; i < this.bTop; i++) { writef("[ %s ]", printableValue(bStack[i])); - //writef("[ %s ]", printableValue(this.current.slots[i])); } write("\n constants> "); @@ -346,7 +338,6 @@ class VM { break; case OpCode.OP_GET_GLOBAL: Value name = this.current.func.chunk.constants[this.readByte()]; - //writefln(asString(name)); if (!isString(name)) { writefln("variables must be strings, got %s", printableValue(name)); return InterpretResult.RUNTIME_ERROR; // TODO error @@ -361,7 +352,6 @@ class VM { case OpCode.OP_DEF_LOCAL: Value val = this.popA(); this.pushB(val); - //current.slots ~= val; /* Value nil = { ValueType.NIL }; @@ -398,7 +388,6 @@ class VM { List lst = new List(length); if (length > 0) { for (int i = length - 1; i >= 0; i--) { - //lst.appendItem(this.popA()); lst.addItemAtIndex(this.popA(), i); } } @@ -406,7 +395,6 @@ class VM { break; case OpCode.OP_CONSTANT: Value constant = this.current.func.chunk.constants[this.readByte()]; - //Value constant = current.func.chunk.constants[b]; this.pushA(constant); break; case OpCode.OP_NEGATE: @@ -466,38 +454,14 @@ class VM { break; case OpCode.OP_ADD: Value b = this.popA(); - /* - if (!isNumber(b)) { - writeln("b is not a number!"); - return InterpretResult.RUNTIME_ERROR; // TODO error - } - */ Value a = this.popA(); - /* - if (!isNumber(a)) { - writeln("a is not a number!"); - return InterpretResult.RUNTIME_ERROR; // TODO error - } - */ double bnum = asNumber(b); double anum = asNumber(a); this.pushA(makeNumberValue(anum + bnum)); break; case OpCode.OP_SUBTRACT: Value b = this.popA(); - /* - if (!isNumber(b)) { - writeln("b is not a number!"); - return InterpretResult.RUNTIME_ERROR; // TODO error - } - */ Value a = this.popA(); - /* - if (!isNumber(a)) { - writeln("a is not a number!"); - return InterpretResult.RUNTIME_ERROR; // TODO error - } - */ double bnum = asNumber(b); double anum = asNumber(a); this.pushA(makeNumberValue(anum - bnum)); @@ -540,25 +504,12 @@ class VM { break; case OpCode.OP_LESS: Value b = this.popA(); - /* - if (!isNumber(b)) { - writeln("b is not a number!"); - return InterpretResult.RUNTIME_ERROR; // TODO error - } - */ Value a = this.popA(); - /* - if (!isNumber(a)) { - writeln("a is not a number!"); - return InterpretResult.RUNTIME_ERROR; // TODO error - } - */ double bnum = asNumber(b); double anum = asNumber(a); this.pushA(makeBooleanValue(anum < bnum)); break; case OpCode.OP_RETURN: - Value ret = this.popA(); this.popA(); // function this.frameCount--; @@ -591,7 +542,6 @@ class VM { break; case OpCode.OP_JUMP: uint offset = this.readShort(); - //ip += offset; this.current.ip += offset; break; case OpCode.OP_JUMP_IF_FALSE: @@ -601,7 +551,6 @@ class VM { return InterpretResult.RUNTIME_ERROR; // TODO error } if (!asBoolean(this.peekA(0))) { - //ip += offset; this.current.ip += offset; } break; |
