aboutsummaryrefslogtreecommitdiff
path: root/dbg.d
diff options
context:
space:
mode:
authorBen Winston2023-05-20 22:54:07 -0400
committerBen Winston2023-05-20 22:54:07 -0400
commit2ad2be250a68e907b308b120b934edcbfc99ae6e (patch)
tree54cd9308286cb4a368a8f7eb11ad9011c74ac58a /dbg.d
parent38dc63a67879a42f208b5642a8590e1192e8e2e5 (diff)
block scope and local variables (not really working)
Diffstat (limited to 'dbg.d')
-rw-r--r--dbg.d16
1 files changed, 16 insertions, 0 deletions
diff --git a/dbg.d b/dbg.d
index 1290cf0..18526db 100644
--- a/dbg.d
+++ b/dbg.d
@@ -51,6 +51,10 @@ void printForm(Form f, string prefix = "") {
Def def = cast(Def)f;
writefln("%s var: %s", prefix, def.name.name);
break;
+ case FormType.BLOCK:
+ Block block = cast(Block)f;
+ writefln("%s block of %d", prefix, block.blockBody.length);
+ break;
default:
writeln("printFormDefault");
break;
@@ -79,6 +83,12 @@ string atomAsString(Atom a) {
return printableValue(a.value);
}
+int byteInstruction(string message, Chunk chunk, int offset) {
+ ubyte slot = chunk.code[offset + 1];
+ writefln("%-16s %4d", message, slot);
+ return offset + 2;
+}
+
int constantInstruction(string message, Chunk chunk, int offset) {
ubyte idx = chunk.code[offset + 1];
//writeln("dunno how to write a constant");
@@ -97,6 +107,10 @@ int disassemble(Chunk chunk, int offset) {
ubyte inst = chunk.code[offset];
switch (inst) {
+ case OpCode.OP_GET_LOCAL:
+ return byteInstruction("OP_GET_LOCAL", chunk, offset);
+ case OpCode.OP_SET_LOCAL:
+ return byteInstruction("OP_SET_LOCAL", chunk, offset);
case OpCode.OP_ADD:
return simpleInstruction("OP_ADD", offset);
case OpCode.OP_LESS:
@@ -111,6 +125,8 @@ int disassemble(Chunk chunk, int offset) {
return simpleInstruction("OP_NEGATE", offset);
case OpCode.OP_POP:
return simpleInstruction("OP_POP", offset);
+ case OpCode.OP_POP_SCOPE:
+ return simpleInstruction("OP_POP_SCOPE", offset);
case OpCode.OP_RETURN:
return simpleInstruction("OP_RETURN", offset);
case OpCode.OP_NIL: