const m_uint);
ANN m_bool check_lambda(const Env, const Type, Exp_Lambda *);
ANN Type check_op_call(const Env env, Exp_Call *const exp);
-ANN void builtin_func(const MemPool mp, const Func f, void *func_ptr);
+ANN void builtin_func(const Gwion gwion, const Func f, void *func_ptr);
ANN static inline Value upvalues_lookup(const Upvalues *upvalues, const Symbol sym) {
const Value v = (Value)scope_lookup1(upvalues->values, (m_uint)sym);
typedef struct VM_Code_ *VM_Code;
struct VM_Code_ {
- m_bit *bytecode;
union {
- struct Vector_ instr;
- m_uint native_func;
+ struct {
+ m_bit *bytecode;
+ struct Vector_ instr;
+ };
+ struct {
+ m_uint native_func;
+ MP_Vector *types;
+ };
};
Type ret_type; // could be `struct Vector_ tmpl_types;`
void * memoize;
safe_tflag(emit->env->class_def, tflag_tmpl)) || (fdef->base->tmpl && !strcmp(s_name(f->base->xid), "new"))) {
const Func base =
nspc_lookup_func1(func->value_ref->from->owner, f->base->xid);
- builtin_func(emit->gwion->mp, func, (f_xfun)base->code->native_func);
+ builtin_func(emit->gwion, func, (f_xfun)base->code->native_func);
return GW_OK;
}
const uint global = GET_FLAG(f->base, global);
return insert_symbol(env->gwion->st, name);
}
-ANN void builtin_func(const MemPool mp, const Func f, void *func_ptr) {
+ANN void builtin_func(const Gwion gwion, const Func f, void *func_ptr) {
set_vflag(f->value_ref, vflag_builtin);
- f->code = new_vmcode(mp, NULL, NULL, f->name, f->def->stack_depth, true, false);
+ f->code = new_vmcode(gwion->mp, NULL, NULL, f->name, f->def->stack_depth, true, false);
f->code->native_func = (m_uint)func_ptr;
f->code->ret_type = f->def->base->ret_type;
+ if(f->def->base->tmpl && f->def->base->tmpl->call) {
+ const Specialized *spec = mp_vector_at(f->def->base->tmpl->list, Specialized, f->def->base->tmpl->list->len - 1);
+ if(!strcmp(s_name(spec->xid), "...")) {
+ f->code->types = new_mp_vector(gwion->mp, Type_Decl*, f->def->base->tmpl->call->len);
+ for(uint32_t i = 0; i < f->def->base->tmpl->call->len; i++) {
+ Type_Decl *const td = *mp_vector_at(f->def->base->tmpl->call, Type_Decl*, i);
+ mp_vector_set(f->code->types, Type, i, known_type(gwion->env, td));
+ }
+ }
+ }
}
}
if (traverse_func_def(gwi->gwion->env, fdef) < 0)
return error_fdef(gwi, fdef);
- builtin_func(gwi->gwion->mp, fdef->base->func, ck->addr);
+ builtin_func(gwi->gwion, fdef->base->func, ck->addr);
return GW_OK;
}
#include "template.h"
static void array_func(const Env env, const Type t, const m_str name, f_xfun fun) {
const Value v = nspc_lookup_value0(t->nspc, insert_symbol(name));
- builtin_func(env->gwion->mp, v->d.func_ref, fun);
+ builtin_func(env->gwion, v->d.func_ref, fun);
}
static OP_CHECK(opck_array_scan) {
? !tflag(base, tflag_struct) ? vm_vector_rem_obj
: vm_vector_rem_struct
: vm_vector_rem;
- builtin_func(env->gwion->mp, (Func)vector_at(&t->nspc->vtable, 0), rem);
+ builtin_func(env->gwion, (Func)vector_at(&t->nspc->vtable, 0), rem);
void *insert = isa(base, env->gwion->type[et_compound]) > 0
? !tflag(base, tflag_struct) ? vm_vector_insert_obj
: vm_vector_insert_struct
if (vflag(v, vflag_builtin)) v->d.func_ref->def->d.dl_func_ptr = xfun;
def->base->tmpl->call = cpy_type_list(env->gwion->mp, fbase->base->tmpl->call);
CHECK_BO(traverse_dot_tmpl(emit, def, v));
- if (vflag(v, vflag_builtin)) builtin_func(emit->gwion->mp, def->base->func, xfun);
+ if (vflag(v, vflag_builtin)) builtin_func(emit->gwion, def->base->func, xfun);
return def;
}
const Func func = ensure_tmpl(env, fdef, ra->e, ra->v->from->filename);
if (func && func->def->builtin) {
- builtin_func(env->gwion->mp, func, (void*)ra->v->d.func_ref->code->native_func);
+ builtin_func(env->gwion, func, (void*)ra->v->d.func_ref->code->native_func);
set_vflag(func->value_ref, vflag_builtin);
struct Op_Import opi = { .lhs = ra->v->d.func_ref->value_ref->type, .rhs = func->value_ref->type };
op_cpy(env, &opi);
def->base->func = func;
nspc_add_value_front(t->info->value->from->owner, sym, value);
if (vflag(t->info->func->value_ref, vflag_builtin)) {
- builtin_func(env->gwion->mp, func, func_ptr);
+ builtin_func(env->gwion, func, func_ptr);
t->info->func->def->d.dl_func_ptr = func_ptr;
}
return ret;