diff options
| author | mryouse | 2023-05-25 00:30:03 +0000 |
|---|---|---|
| committer | mryouse | 2023-05-25 00:30:03 +0000 |
| commit | c08e9c793b138da5b373d6cb66a2eb599ea77397 (patch) | |
| tree | 1399d36653163831c44212a3f22743c1ad840e88 | |
| parent | df34325463c28f11eb2ce46f83da0c29bafe1a5e (diff) | |
make debug toggle-able
| -rw-r--r-- | compiler.d | 4 | ||||
| -rw-r--r-- | dbg.d | 3 | ||||
| -rw-r--r-- | vm.d | 34 |
3 files changed, 24 insertions, 17 deletions
@@ -716,7 +716,9 @@ class Compiler { Function finish() { this.func.chunk.writeOp(OpCode.OP_RETURN, current.line); - disassembleChunk(this.func.chunk, to!string(func)); + if (DEBUG) { + disassembleChunk(this.func.chunk, to!string(func)); + } return this.func; } @@ -8,6 +8,9 @@ import parser; //import dbg; //import value; +bool DEBUG = true; + + void printForm(Form f, string prefix = "") { switch (f.type) { case FormType.EOF: @@ -224,22 +224,25 @@ class VM { InterpretResult run() { writeln("== VM running =="); while (true) { - writeln(" Stacks:"); - write(" A> "); - for (int i = 0; i < aTop; i++) { - writef("[ %s ]", printableValue(aStack[i])); + if (DEBUG) { + writeln(" Stacks:"); + write(" A> "); + for (int i = 0; i < aTop; i++) { + writef("[ %s ]", printableValue(aStack[i])); + } + write("\n B> "); + for (int i = 0; i < bTop; i++) { + //writef("[ %s ]", printableValue(bStack[i])); + writef("[ %s ]", printableValue(current.slots[i])); + } + + write("\n constants> "); + for (int i = 0; i < current.func.chunk.constants.length; i++) { + writef("[ %s ]", printableValue(current.func.chunk.constants[i])); + } + writeln("\n--"); + disassemble(current.func.chunk, current.ip); } - write("\n B> "); - for (int i = 0; i < bTop; i++) { - //writef("[ %s ]", printableValue(bStack[i])); - writef("[ %s ]", printableValue(current.slots[i])); - } - - write("\n constants> "); - for (int i = 0; i < current.func.chunk.constants.length; i++) { - writef("[ %s ]", printableValue(current.func.chunk.constants[i])); - } - writeln("\n--"); /* write(" globals >"); @@ -250,7 +253,6 @@ class VM { writeln("\n--"); */ - disassemble(current.func.chunk, current.ip); ubyte inst; switch (inst = this.readByte()) { case OpCode.OP_DEF_GLOBAL: |
