Fix invalid pointer in struct type, more work on calls

This commit is contained in:
Krzosa Karol
2022-05-30 11:20:00 +02:00
parent 671853287a
commit b2d3e9d8e1
4 changed files with 17 additions and 5 deletions

View File

@@ -25,11 +25,14 @@ add_10 :: (size: int): int
constant :: 20; result := constant + 10 constant :: 20; result := constant + 10
v5 := add([0] = 1, [1] = 2)
v1 := add(a = 1) v1 := add(a = 1)
v2 := add(a = 1, b = 2) v2 := add(a = 1, b = 2)
v3 := add([0] = 1) v3 := add([0] = 1)
v4 := add(b = 1, a = 2) v4 := add(b = 1, a = 2)
v5 := add([0] = 1, [1] = 2)
// v_err := add([0] = 1, 10) // illegal
// v_err := add([1] = 1) // illegal
// v_err := add() // illegal
return v3 return v3

View File

@@ -65,8 +65,8 @@ int main(){
String result = {}; String result = {};
// result = compile_file("order1.kl"_s); // result = compile_file("order1.kl"_s);
result = compile_file("lambdas.kl"_s); // result = compile_file("lambdas.kl"_s);
// result = compile_file("order2.kl"_s); result = compile_file("order2.kl"_s);
// result = compile_file("globals.kl"_s); // result = compile_file("globals.kl"_s);
printf("%s", result.str); printf("%s", result.str);

View File

@@ -391,6 +391,7 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *const_sym){
Ast_Resolved_Type *resolved = type->func.args[i]; Ast_Resolved_Type *resolved = type->func.args[i];
Ast_Lambda_Arg *arg = it[0]; Ast_Lambda_Arg *arg = it[0];
// @note: match any in list of call items, if none matched then we have a problem // @note: match any in list of call items, if none matched then we have a problem
// there are three kinds of possible matches: indexed, named, default // there are three kinds of possible matches: indexed, named, default
S64 default_iter = 0; S64 default_iter = 0;
@@ -411,10 +412,12 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *const_sym){
if(op.int_val == i) item = expr[0]; if(op.int_val == i) item = expr[0];
} }
else if(node->exprs.get_index(expr) == default_iter){ else if(node->exprs.get_index(expr) == default_iter){
// @todo might feel janky
default_iter++; default_iter++;
item = expr[0]; item = expr[0];
} }
else{
parsing_error(expr[0]->pos, "Positional argument after named or indexed argument");
}
if(item) break; if(item) break;
} }
@@ -642,7 +645,7 @@ parse_file(){
sym->kind = SYM_CONST; sym->kind = SYM_CONST;
Ast_Struct *s = const_try_getting_struct(decl); Ast_Struct *s = const_try_getting_struct(decl);
if(s){ if(s){
s->type = type_incomplete(decl); s->type = type_incomplete(s);
sym->type_val = s->type; sym->type_val = s->type;
sym->type = type_type; sym->type = type_type;
sym->state = SYM_RESOLVED; sym->state = SYM_RESOLVED;

View File

@@ -21,4 +21,10 @@ with_type: Arena = thing
pointer := &with_type pointer := &with_type
deref := *pointer deref := *pointer
arena := Arena(
next = 0,
data = 0,
len = 1000,
cap = 1000,
)