From 7de941899f47ab5fca87068fa9d092cc36e061a9 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 28 May 2022 17:48:52 +0200 Subject: [PATCH] Fix crashes --- globals.kl | 1 + main.cpp | 4 ++-- new_ast.cpp | 8 ++++---- new_lex.cpp | 1 - new_parse.cpp | 1 + order_independent_globals.kl | 17 +++++++++++++++++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/globals.kl b/globals.kl index fb3406a..e36d3bb 100644 --- a/globals.kl +++ b/globals.kl @@ -27,6 +27,7 @@ array2: [32]int = {1,2,3,4} array3: [32]int = { [0] = null, [1] = 1, + [2] = 2, [31] = 31, } array_item := array1[0] diff --git a/main.cpp b/main.cpp index fe5797c..8d8d87b 100644 --- a/main.cpp +++ b/main.cpp @@ -23,8 +23,8 @@ int main(){ test_intern_table(); lex_test(); - // String result = compile_file("globals.kl"_s); - String result = compile_file("lambdas.kl"_s); + String result = compile_file("globals.kl"_s); + // String result = compile_file("lambdas.kl"_s); // String result = compile_file("order_independent_globals.kl"_s); printf("%s", result.str); diff --git a/new_ast.cpp b/new_ast.cpp index 42b4dea..94e7a0f 100644 --- a/new_ast.cpp +++ b/new_ast.cpp @@ -276,7 +276,7 @@ ast_expr_compound(Token *pos, Ast_Expr *typespec, Array exp AST_NEW(Compound, COMPOUND, pos); result->typespec = typespec; result->exprs = exprs.tight_copy(pctx->perm); - result->typespec->parent = result; + if(result->typespec) result->typespec->parent = result; For(result->exprs) it[0]->parent = result; return result; } @@ -287,8 +287,8 @@ ast_expr_compound_item(Token *pos, Ast_Expr *index, Ast_Atom *name, Ast_Expr *it result->name = name; result->index = index; result->item = item; - name->parent = result; - index->parent = result; + if(result->name) result->name->parent = result; + if(result->index) result->index->parent = result; item->parent = result; return result; } @@ -330,7 +330,7 @@ ast_lambda(Token *pos, Array params, Ast_Expr *ret, Ast_Block result->ret = ret; if(!ret) result->ret = ast_ident(result->pos, intern_void); - result->block->parent = result; + if(result->block) result->block->parent = result; result->ret->parent = result; For(result->args) it[0]->parent = result; return result; diff --git a/new_lex.cpp b/new_lex.cpp index 576e78f..85fc3cb 100644 --- a/new_lex.cpp +++ b/new_lex.cpp @@ -121,7 +121,6 @@ struct Lex_Stream{ String file; S32 line; S32 inside_brace_paren; - S32 last_valid_indent; Array indent_stack; }; diff --git a/new_parse.cpp b/new_parse.cpp index be7ebba..279bed6 100644 --- a/new_parse.cpp +++ b/new_parse.cpp @@ -140,6 +140,7 @@ parse_expr_compound(){ Scratch scratch; Token *pos = token_get(); Array exprs = {scratch}; + while(!token_is(TK_CloseBrace)){ Token *token = token_get(); Ast_Expr *index = 0; diff --git a/order_independent_globals.kl b/order_independent_globals.kl index ba9ca77..fec4a15 100644 --- a/order_independent_globals.kl +++ b/order_independent_globals.kl @@ -1,4 +1,21 @@ +/* +@todo: !!! +Maybe instead of compound exprs like this: + [4]Thing{1,2,3,4} + +Do it like this + [4]Thing(1,2,3,4) + [4]Thing([0]=1, [3]=3) + Thing(a=1, b=2) + +unifying the call expression and compound expression +seems more unified and better for coherence +but more abigous and probably harder to implement + + +*/ + other_func :: () a_val := recursive_lambda