aboutsummaryrefslogtreecommitdiff
path: root/dbg.d
diff options
context:
space:
mode:
authorBen Winston2023-05-21 16:20:41 -0400
committerBen Winston2023-05-21 16:20:41 -0400
commit618de4c70d8916f64781997f3ae538e3e6109d00 (patch)
treebcd8ee70d82402407399a49c9cf6914858bd9449 /dbg.d
parentb1183af95f45ba0162a91f7a308a4846418f03be (diff)
if/else, 'and' control flow
Diffstat (limited to 'dbg.d')
-rw-r--r--dbg.d13
1 files changed, 13 insertions, 0 deletions
diff --git a/dbg.d b/dbg.d
index 89ae8c1..e14e9fe 100644
--- a/dbg.d
+++ b/dbg.d
@@ -1,5 +1,6 @@
import std.stdio;
import std.string;
+import std.conv;
import chunk;
import parser;
@@ -83,6 +84,13 @@ string atomAsString(Atom a) {
return printableValue(a.value);
}
+int jumpInstruction(string message, int sign, Chunk chunk, int offset) {
+ uint jump = to!uint(chunk.code[offset + 1] << 8);
+ jump |= chunk.code[offset + 2];
+ writefln("%-16s %4d -> %d", message, offset, offset + 3 + sign * jump);
+ return offset + 3;
+}
+
int byteInstruction(string message, Chunk chunk, int offset) {
ubyte slot = chunk.code[offset + 1];
writefln("%-16s %4d", message, slot);
@@ -135,6 +143,11 @@ int disassemble(Chunk chunk, int offset) {
return simpleInstruction("OP_RETURN", offset);
case OpCode.OP_NIL:
return simpleInstruction("OP_NIL", offset);
+ case OpCode.OP_JUMP:
+ return jumpInstruction("OP_JUMP", 1, chunk, offset);
+ case OpCode.OP_JUMP_IF_FALSE:
+ return jumpInstruction("OP_JUMP_IF_FALSE", 1, chunk, offset);
+
default:
writeln("unknown opcode?");
return offset + 1;