aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/chunk.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/bytecode/chunk.h')
-rw-r--r--src/bytecode/chunk.h15
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
7typedef struct LineInfo {
8 size_t line;
9 size_t col;
10} LineInfo;
11
7typedef struct Chunk { 12typedef struct Chunk {
8 u8 *code; 13 u8 *code;
9 Object *constants; 14 Object *constants;
15 LineInfo *lines;
10} Chunk; 16} Chunk;
11 17
12 18void add_code(Chunk chunk, u8 byte, size_t line, size_t col);
13size_t add_constant(Chunk chunk, Object obj); 19size_t add_constant(Chunk chunk, Object obj);
14 20
21void
22add_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
15size_t 28size_t
16add_constant(Chunk chunk, Object obj) { 29add_constant(Chunk chunk, Object obj) {
17 size_t pos = array_size(chunk.constants); 30 size_t pos = array_size(chunk.constants);