diff options
Diffstat (limited to 'dbg.d')
| -rw-r--r-- | dbg.d | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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; |
