diff options
Diffstat (limited to 'src/bytecode/debug.h')
-rw-r--r-- | src/bytecode/debug.h | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/bytecode/debug.h b/src/bytecode/debug.h index ceedfbf..c891b77 100644 --- a/src/bytecode/debug.h +++ b/src/bytecode/debug.h | |||
@@ -3,47 +3,47 @@ | |||
3 | 3 | ||
4 | #include "chunk.h" | 4 | #include "chunk.h" |
5 | 5 | ||
6 | void disassemble_chunk(Chunk chunk, const char *name); | 6 | void disassemble_chunk(Chunk *chunk, const char *name); |
7 | size_t disassemble_instruction(Chunk chunk, size_t offset); | 7 | size_t disassemble_instruction(Chunk *chunk, size_t offset); |
8 | 8 | ||
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 | printf("code:\n"); |
13 | size_t offset = 0; | 13 | size_t offset = 0; |
14 | while (offset < array_size(chunk.code)) { | 14 | while (offset < array_size(chunk->code)) { |
15 | offset = disassemble_instruction(chunk, offset); | 15 | offset = disassemble_instruction(chunk, offset); |
16 | } | 16 | } |
17 | printf("\nconstants:\n"); | 17 | printf("\nconstants:\n"); |
18 | offset = 0; | 18 | offset = 0; |
19 | while (offset < array_size(chunk.constants)) { | 19 | while (offset < array_size(chunk->constants)) { |
20 | printf("\t%04ld -> ", offset); | 20 | printf("\t%04ld -> ", offset); |
21 | display(chunk.constants[offset]); | 21 | display(chunk->constants[offset]); |
22 | printf("\n"); | 22 | printf("\n"); |
23 | offset++; | 23 | offset++; |
24 | } | 24 | } |
25 | } | 25 | } |
26 | 26 | ||
27 | size_t | 27 | size_t |
28 | disassemble_instruction(Chunk chunk, size_t offset) { | 28 | disassemble_instruction(Chunk *chunk, size_t offset) { |
29 | printf("\t%04ld ", offset); | 29 | printf("\t%04ld ", offset); |
30 | if (offset > 0 | 30 | if (offset > 0 |
31 | && chunk.lines[offset].line == chunk.lines[offset - 1].line | 31 | && chunk->lines[offset].line == chunk->lines[offset - 1].line |
32 | && chunk.lines[offset].col == chunk.lines[offset - 1].col) { | 32 | && chunk->lines[offset].col == chunk->lines[offset - 1].col) { |
33 | printf("%4s|%-4s ", " ", " "); | 33 | printf("%4s|%-4s ", " ", " "); |
34 | } else { | 34 | } else { |
35 | printf("%4ld:%-4ld ", chunk.lines[offset].line, chunk.lines[offset].col); | 35 | printf("%4ld:%-4ld ", chunk->lines[offset].line, chunk->lines[offset].col); |
36 | } | 36 | } |
37 | u8 instruction = chunk.code[offset]; | 37 | u8 instruction = chunk->code[offset]; |
38 | switch (instruction) { | 38 | switch (instruction) { |
39 | case OP_RETURN: { | 39 | case OP_RETURN: { |
40 | printf("OP_RETURN\n"); | 40 | printf("OP_RETURN\n"); |
41 | return offset + 1; | 41 | return offset + 1; |
42 | } break; | 42 | } break; |
43 | case OP_CONSTANT: { | 43 | case OP_CONSTANT: { |
44 | u8 constant = chunk.code[offset + 1]; | 44 | u8 constant = chunk->code[offset + 1]; |
45 | printf("%-16s %4d (", "OP_CONSTANT", constant); | 45 | printf("%-16s %4d (", "OP_CONSTANT", constant); |
46 | display(chunk.constants[constant]); | 46 | display(chunk->constants[constant]); |
47 | printf(")\n"); | 47 | printf(")\n"); |
48 | return offset + 2; | 48 | return offset + 2; |
49 | } break; | 49 | } break; |