Scopes should be working now, need to still fix early return
This commit is contained in:
parent
99675eb6d3
commit
a4a695f84a
14
compiler.c
14
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue