diff options
Diffstat (limited to 'clox/src/debug.c')
-rw-r--r-- | clox/src/debug.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clox/src/debug.c b/clox/src/debug.c index 5a3cedc..b3f756a 100644 --- a/clox/src/debug.c +++ b/clox/src/debug.c @@ -30,6 +30,14 @@ static int byteInstruction(const char *name, Chunk *chunk, int offset) { return offset + 2; } +static int jumpInstruction(const char *name, int sign, Chunk *chunk, + int offset) { + uint16_t jump = (uint16_t)(chunk->code[offset + 1] << 8); + jump |= chunk->code[offset + 2]; + printf("%-16s %4d -> %d\n", name, offset, offset + 3 + sign * jump); + return offset + 3; +} + int disassembleInstruction(Chunk *chunk, int offset) { printf("%04d ", offset); if (offset > 0 && chunk->lines[offset] == chunk->lines[offset - 1]) { @@ -80,6 +88,10 @@ int disassembleInstruction(Chunk *chunk, int offset) { return simpleInstruction("OP_NEGATE", offset); case OP_PRINT: return simpleInstruction("OP_PRINT", offset); + case OP_JUMP: + return jumpInstruction("OP_JUMP", 1, chunk, offset); + case OP_JUMP_IF_FALSE: + return jumpInstruction("OP_JUMP_IF_FALSE", 1, chunk, offset); case OP_RETURN: return simpleInstruction("OP_RETURN", offset); default: |