vtype->constval.vfunc = self;
self->varargs = NULL;
+ self->argc = NULL;
return self;
}
vec_free(self->continueblocks);
if (self->varargs)
ast_delete(self->varargs);
+ if (self->argc)
+ ast_delete(self->argc);
mem_d(self);
}
{
ir_function *irf;
ir_value *dummy;
- ast_expression_common *ec;
+ ast_expression_common *ec;
+ ast_expression_codegen *cgen;
size_t i;
(void)ir;
return false;
}
+ if (self->argc) {
+ ir_value *va_count;
+ if (!ast_local_codegen(self->argc, self->ir_func, true))
+ return false;
+ cgen = self->argc->expression.codegen;
+ if (!(*cgen)((ast_expression*)(self->argc), self, false, &va_count))
+ return false;
+ if (!ir_block_create_store_op(self->curblock, ast_ctx(self), INSTR_STORE_F,
+ va_count, ir_builder_get_va_count(ir)))
+ {
+ return false;
+ }
+ }
+
for (i = 0; i < vec_size(self->blocks); ++i) {
- ast_expression_codegen *gen = self->blocks[i]->expression.codegen;
- if (!(*gen)((ast_expression*)self->blocks[i], self, false, &dummy))
+ cgen = self->blocks[i]->expression.codegen;
+ if (!(*cgen)((ast_expression*)self->blocks[i], self, false, &dummy))
return false;
}
}
}
- if (var->argcounter) {
- ast_value *argc = ast_value_new(ast_ctx(var), var->argcounter, TYPE_FLOAT);
- ast_block_collect(block, (ast_expression*)argc);
- parser_addlocal(parser, argc->name, (ast_expression*)argc);
- }
-
func = ast_function_new(ast_ctx(var), var->name, var);
if (!func) {
parseerror(parser, "failed to allocate function for `%s`", var->name);
}
vec_push(parser->functions, func);
+ if (var->argcounter) {
+ ast_value *argc = ast_value_new(ast_ctx(var), var->argcounter, TYPE_FLOAT);
+ parser_addlocal(parser, argc->name, (ast_expression*)argc);
+ func->argc = argc;
+ }
+
if (var->expression.flags & AST_FLAG_VARIADIC) {
char name[1024];
ast_value *varargs = ast_value_new(ast_ctx(var), "reserved:va_args", TYPE_ARRAY);