aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/debug.h
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-22 11:24:09 +0200
committerBad Diode <bd@badd10de.dev>2021-10-22 11:24:09 +0200
commitab7d7c155fb1bec5eed8f97462fbb656ea27dbb5 (patch)
treec0ab41a9078a67aa1fa9aa25a69942329200ea32 /src/bytecode/debug.h
parentf4113cbcdc192b23f9b6e5e14b0a3e4afac35272 (diff)
downloadbdl-ab7d7c155fb1bec5eed8f97462fbb656ea27dbb5.tar.gz
bdl-ab7d7c155fb1bec5eed8f97462fbb656ea27dbb5.zip
Add VM structure and fix AdressSanitizer bugs
Diffstat (limited to 'src/bytecode/debug.h')
-rw-r--r--src/bytecode/debug.h26
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
6void disassemble_chunk(Chunk chunk, const char *name); 6void disassemble_chunk(Chunk *chunk, const char *name);
7size_t disassemble_instruction(Chunk chunk, size_t offset); 7size_t disassemble_instruction(Chunk *chunk, size_t offset);
8 8
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 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
27size_t 27size_t
28disassemble_instruction(Chunk chunk, size_t offset) { 28disassemble_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;