ir_value *v = NULL;
if (self->isconst && self->expression.vtype == TYPE_FUNCTION)
{
- ir_function *func = ir_builder_create_function(ir, self->name);
+ ir_function *func = ir_builder_create_function(ir, self->name, self->expression.next->expression.vtype);
if (!func)
return false;
bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value **out)
{
/* TODO: call ir codegen */
+ ast_expression_codegen *cgen;
+ ir_value_vector params;
+ ir_instr *callinstr;
+ size_t i;
+
+ ir_value *funval = NULL;
+
+ /* return values are never rvalues */
+ (void)lvalue;
+
+ cgen = self->func->expression.codegen;
+ if (!(*cgen)((ast_expression*)(self->func), func, false, &funval))
+ return false;
+ if (!funval)
+ return false;
+
+ MEM_VECTOR_INIT(¶ms, v);
+
+ /* parameters */
+ for (i = 0; i < self->params_count; ++i)
+ {
+ ir_value *param;
+ ast_expression *expr = self->params[i];
+
+ cgen = expr->expression.codegen;
+ if (!(*cgen)(expr, func, false, ¶m))
+ goto error;
+ if (!param)
+ goto error;
+ if (!ir_value_vector_v_add(¶ms, param))
+ goto error;
+ }
+
+ callinstr = ir_block_create_call(func->curblock, ast_function_label(func, "call"), funval);
+ if (!callinstr)
+ goto error;
+
+ for (i = 0; i < params.v_count; ++i) {
+ if (!ir_call_param(callinstr, params.v[i]))
+ goto error;
+ }
+
+ *out = ir_call_value(callinstr);
+
+ return true;
+error:
+ MEM_VECTOR_CLEAR(¶ms, v);
return false;
}