ADD: nested functions.

main
bog 2023-08-29 00:14:24 +02:00
parent bc869aa6e8
commit 3f38358390
2 changed files with 34 additions and 4 deletions

View File

@ -412,14 +412,13 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz
type_free(t); free(t);
}
}
int status = cstatic_check(self,
ast->children.data[ast->children.size - 1],
inner_table,
msg,
size
);
symtable_free(inner_table); free(inner_table);
@ -430,6 +429,11 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz
if (ast->type == NODE_RETURN)
{
type* ret_ty = cstatic_resolve_new(self, sym, ast);
int status_inner = cstatic_check_children(self, ast, sym, msg, size);
if (!status_inner) { return status_inner; }
type* fun_ty = cstatic_top_fun(self)->ty;
type* fun_res = NULL;
@ -473,10 +477,25 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz
{
char const* fun_name = ast->children.data[0]->value;
symentry* entry = symtable_find(sym, fun_name);
assert(entry);
type* fun_type = entry->ty;
type* fun_type = NULL;
if (entry)
{
fun_type = entry->ty;
}
else
{
fun_info* info = cstatic_top_fun(self);
if (info && info->name)
{
fun_type = info->ty;
}
}
assert(fun_type);
node* args = ast->children.data[1];
size_t arity = 0;
@ -556,6 +575,7 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz
|| ast->type == NODE_FUNDECL)
{
char const* name = ast->children.data[0]->value;
symentry* entry = symtable_find(sym, name);
if (entry && entry->scope >= sym->scope)
{

View File

@ -55,3 +55,13 @@ fun i (n as int) as int
end
assert 27 == h 3, i
fun j (n as int) as int
fun j_inner (n as int) as int
return n * 2
end
return j_inner (j_inner n)
end
assert 32 == j 8