From 2ad2be250a68e907b308b120b934edcbfc99ae6e Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Sat, 20 May 2023 22:54:07 -0400 Subject: block scope and local variables (not really working) --- dbg.d | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'dbg.d') 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: -- cgit v1.2.3