aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-09-17 22:05:40 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commitdcd26bcfcc691f24508a7b6bf04c15042a4668ea (patch)
treef47df3dc79a5ac0b89507890d25843e9c724161b /src
parentb095aedd386e076d1f5a56b7384b836e653387d1 (diff)
Fix function call resolved type
Diffstat (limited to 'src')
-rw-r--r--src/ast.c8
-rw-r--r--src/ssa/ssa.c20
2 files changed, 21 insertions, 7 deletions
diff --git a/src/ast.c b/src/ast.c
index 8e102ee..0008785 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -743,6 +743,14 @@ static void funccall_resolve(Ast *self, AstCompilerContext *context) {
throw(AST_ERR);
}
+ {
+ FunctionSignature *func_sig = self->resolve_data.type.value.func_sig;
+ FunctionReturnType *return_type = buffer_begin(&func_sig->return_types);
+ assert(buffer_get_size(&func_sig->return_types, FunctionReturnType) == 1);
+ self->resolve_data.type.type = RESOLVED_TYPE_LHS_EXPR;
+ self->resolve_data.type = return_type->resolved_type;
+ }
+
ast = buffer_begin(&func_call->args);
ast_end = buffer_end(&func_call->args);
for(; ast != ast_end; ++ast) {
diff --git a/src/ssa/ssa.c b/src/ssa/ssa.c
index 13f19a9..d76ad28 100644
--- a/src/ssa/ssa.c
+++ b/src/ssa/ssa.c
@@ -640,7 +640,7 @@ static CHECK_RESULT SsaRegister funcdecl_generate_ssa(FunctionDecl *self, SsaCom
return 0;
}
-static CHECK_RESULT SsaRegister funccall_generate_ssa(FunctionCall *self, AstResolveData *resolve_data, SsaCompilerContext *context) {
+static CHECK_RESULT SsaRegister funccall_generate_ssa(FunctionCall *self, SsaCompilerContext *context) {
SsaRegister reg;
FunctionSignature *func_sig;
FunctionDecl *func_decl;
@@ -649,12 +649,18 @@ static CHECK_RESULT SsaRegister funccall_generate_ssa(FunctionCall *self, AstRes
context->import_index = 0;
throw_if_error(ssa_get_unique_reg(context->ssa, &reg));
- assert(resolve_data->type.type == RESOLVED_TYPE_FUNC_SIG);
- func_sig = resolve_data->type.value.func_sig;
+ assert(self->func.resolved_var.type == NAMED_OBJECT_LHS_EXPR);
+ func_lhs_expr = self->func.resolved_var.value.lhs_expr;
+ if(func_lhs_expr->type.type == VARIABLE_TYPE_SIGNATURE) {
+ func_sig = func_lhs_expr->type.value.signature;
+ } else if(func_lhs_expr->type.type == VARIABLE_TYPE_VARIABLE) {
+ AstResolveData *resolve_data = func_lhs_expr->type.value.variable->resolved_var.resolve_data;
+ assert(resolve_data->type.type == RESOLVED_TYPE_FUNC_SIG);
+ func_sig = resolve_data->type.value.func_sig;
+ } else {
+ assert(bool_false);
+ }
func_decl = func_sig->func_decl;
- func_lhs_expr = NULL;
- if(self->func.resolved_var.type == NAMED_OBJECT_LHS_EXPR)
- func_lhs_expr = self->func.resolved_var.value.lhs_expr;
/* Push return arguments */
{
@@ -869,7 +875,7 @@ static CHECK_RESULT SsaRegister ast_generate_ssa_resolve_data(void *ast_data, As
resolve_data->ssa_reg = funcdecl_generate_ssa(ast_data, context);
break;
case AST_FUNCTION_CALL:
- resolve_data->ssa_reg = funccall_generate_ssa(ast_data, resolve_data, context);
+ resolve_data->ssa_reg = funccall_generate_ssa(ast_data, context);
break;
case AST_STRUCT_DECL:
resolve_data->ssa_reg = structdecl_generate_ssa(ast_data, context);