]> Nishi Git Mirror - gwion.git/commitdiff
:bug: Fix emit_symbol_owned
authorfennecdjay <astor.jeremie@wanadoo.fr>
Sun, 10 Mar 2019 21:38:31 +0000 (22:38 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Sun, 10 Mar 2019 21:38:31 +0000 (22:38 +0100)
src/emit/emit.c
src/vm/vm.c

index a2ab4dac35626226a7cf7a6039ff2ac2fd330ba4..be2fac75486ea7a99bcdd19da95e60b32bded09f 100644 (file)
@@ -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;
 }
 
index 2f4a59b20e90d36b8942d0b159079a187e9060ef..e456afde46008338195c09e9cd05334847ddba4e 100644 (file)
@@ -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()