Fix crashes

This commit is contained in:
Krzosa Karol
2022-05-28 17:48:52 +02:00
parent 798453c7db
commit 7de941899f
6 changed files with 25 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ array2: [32]int = {1,2,3,4}
array3: [32]int = { array3: [32]int = {
[0] = null, [0] = null,
[1] = 1, [1] = 1,
[2] = 2,
[31] = 31, [31] = 31,
} }
array_item := array1[0] array_item := array1[0]

View File

@@ -23,8 +23,8 @@ int main(){
test_intern_table(); test_intern_table();
lex_test(); lex_test();
// String result = compile_file("globals.kl"_s); String result = compile_file("globals.kl"_s);
String result = compile_file("lambdas.kl"_s); // String result = compile_file("lambdas.kl"_s);
// String result = compile_file("order_independent_globals.kl"_s); // String result = compile_file("order_independent_globals.kl"_s);
printf("%s", result.str); printf("%s", result.str);

View File

@@ -276,7 +276,7 @@ ast_expr_compound(Token *pos, Ast_Expr *typespec, Array<Ast_Compound_Item *> exp
AST_NEW(Compound, COMPOUND, pos); AST_NEW(Compound, COMPOUND, pos);
result->typespec = typespec; result->typespec = typespec;
result->exprs = exprs.tight_copy(pctx->perm); 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; For(result->exprs) it[0]->parent = result;
return 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->name = name;
result->index = index; result->index = index;
result->item = item; result->item = item;
name->parent = result; if(result->name) result->name->parent = result;
index->parent = result; if(result->index) result->index->parent = result;
item->parent = result; item->parent = result;
return result; return result;
} }
@@ -330,7 +330,7 @@ ast_lambda(Token *pos, Array<Ast_Lambda_Arg *> params, Ast_Expr *ret, Ast_Block
result->ret = ret; result->ret = ret;
if(!ret) result->ret = ast_ident(result->pos, intern_void); 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; result->ret->parent = result;
For(result->args) it[0]->parent = result; For(result->args) it[0]->parent = result;
return result; return result;

View File

@@ -121,7 +121,6 @@ struct Lex_Stream{
String file; String file;
S32 line; S32 line;
S32 inside_brace_paren; S32 inside_brace_paren;
S32 last_valid_indent;
Array<Token *> indent_stack; Array<Token *> indent_stack;
}; };

View File

@@ -140,6 +140,7 @@ parse_expr_compound(){
Scratch scratch; Scratch scratch;
Token *pos = token_get(); Token *pos = token_get();
Array<Ast_Compound_Item *> exprs = {scratch}; Array<Ast_Compound_Item *> exprs = {scratch};
while(!token_is(TK_CloseBrace)){ while(!token_is(TK_CloseBrace)){
Token *token = token_get(); Token *token = token_get();
Ast_Expr *index = 0; Ast_Expr *index = 0;

View File

@@ -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 :: () other_func :: ()
a_val := recursive_lambda a_val := recursive_lambda