From 8e1f84b1369909745859777d07a5e8e74b5df334 Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Sun, 21 May 2023 20:26:59 -0400 Subject: move disassembly into compiler, preparing for functions --- dbg.d | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'dbg.d') diff --git a/dbg.d b/dbg.d index defa8ef..b32c431 100644 --- a/dbg.d +++ b/dbg.d @@ -80,6 +80,10 @@ string printableValue(Value val) { } } +string printableFunction(Function func) { + return format("%s", func); +} + string atomAsString(Atom a) { return printableValue(a.value); } @@ -110,6 +114,18 @@ int simpleInstruction(string message, int offset) { return offset + 1; } +void disassembleChunk(Chunk chunk, string name) { + writefln("== %s ==", name); + int cnt = 0; + while(true) { + if (cnt >= chunk.code.length) { + break; + } + cnt = disassemble(chunk, cnt); + } + +} + int disassemble(Chunk chunk, int offset) { writef("%04d %4d ", offset, chunk.lines[offset]); -- cgit v1.2.3