diff options
author | Bad Diode <bd@badd10de.dev> | 2021-10-22 10:57:23 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-10-22 10:57:23 +0200 |
commit | f4113cbcdc192b23f9b6e5e14b0a3e4afac35272 (patch) | |
tree | 8ce6ee2b83256243720465d4fb2e1a89fcee8be7 /src/bytecode/debug.h | |
parent | 33372512fc32c26913c8385637d20f6d98c8376c (diff) | |
download | bdl-f4113cbcdc192b23f9b6e5e14b0a3e4afac35272.tar.gz bdl-f4113cbcdc192b23f9b6e5e14b0a3e4afac35272.zip |
Add line/col information for debugging purposes.
Diffstat (limited to 'src/bytecode/debug.h')
-rw-r--r-- | src/bytecode/debug.h | 18 |
1 files changed, 17 insertions, 1 deletions
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); | |||
9 | void | 9 | void |
10 | disassemble_chunk(Chunk chunk, const char *name) { | 10 | disassemble_chunk(Chunk chunk, const char *name) { |
11 | printf("== %s ==\n", name); | 11 | printf("== %s ==\n", name); |
12 | printf("code:\n"); | ||
12 | size_t offset = 0; | 13 | size_t offset = 0; |
13 | while (offset < array_size(chunk.code)) { | 14 | while (offset < array_size(chunk.code)) { |
14 | offset = disassemble_instruction(chunk, offset); | 15 | offset = disassemble_instruction(chunk, offset); |
15 | } | 16 | } |
17 | printf("\nconstants:\n"); | ||
18 | offset = 0; | ||
19 | while (offset < array_size(chunk.constants)) { | ||
20 | printf("\t%04ld -> ", offset); | ||
21 | display(chunk.constants[offset]); | ||
22 | printf("\n"); | ||
23 | offset++; | ||
24 | } | ||
16 | } | 25 | } |
17 | 26 | ||
18 | size_t | 27 | size_t |
19 | disassemble_instruction(Chunk chunk, size_t offset) { | 28 | disassemble_instruction(Chunk chunk, size_t offset) { |
20 | printf("%04ld ", offset); | 29 | printf("\t%04ld ", offset); |
30 | if (offset > 0 | ||
31 | && chunk.lines[offset].line == chunk.lines[offset - 1].line | ||
32 | && chunk.lines[offset].col == chunk.lines[offset - 1].col) { | ||
33 | printf("%4s|%-4s ", " ", " "); | ||
34 | } else { | ||
35 | printf("%4ld:%-4ld ", chunk.lines[offset].line, chunk.lines[offset].col); | ||
36 | } | ||
21 | u8 instruction = chunk.code[offset]; | 37 | u8 instruction = chunk.code[offset]; |
22 | switch (instruction) { | 38 | switch (instruction) { |
23 | case OP_RETURN: { | 39 | case OP_RETURN: { |