aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/debug.h
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-22 10:57:23 +0200
committerBad Diode <bd@badd10de.dev>2021-10-22 10:57:23 +0200
commitf4113cbcdc192b23f9b6e5e14b0a3e4afac35272 (patch)
tree8ce6ee2b83256243720465d4fb2e1a89fcee8be7 /src/bytecode/debug.h
parent33372512fc32c26913c8385637d20f6d98c8376c (diff)
downloadbdl-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.h18
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);
9void 9void
10disassemble_chunk(Chunk chunk, const char *name) { 10disassemble_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
18size_t 27size_t
19disassemble_instruction(Chunk chunk, size_t offset) { 28disassemble_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: {