From abdcae0f839d0bd772c5f7211cb1cb2034355b62 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 24 Oct 2021 16:47:15 +0200 Subject: Cleanup IF jump code in compiler --- src/bytecode/debug.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/bytecode/debug.h') diff --git a/src/bytecode/debug.h b/src/bytecode/debug.h index 674d469..bc736f9 100755 --- a/src/bytecode/debug.h +++ b/src/bytecode/debug.h @@ -71,11 +71,19 @@ disassemble_instruction(Chunk *chunk, size_t offset) { switch (instruction) { case OP_CONSTANT: { u8 constant = chunk->code[offset + 1]; - printf("%-16s %4d -> ", "OP_CONSTANT", constant); + printf("%-16s %4d -> ", ops_str[instruction], constant); display(chunk->constants[constant]); printf("\n"); return offset + 2; } break; + case OP_JUMP: + case OP_JUMP_IF_FALSE: { + u16 a = chunk->code[offset + 1]; + u16 b = chunk->code[offset + 2]; + u16 jmp = (a << 8) | b; + printf("%-16s %4d\n", ops_str[instruction], jmp); + return offset + 3; + } break; default: { printf("%s\n", ops_str[instruction]); return offset + 1; -- cgit v1.2.1