diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-21 14:50:32 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-21 14:50:32 +0200 |
commit | d336498c7cf397de496fa46fccc31883480ecb1d (patch) | |
tree | e3ed49920485c8ed9c02fd74ba09dae2bed69bd3 | |
parent | eea63b71c0a21287c78c456b9674400d0bb45fc2 (diff) | |
download | bdl-d336498c7cf397de496fa46fccc31883480ecb1d.tar.gz bdl-d336498c7cf397de496fa46fccc31883480ecb1d.zip |
Fix scope allocation bug (non zero!)
-rw-r--r-- | src/main.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -59,7 +59,7 @@ typedef struct Analyzer { | |||
59 | Scope * | 59 | Scope * |
60 | scope_alloc(Analyzer *a, Scope *parent) { | 60 | scope_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) { | |||
258 | void | 258 | void |
259 | symbolic_analysis(Analyzer *a, Parser *parser) { | 259 | symbolic_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. |