self->getter = NULL;
self->desc = NULL;
- self->argcounter = NULL;
+ self->argcounter = NULL;
return self;
}
vtype->hasvalue = true;
vtype->constval.vfunc = self;
- self->varargs = NULL;
- self->argc = NULL;
+ self->varargs = NULL;
+ self->argc = NULL;
+ self->fixedparams = NULL;
return self;
}
ast_delete(self->varargs);
if (self->argc)
ast_delete(self->argc);
+ if (self->fixedparams)
+ ast_unref(self->fixedparams);
mem_d(self);
}
if (self->argc) {
ir_value *va_count;
+ ir_value *fixed;
+ ir_value *sub;
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;
+ cgen = self->fixedparams->expression.codegen;
+ if (!(*cgen)((ast_expression*)(self->fixedparams), self, false, &fixed))
+ return false;
+ sub = ir_block_create_binop(self->curblock, ast_ctx(self),
+ ast_function_label(self, "va_count"), INSTR_SUB_F,
+ ir_builder_get_va_count(ir), fixed);
+ if (!sub)
+ return false;
if (!ir_block_create_store_op(self->curblock, ast_ctx(self), INSTR_STORE_F,
- va_count, ir_builder_get_va_count(ir)))
+ va_count, sub))
{
return false;
}
ast_value *varargs;
ast_value *argc;
+ ast_value *fixedparams;
};
ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype);
/* This will NOT delete the underlying ast_value */
if ((fun->expression.flags & AST_FLAG_VARIADIC) &&
!(/*funval->cvq == CV_CONST && */ funval->hasvalue && funval->constval.vfunc->builtin))
{
- size_t va_count;
- if (paramcount < vec_size(fun->expression.params))
- va_count = 0;
- else
- va_count = paramcount - vec_size(fun->expression.params);
- call->va_count = (ast_expression*)parser_const_float(parser, (double)va_count);
+ call->va_count = (ast_expression*)parser_const_float(parser, (double)paramcount);
}
}
goto enderrfn;
}
func->varargs = varargs;
+
+ func->fixedparams = parser_const_float(parser, vec_size(var->expression.params));
}
parser->function = func;