Calling functions is working, same syntax as compound stmts
This commit is contained in:
@@ -350,11 +350,13 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *const_sym){
|
||||
BREAK();
|
||||
}
|
||||
|
||||
CASE(COMPOUND, Compound){
|
||||
Ast_Resolved_Type *type = resolve_typespec(node->typespec, AST_CAN_BE_NULL);
|
||||
if(!type && expected_type) type = expected_type;
|
||||
else if(!expected_type && type);
|
||||
else if(expected_type != type) parsing_error(node->pos, "Variable type different from explicit compound type");
|
||||
CASE(CALL, Call){
|
||||
Operand name = resolve_expr(node->name);
|
||||
Ast_Resolved_Type *type = name.type;
|
||||
if(name.type == type_type){
|
||||
type = name.type_val;
|
||||
if(expected_type && expected_type != type) parsing_error(node->pos, "Variable type different from explicit compound type");
|
||||
}
|
||||
node->type = type;
|
||||
|
||||
if(type->kind == TYPE_ARRAY){
|
||||
@@ -362,9 +364,8 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *const_sym){
|
||||
Ast_Resolved_Type *item_type = type->arr.base;
|
||||
|
||||
For(node->exprs){
|
||||
assert(it[0]->kind == AST_COMPOUND_ITEM);
|
||||
Ast_Compound_Item *i = (Ast_Compound_Item *)it[0];
|
||||
assert(i->kind == AST_COMPOUND_ITEM);
|
||||
Ast_Call_Item *i = (Ast_Call_Item *)it[0];
|
||||
assert(i->kind == AST_CALL_ITEM);
|
||||
if(i->name) parsing_error(i->pos, "Invalid indexing kind in a compound expression of type %s", type_names[type->kind]);
|
||||
if(i->index){
|
||||
Operand index_op = resolve_expr(i->index);
|
||||
@@ -376,7 +377,20 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *const_sym){
|
||||
resolve_type_pair(i->pos, expr.type, item_type);
|
||||
}
|
||||
}
|
||||
else parsing_error(node->pos, "Invalid compound expression type");
|
||||
else if(type->kind == TYPE_LAMBDA){
|
||||
if(type->func.args.len != node->exprs.len) parsing_error(node->pos, "Invalid number of arguments");
|
||||
For(node->exprs){
|
||||
Ast_Call_Item *i = (Ast_Call_Item *)it[0];
|
||||
assert(i->kind == AST_CALL_ITEM);
|
||||
|
||||
S64 index = node->exprs.get_index(it);
|
||||
Operand expr = resolve_expr(i->item);
|
||||
if(expr.type != type->func.args[index]) parsing_error(i->pos, "Type is not matching function definition");
|
||||
}
|
||||
|
||||
type = type->func.ret;
|
||||
}
|
||||
else parsing_error(node->pos, "Invalid function call type");
|
||||
|
||||
Operand result = {type, false};
|
||||
return result;
|
||||
@@ -457,7 +471,7 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *const_sym){
|
||||
BREAK();
|
||||
}
|
||||
|
||||
// @todo: add const prepass? expecting only structs, exprs, lambdas
|
||||
// @todo: add const first level function? expecting only structs, exprs, lambdas
|
||||
CASE(STRUCT, Struct){
|
||||
assert(const_sym);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user