From f4113cbcdc192b23f9b6e5e14b0a3e4afac35272 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 22 Oct 2021 10:57:23 +0200 Subject: Add line/col information for debugging purposes. --- src/bytecode/debug.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/bytecode/debug.h') diff --git a/src/bytecode/debug.h b/src/bytecode/debug.h index e07b9a2..ceedfbf 100644 --- a/src/bytecode/debug.h +++ b/src/bytecode/debug.h @@ -9,15 +9,31 @@ size_t disassemble_instruction(Chunk chunk, size_t offset); void disassemble_chunk(Chunk chunk, const char *name) { printf("== %s ==\n", name); + printf("code:\n"); size_t offset = 0; while (offset < array_size(chunk.code)) { offset = disassemble_instruction(chunk, offset); } + printf("\nconstants:\n"); + offset = 0; + while (offset < array_size(chunk.constants)) { + printf("\t%04ld -> ", offset); + display(chunk.constants[offset]); + printf("\n"); + offset++; + } } size_t disassemble_instruction(Chunk chunk, size_t offset) { - printf("%04ld ", offset); + printf("\t%04ld ", offset); + if (offset > 0 + && chunk.lines[offset].line == chunk.lines[offset - 1].line + && chunk.lines[offset].col == chunk.lines[offset - 1].col) { + printf("%4s|%-4s ", " ", " "); + } else { + printf("%4ld:%-4ld ", chunk.lines[offset].line, chunk.lines[offset].col); + } u8 instruction = chunk.code[offset]; switch (instruction) { case OP_RETURN: { -- cgit v1.2.1