aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/chunk.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/chunk.h
parent33372512fc32c26913c8385637d20f6d98c8376c (diff)
downloadbdl-f4113cbcdc192b23f9b6e5e14b0a3e4afac35272.tar.gz
bdl-f4113cbcdc192b23f9b6e5e14b0a3e4afac35272.zip
Add line/col information for debugging purposes.
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);