Scopes should be working now, need to still fix early return

This commit is contained in:
zongor 2026-05-21 23:19:47 -07:00
parent 99675eb6d3
commit a4a695f84a
2 changed files with 13 additions and 7 deletions

View File

@ -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;
}

View File

@ -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);