else {
const Instr back = (Instr)vector_back(&emit->code->instr);
back->opcode = ePushStaticCode;
+ back->m_val = 0;
}
+ }else if(emit->env->func != f && !f->value_ref->owner_class && !f->code && !is_fptr(f->value_ref->type)) {
+ const Instr back = emit_add_instr(emit, PushStaticCode);
+ back->m_val = (m_uint)f;
}
} else if((f->value_ref->owner_class && is_special(f->value_ref->owner_class) > 0) ||
!f->value_ref->owner_class || (GET_FLAG(f, template) &&
const Func f = exp_self(member)->type->e->d.func;
if(isa(member->t_base, t_class) > 0 || GET_FLAG(member->base->type, force)) {
const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : PushStaticCode);
- func_i->m_val = (m_uint)(f->code ?: (VM_Code)f);
+ if(f->code)
+ func_i->m_val = (m_uint)(f->code ?: (VM_Code)f);
return GW_OK;
}
if(f->def->base->tmpl)
ANN static m_bool fptr_tmpl_push(const Env env, struct FptrInfo *info) {
if(!info->rhs->def->base->tmpl)
return GW_OK;
-// some kind of template_match ?
ID_List t0 = info->lhs->def->base->tmpl->list,
t1 = info->rhs->def->base->tmpl->list;
-nspc_push_type(env->gwion->mp, env->curr);
+ nspc_push_type(env->gwion->mp, env->curr);
while(t0) {
-// CHECK_OB(t1)
-nspc_add_type(env->curr, t0->xid, t_undefined);//
-nspc_add_type(env->curr, t1->xid, t_undefined);//
+ nspc_add_type(env->curr, t0->xid, t_undefined);
+ nspc_add_type(env->curr, t1->xid, t_undefined);
t0 = t0->next;
t1 = t1->next;
}
-// CHECK_BB(template_push_types(env, info->lhs->def->base->tmpl))
-// return template_push_types(env, info->rhs->def->base->tmpl);
-return GW_OK;//
+ return GW_OK;
}
for(m_uint i = 0; i <= v->offset && !type; ++i) {
const Symbol sym = (!info->lhs->def->base->tmpl || i != 0) ?
func_symbol(env, nspc->name, c, stmpl, i) : info->lhs->def->base->xid;
- CHECK_OO((info->lhs = nspc_lookup_func1(nspc, sym)))
+ if(isa(info->lhs->value_ref->type, t_class) < 0)
+ CHECK_OO((info->lhs = nspc_lookup_func1(nspc, sym)))
+ else {
+ DECL_OO(const Type, t, = nspc_lookup_type1(nspc, info->lhs->def->base->xid))
+ info->lhs = actual_type(t)->e->d.func;
+ }
Func_Base *base[2] = { info->lhs->def->base, info->rhs->def->base };
if(fptr_tmpl_push(env, info) > 0) {
if(fptr_rettype(env, info) > 0 &&
fptr_arity(info) && fptr_args(env, base) > 0)
- type = info->lhs->value_ref->type;
- if(info->rhs->def->base->tmpl) {
-// nspc_pop_type(env->gwion->mp, env->curr);
+ type = actual_type(info->lhs->value_ref->type) ?: info->lhs->value_ref->type;
+ if(info->rhs->def->base->tmpl)
nspc_pop_type(env->gwion->mp, env->curr);
- }
}
}
return type;
ANN static m_bool fptr_do(const Env env, struct FptrInfo *info) {
if(isa(info->exp->type, t_lambda) < 0) {
CHECK_BB(fptr_check(env, info))
- return (info->exp->type = fptr_type(env, info)) ? GW_OK : GW_ERROR;
+ DECL_OB(const Type, t, = fptr_type(env, info))
+ info->exp->type = t;
+ return GW_OK;
}
return fptr_lambda(env, info);
}
*(m_uint**)o->data = *(m_uint**)REG(-SZ_INT);
}
+static OP_EMIT(opem_ptr_assign) {
+ emit_add_instr(emit, GWOP_EXCEPT);
+ emit_add_instr(emit, instr_ptr_assign);
+ return GW_OK;
+}
+
static OP_CHECK(opck_ptr_deref) {
const Exp_Unary* unary = (Exp_Unary*)data;
return exp_self(unary)->type = nspc_lookup_type1(unary->exp->type->e->owner, insert_symbol(env->gwion->st, get_type_name(env, unary->exp->type->name, 1)));
t_ptr->nspc->info->offset = SZ_INT;
GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "Ptr", NULL))
GWI_BB(gwi_oper_add(gwi, opck_ptr_assign))
+ GWI_BB(gwi_oper_emi(gwi, opem_ptr_assign))
GWI_BB(gwi_oper_end(gwi, ":=>", instr_ptr_assign))
GWI_BB(gwi_oper_add(gwi, opck_implicit_ptr))
GWI_BB(gwi_oper_end(gwi, "@implicit", Cast2Ptr))
}
static m_bool tuple_match(const Type lhs, const Type rhs) {
- const Vector lv = &lhs->e->tuple->types;
- const Vector rv = &rhs->e->tuple->types;
+ DECL_OB(const Vector, lv, = &lhs->e->tuple->types)
+ DECL_OB(const Vector, rv, = &rhs->e->tuple->types)
for(m_uint i = 0; i < vector_size(rv); i++) {
DECL_OB(const Type, l, = (Type)vector_at(lv, i))
const Type r = (Type)vector_at(rv, i);
if(nspc) {
Type t = nspc_lookup_type1(nspc, xid);
while(!t && type && type->e->parent) {
- t = nspc_lookup_type1(type->e->parent->nspc, xid); // was lookup2
+ if(type->e->parent->nspc) // should we break sooner ?
+ t = nspc_lookup_type1(type->e->parent->nspc, xid); // was lookup2
type = type->e->parent;
}
if(!t)
}
ANN static inline m_bool scan1_exp_dot(const Env env, const Exp_Dot* member) {
+ if(member->base->next)
+ ERR_B(member->base->pos, _("can't use multiple expression"
+ " in dot member base expression"))
return scan1_exp(env, member->base);
}
for(m_uint i= 0; i < sz; ++i) {
const Instr instr = (Instr)vector_at(v, i);
if(instr->opcode == ePushStaticCode) {
- instr->opcode = eRegPushImm;
- instr->m_val = (m_uint)code;
+ if(!instr->m_val) {
+ instr->opcode = eRegPushImm;
+ instr->m_val = (m_uint)code;
+ } else {
+ instr->opcode = eRegSetImm;
+ instr->m_val = (m_uint)((Func)instr->m_val)->code;
+ instr->m_val2 = -SZ_INT;
+ }
}
if(instr->opcode < eGack)
memcpy(ptr + i*BYTECODE_SZ, instr, BYTECODE_SZ);