From 00ce69d1680f38bfb4fea36694c0ca3ec69a887b Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 5 Sep 2019 19:35:39 +0200 Subject: [PATCH] :bug: One more AFL session --- src/emit/emit.c | 7 ++++++- src/lib/func.c | 29 +++++++++++++++-------------- src/lib/ptr.c | 7 +++++++ src/lib/tuple.c | 4 ++-- src/oo/env_utils.c | 3 ++- src/parse/scan1.c | 3 +++ src/vm/vm_code.c | 10 ++++++++-- 7 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index c6a0180a..e68bda2d 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -970,7 +970,11 @@ ANN m_bool emit_exp_call1(const Emitter emit, const Func f) { 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) && @@ -1648,7 +1652,8 @@ ANN static m_bool emit_member_func(const Emitter emit, const Exp_Dot* member) { 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) diff --git a/src/lib/func.c b/src/lib/func.c index ebedcd47..7d34c9dd 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -67,20 +67,16 @@ struct FptrInfo { 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; } @@ -140,16 +136,19 @@ ANN static Type fptr_type(const Env env, struct FptrInfo *info) { 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; @@ -190,7 +189,9 @@ ANN static m_bool fptr_lambda(const Env env, struct FptrInfo *info) { 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); } diff --git a/src/lib/ptr.c b/src/lib/ptr.c index 73388a52..d1465cdb 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -33,6 +33,12 @@ static INSTR(instr_ptr_assign) { *(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))); @@ -108,6 +114,7 @@ GWION_IMPORT(ptr) { 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)) diff --git a/src/lib/tuple.c b/src/lib/tuple.c index 434edc89..1eb9158d 100644 --- a/src/lib/tuple.c +++ b/src/lib/tuple.c @@ -112,8 +112,8 @@ ANN void emit_unpack_instr(const Emitter emit, struct TupleEmit *te) { } 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); diff --git a/src/oo/env_utils.c b/src/oo/env_utils.c index df445cfd..e88a9910 100644 --- a/src/oo/env_utils.c +++ b/src/oo/env_utils.c @@ -48,7 +48,8 @@ ANN Type find_type(const Env env, ID_List path) { 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) diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 7538d7e5..ea0d4c51 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -154,6 +154,9 @@ ANN static m_bool scan1_exp_call(const Env env, const Exp_Call* exp_call) { } 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); } diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index e011b1a1..6a6d29f3 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -48,8 +48,14 @@ ANN static m_bit* tobytecode(MemPool p, const VM_Code code) { 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); -- 2.43.0