From: fennecdjay Date: Sun, 10 Mar 2019 21:38:31 +0000 (+0100) Subject: :bug: Fix emit_symbol_owned X-Git-Tag: nightly~2753^2~9 X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=d548db2475e1bc04fe711ab84de12e16ac3a1113;p=gwion.git :bug: Fix emit_symbol_owned --- diff --git a/src/emit/emit.c b/src/emit/emit.c index a2ab4dac..be2fac75 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -241,16 +241,36 @@ static const f_instr dotmember[] = { DotMember, DotMember2, DotMember3, DotMemb static const f_instr allocmember[] = { RegPushImm, RegPushImm2, RegPushImm3, AllocMember4 }; static const f_instr allocword[] = { AllocWord, AllocWord2, AllocWord3, AllocWord4 }; -ANN static m_bool emit_symbol_owned(const Emitter emit, const Exp_Primary* prim) { GWDEBUG_EXE - const Value v = prim->value; - const Exp exp = new_exp_prim_id(insert_symbol("this"), prim->self->pos); +ANN static inline Exp this_exp(const Type t, const uint pos) { + const Exp exp = new_exp_prim_id(insert_symbol("this"), pos); + exp->type = t; + return exp; +} + +ANN static inline Exp dot_this_exp(const Exp_Primary* prim, const Type t) { + const Exp exp = this_exp(t, prim->self->pos); const Exp dot = new_exp_dot(exp, prim->d.var); - exp->type = v->owner_class; - dot->d.exp_dot.t_base = v->owner_class; + dot->d.exp_dot.t_base = t; + return dot; +} + +ANN static inline Exp dot_static_exp(const Exp_Primary* prim, const Type t) { + const Symbol s = insert_symbol(t->name); + const Exp e = new_exp_prim_id(s, prim->self->pos); + const Value val = nspc_lookup_value1(t->nspc->parent, s); + const Exp dot = new_exp_dot(e, prim->d.var); + dot->d.exp_dot.t_base = val->type; + return dot; +} + +ANN static m_bool emit_symbol_owned(const Emitter emit, const Exp_Primary* prim) { + const Value v = prim->value; + const Exp dot = !GET_FLAG(v, static) ? + dot_this_exp(prim, v->owner_class) : dot_static_exp(prim, v->owner_class); dot->type = v->type; dot->emit_var = prim->self->emit_var; const m_bool ret = emit_exp_dot(emit, &dot->d.exp_dot); - free_exp(exp); + free_exp(dot); return ret; } diff --git a/src/vm/vm.c b/src/vm/vm.c index 2f4a59b2..e456afde 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -714,7 +714,7 @@ dotstaticfunc: *(VM_Code*)(reg-SZ_INT) = ((Func)vector_at(a.obj->vtable, instr->m_val))->code; DISPATCH() staticcode: - instr->m_val = (m_uint)((*(VM_Code*)reg = ((Func)instr->m_val)->code)); + instr->m_val = (m_uint)(a.code = (*(VM_Code*)reg = ((Func)instr->m_val)->code)); instr->opcode = eRegPushImm; reg += SZ_INT; DISPATCH()