aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/compiler.h
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-24 11:52:56 +0200
committerBad Diode <bd@badd10de.dev>2021-10-24 11:58:43 +0200
commit6e27b20d10306d53cd838ef375fe80571dfe91ff (patch)
tree3ec4bbc6862e8b50e9e365b35a4e27d9c90d4bbc /src/bytecode/compiler.h
parentb743e03fc6042e3e2d55cfa0387c092824de64c5 (diff)
downloadbdl-6e27b20d10306d53cd838ef375fe80571dfe91ff.tar.gz
bdl-6e27b20d10306d53cd838ef375fe80571dfe91ff.zip
Add updated hash table with intern key-values
Diffstat (limited to 'src/bytecode/compiler.h')
-rwxr-xr-xsrc/bytecode/compiler.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/bytecode/compiler.h b/src/bytecode/compiler.h
index d404a5a..ec51942 100755
--- a/src/bytecode/compiler.h
+++ b/src/bytecode/compiler.h
@@ -33,11 +33,16 @@ has_next_token(const Visitor *visitor) {
33 33
34void 34void
35emit_constant(Chunk *chunk, Token tok, Object obj) { 35emit_constant(Chunk *chunk, Token tok, Object obj) {
36 // TODO: Should we deduplicate constants? For example why store a number 36 size_t prev_size = array_size(chunk->constants);
37 // more than once instead of reusing the existing index?
38 size_t num_idx = add_constant(chunk, obj); 37 size_t num_idx = add_constant(chunk, obj);
39 add_code(chunk, OP_CONSTANT, tok.line, tok.column); 38 add_code(chunk, OP_CONSTANT, tok.line, tok.column);
40 add_code(chunk, num_idx, tok.line, tok.column); 39 add_code(chunk, num_idx, tok.line, tok.column);
40
41 // If the non value constant was already present we need to properly free
42 // the memory from the object given to this function.
43 if (prev_size == array_size(chunk->constants)) {
44 object_free(obj);
45 }
41} 46}
42 47
43void 48void
@@ -180,6 +185,7 @@ parse_list(Chunk *chunk, Visitor *vs, Token start) {
180 .line = start.line, 185 .line = start.line,
181 .col = start.column, 186 .col = start.column,
182 }); 187 });
188 return;
183 } 189 }
184 Token tok = next_token(vs); 190 Token tok = next_token(vs);
185 switch (tok.type) { 191 switch (tok.type) {