aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-06-21 14:50:32 +0200
committerBad Diode <bd@badd10de.dev>2024-06-21 14:50:32 +0200
commitd336498c7cf397de496fa46fccc31883480ecb1d (patch)
treee3ed49920485c8ed9c02fd74ba09dae2bed69bd3
parenteea63b71c0a21287c78c456b9674400d0bb45fc2 (diff)
downloadbdl-d336498c7cf397de496fa46fccc31883480ecb1d.tar.gz
bdl-d336498c7cf397de496fa46fccc31883480ecb1d.zip
Fix scope allocation bug (non zero!)
-rw-r--r--src/main.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index a16b0e6..7cb0b87 100644
--- a/src/main.c
+++ b/src/main.c
@@ -59,7 +59,7 @@ typedef struct Analyzer {
59Scope * 59Scope *
60scope_alloc(Analyzer *a, Scope *parent) { 60scope_alloc(Analyzer *a, Scope *parent) {
61 bool is_root = parent == NULL; 61 bool is_root = parent == NULL;
62 Scope *scope = arena_malloc(sizeof(Scope), a->storage); 62 Scope *scope = arena_calloc(sizeof(Scope), a->storage);
63 scope->id = a->scope_gen++; 63 scope->id = a->scope_gen++;
64 scope->parent = parent; 64 scope->parent = parent;
65 scope->depth = is_root ? 0 : parent->depth + 1; 65 scope->depth = is_root ? 0 : parent->depth + 1;
@@ -258,6 +258,9 @@ analyzer_symbols(Analyzer *a, Node *node, Scope *scope) {
258void 258void
259symbolic_analysis(Analyzer *a, Parser *parser) { 259symbolic_analysis(Analyzer *a, Parser *parser) {
260 Scope *scope = scope_alloc(a, NULL); 260 Scope *scope = scope_alloc(a, NULL);
261 assert(a);
262 assert(parser);
263 assert(scope);
261 264
262 // Fill builtin functions. 265 // Fill builtin functions.
263 Str builtin_functions[] = { 266 Str builtin_functions[] = {
@@ -266,8 +269,8 @@ symbolic_analysis(Analyzer *a, Parser *parser) {
266 }; 269 };
267 for (sz i = 0; i < LEN(builtin_functions); i++) { 270 for (sz i = 0; i < LEN(builtin_functions); i++) {
268 Str symbol = builtin_functions[i]; 271 Str symbol = builtin_functions[i];
269 symmap_insert(&scope->symbols, symbol, (Symbol){.kind = SYM_BUILTIN}, 272 Symbol sym = (Symbol){.kind = SYM_BUILTIN};
270 a->storage); 273 symmap_insert(&scope->symbols, symbol, sym, a->storage);
271 } 274 }
272 275
273 // Find top level function declarations. 276 // Find top level function declarations.