diff options
Diffstat (limited to 'src/bytecode/chunk.h')
-rw-r--r-- | src/bytecode/chunk.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/bytecode/chunk.h b/src/bytecode/chunk.h index 29dd99d..6157057 100644 --- a/src/bytecode/chunk.h +++ b/src/bytecode/chunk.h | |||
@@ -4,14 +4,27 @@ | |||
4 | #include "objects.h" | 4 | #include "objects.h" |
5 | #include "darray.h" | 5 | #include "darray.h" |
6 | 6 | ||
7 | typedef struct LineInfo { | ||
8 | size_t line; | ||
9 | size_t col; | ||
10 | } LineInfo; | ||
11 | |||
7 | typedef struct Chunk { | 12 | typedef struct Chunk { |
8 | u8 *code; | 13 | u8 *code; |
9 | Object *constants; | 14 | Object *constants; |
15 | LineInfo *lines; | ||
10 | } Chunk; | 16 | } Chunk; |
11 | 17 | ||
12 | 18 | void add_code(Chunk chunk, u8 byte, size_t line, size_t col); | |
13 | size_t add_constant(Chunk chunk, Object obj); | 19 | size_t add_constant(Chunk chunk, Object obj); |
14 | 20 | ||
21 | void | ||
22 | add_code(Chunk chunk, u8 byte, size_t line, size_t col) { | ||
23 | array_push(chunk.code, byte); | ||
24 | LineInfo info = (LineInfo){line, col}; | ||
25 | array_push(chunk.lines, info); | ||
26 | } | ||
27 | |||
15 | size_t | 28 | size_t |
16 | add_constant(Chunk chunk, Object obj) { | 29 | add_constant(Chunk chunk, Object obj) { |
17 | size_t pos = array_size(chunk.constants); | 30 | size_t pos = array_size(chunk.constants); |