ADD: nested functions.
parent
bc869aa6e8
commit
3f38358390
|
@ -419,7 +419,6 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz
|
||||||
msg,
|
msg,
|
||||||
size
|
size
|
||||||
);
|
);
|
||||||
|
|
||||||
symtable_free(inner_table); free(inner_table);
|
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)
|
if (ast->type == NODE_RETURN)
|
||||||
{
|
{
|
||||||
type* ret_ty = cstatic_resolve_new(self, sym, ast);
|
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_ty = cstatic_top_fun(self)->ty;
|
||||||
|
|
||||||
type* fun_res = NULL;
|
type* fun_res = NULL;
|
||||||
|
@ -473,9 +477,24 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz
|
||||||
{
|
{
|
||||||
char const* fun_name = ast->children.data[0]->value;
|
char const* fun_name = ast->children.data[0]->value;
|
||||||
symentry* entry = symtable_find(sym, fun_name);
|
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];
|
node* args = ast->children.data[1];
|
||||||
size_t arity = 0;
|
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)
|
|| ast->type == NODE_FUNDECL)
|
||||||
{
|
{
|
||||||
char const* name = ast->children.data[0]->value;
|
char const* name = ast->children.data[0]->value;
|
||||||
|
|
||||||
symentry* entry = symtable_find(sym, name);
|
symentry* entry = symtable_find(sym, name);
|
||||||
if (entry && entry->scope >= sym->scope)
|
if (entry && entry->scope >= sym->scope)
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,3 +55,13 @@ fun i (n as int) as int
|
||||||
end
|
end
|
||||||
|
|
||||||
assert 27 == h 3, i
|
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
|
||||||
|
|
Loading…
Reference in New Issue