Recursive lambdas with new system

This commit is contained in:
Krzosa Karol
2022-05-27 15:35:15 +02:00
parent 79aa52e726
commit d6401ff05d
4 changed files with 10 additions and 20 deletions

View File

@@ -1,13 +1,7 @@
/*
@todo!!!
I think it might be better to try doing order indepent decls
as well as the tree transformations in the backend code
plus some cleanups before adding more complications to the code
*/
type :: int
pointer_type :: *int
null_pointer: pointer_type = null
if_stmt :: (cond: int): type
CONSTANT :: 10

View File

@@ -5,10 +5,10 @@
#include "new_parse.cpp"
#include "new_type.cpp"
#include "new_resolve.cpp"
#include "cgenerate.cpp"
#include "ccodegen.cpp"
/// @todo
/// [ ] - Typespecs should probably be expressions so stuff like would be possible :: *[32]int
/// [x] - Typespecs should probably be expressions so stuff like would be possible :: *[32]int
int main(){
@@ -24,8 +24,8 @@ int main(){
lex_test();
// String result = compile_file("globals.kl"_s);
String result = compile_file("lambdas.kl"_s);
// String result = compile_file("order_independent_globals.kl"_s);
// String result = compile_file("lambdas.kl"_s);
String result = compile_file("order_independent_globals.kl"_s);
printf("%s", result.str);
// compile_file("lambdas.kl"_s);

View File

@@ -334,6 +334,10 @@ eval_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_comple
assert(lambda_type);
Value val; val.type_val = lambda_type;
sym_new_resolved(SYM_CONST, {}, type_type, val, node);
if(lambda_to_complete){
lambda_to_complete->type = lambda_type;
lambda_to_complete->state = SYM_RESOLVED;
}
}
Operand result = {type_type, true};
@@ -533,14 +537,6 @@ resolve_sym(Sym *sym){
assert(sym->ast->kind == AST_VAR || sym->ast->kind == AST_CONST);
sym->state = SYM_RESOLVING;
// @note: lambda doesn't need body for it to be usable
// quickly resolve the type so we can have recursive functions
// Ast_Lambda *lambda = ast_get_lambda(sym->ast);
// if(lambda){
// sym->type = eval_typespec(ast_typespec_lambda(lambda->pos, lambda));
// sym->state = SYM_RESOLVED;
// }
Operand op = eval_decl(sym->ast, sym);
sym->type = op.type;
if(sym->kind == SYM_CONST){