From d6401ff05ddcb05d9733d525f54fc7ca6c48f8f7 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 27 May 2022 15:35:15 +0200 Subject: [PATCH] Recursive lambdas with new system --- cgenerate.cpp => ccodegen.cpp | 0 lambdas.kl | 10 ++-------- main.cpp | 8 ++++---- new_resolve.cpp | 12 ++++-------- 4 files changed, 10 insertions(+), 20 deletions(-) rename cgenerate.cpp => ccodegen.cpp (100%) diff --git a/cgenerate.cpp b/ccodegen.cpp similarity index 100% rename from cgenerate.cpp rename to ccodegen.cpp diff --git a/lambdas.kl b/lambdas.kl index 74a0afa..ccf7541 100644 --- a/lambdas.kl +++ b/lambdas.kl @@ -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 diff --git a/main.cpp b/main.cpp index 2d72769..4c91cb0 100644 --- a/main.cpp +++ b/main.cpp @@ -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); diff --git a/new_resolve.cpp b/new_resolve.cpp index a8d1ec1..8025fe1 100644 --- a/new_resolve.cpp +++ b/new_resolve.cpp @@ -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){