ADD: high order functions.
parent
9b31a14723
commit
bc869aa6e8
|
@ -63,7 +63,6 @@ type* cstatic_resolve_new(cstatic* self, symtable* sym, node* ast)
|
||||||
type_new_from_node(
|
type_new_from_node(
|
||||||
ast->children.data[i]->children.data[1]
|
ast->children.data[i]->children.data[1]
|
||||||
);
|
);
|
||||||
|
|
||||||
type_add_sub_type(ty, param_ty);
|
type_add_sub_type(ty, param_ty);
|
||||||
type_free(param_ty); free(param_ty);
|
type_free(param_ty); free(param_ty);
|
||||||
|
|
||||||
|
@ -90,7 +89,6 @@ type* cstatic_resolve_new(cstatic* self, symtable* sym, node* ast)
|
||||||
if (ast->type == NODE_CALL)
|
if (ast->type == NODE_CALL)
|
||||||
{
|
{
|
||||||
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);
|
||||||
fun_info* info = NULL;
|
fun_info* info = NULL;
|
||||||
|
|
||||||
|
@ -126,12 +124,13 @@ type* cstatic_resolve_new(cstatic* self, symtable* sym, node* ast)
|
||||||
|
|
||||||
if (ret_count > 0)
|
if (ret_count > 0)
|
||||||
{
|
{
|
||||||
type* ret_type = fun_type->sub_types.data[ret_count - 1];
|
type* ret_type =
|
||||||
|
fun_type->sub_types.data[ret_count - 1];
|
||||||
|
|
||||||
assert(ret_type);
|
assert(ret_type);
|
||||||
|
|
||||||
if (ret_type->kind == KIND_RETURN)
|
if (ret_type->kind == KIND_RETURN)
|
||||||
{
|
{
|
||||||
|
|
||||||
type* res = type_new_clone(ret_type);
|
type* res = type_new_clone(ret_type);
|
||||||
res->kind = KIND_CONJUNCTION;
|
res->kind = KIND_CONJUNCTION;
|
||||||
return res;
|
return res;
|
||||||
|
@ -190,8 +189,6 @@ type* cstatic_resolve_new(cstatic* self, symtable* sym, node* ast)
|
||||||
|| ast->type == NODE_CONSTDECL
|
|| ast->type == NODE_CONSTDECL
|
||||||
|| ast->type == NODE_FUNDECL)
|
|| ast->type == NODE_FUNDECL)
|
||||||
{
|
{
|
||||||
char* name = ast->children.data[0]->value;
|
|
||||||
printf("-> %s\n", name);
|
|
||||||
type* ty = cstatic_resolve_new(self,
|
type* ty = cstatic_resolve_new(self,
|
||||||
sym,
|
sym,
|
||||||
ast->children.data[1]);
|
ast->children.data[1]);
|
||||||
|
@ -448,7 +445,7 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(fun_res);
|
assert(fun_res);
|
||||||
|
assert(ret_ty);
|
||||||
int status = cstatic_check_same_type_ptr(
|
int status = cstatic_check_same_type_ptr(
|
||||||
self,
|
self,
|
||||||
ast,
|
ast,
|
||||||
|
|
|
@ -35,6 +35,7 @@ type* type_init_from_node(node* root)
|
||||||
for (size_t i=0; i< rets->children.size; i++)
|
for (size_t i=0; i< rets->children.size; i++)
|
||||||
{
|
{
|
||||||
type* t = type_new_from_node(rets->children.data[i]);
|
type* t = type_new_from_node(rets->children.data[i]);
|
||||||
|
t->kind = KIND_RETURN;
|
||||||
type_add_sub_type(ty, t);
|
type_add_sub_type(ty, t);
|
||||||
type_free(t); free(t);
|
type_free(t); free(t);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,3 +46,12 @@ end
|
||||||
|
|
||||||
assert 120 == f 5
|
assert 120 == f 5
|
||||||
|
|
||||||
|
fun h (n as int, m as fun<int:int>) as int
|
||||||
|
return (m (m n))
|
||||||
|
end
|
||||||
|
|
||||||
|
fun i (n as int) as int
|
||||||
|
return n * 3
|
||||||
|
end
|
||||||
|
|
||||||
|
assert 27 == h 3, i
|
||||||
|
|
Loading…
Reference in New Issue