From a4a695f84a9402a97ed36759f5b20dabf268fca1 Mon Sep 17 00:00:00 2001 From: zongor Date: Thu, 21 May 2026 23:19:47 -0700 Subject: [PATCH] Scopes should be working now, need to still fix early return --- compiler.c | 14 +++++++++----- test/fib.ul | 6 ++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/compiler.c b/compiler.c index 670d9e0..cec394b 100644 --- a/compiler.c +++ b/compiler.c @@ -233,18 +233,23 @@ define_function() /* get return slot */ fn->secondary_type = token_type_to_sym_type(parser.previous.type); /* now parse the fn body */ - expect(TOKEN_LBRACE); } + expect(TOKEN_LBRACE); /* get the size of all the locals for the function in the body */ - while(!match(TOKEN_RBRACE)) { - if(is_type() && parser.current.type == TOKEN_IDENTIFIER) + while(parser.depth > 0) { + if(match(TOKEN_LBRACE)) { + scope_new(); + continue; + } else if(match(TOKEN_RBRACE)) { + scope_pop(); + continue; + } else if(is_type() && parser.current.type == TOKEN_IDENTIFIER) size += variable_declaration(fn); advance(); } fn->size = size; - scope_pop(); } void @@ -623,7 +628,6 @@ void call() { emitter.emit_arena_fn_call(parser.call_fn); parser.current_type = parser.call_fn->secondary_type; - advance(); return; } diff --git a/test/fib.ul b/test/fib.ul index edc5240..d87eada 100755 --- a/test/fib.ul +++ b/test/fib.ul @@ -1,3 +1,7 @@ +function main() { + print(fib(23) as str); +} + /** * Recursively calculate fibonacci */ @@ -5,5 +9,3 @@ function fib(nat n) nat { if (n < 2) { return n; } return fib(n - 2) + fib(n - 1); } - -print(fib(23) as str);