]> Nishi Git Mirror - gwion.git/commitdiff
:art: Push litteral array depth on the stack
authorfennecdjay <astor.jeremie@wanadoo.fr>
Fri, 15 Feb 2019 16:10:49 +0000 (17:10 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Fri, 15 Feb 2019 16:10:49 +0000 (17:10 +0100)
src/emit/emit.c
src/lib/array.c

index 958514fc3340a1ea6f0825ac11ec05e1bc3b254a..46e7b325f931a7fba413760c3b22b72ddec815ec 100644 (file)
@@ -317,10 +317,11 @@ ANN static m_bool prim_array(const Emitter emit, const Exp_Primary * primary) {
   while((e = e->next));
   const Type type = array->type;
   const Type base = array_base(type);
+  const Instr push = emit_add_instr(emit, RegPushImm);
+  push->m_val = count;
   const Instr instr = emit_add_instr(emit, ArrayInit);
-  instr->m_val = count;
+  instr->m_val = (m_uint)type;
   instr->m_val2 = base->size;
-  *(Type*)instr->ptr = type;
   return GW_OK;
 }
 
index e38aa100a2f58ebcb499f7777b35456ea9156100..bf14578ca9f69c42252691ba866e709b77cb68bc 100644 (file)
@@ -253,11 +253,11 @@ INSTR(ArrayPost) { GWDEBUG_EXE
 }
 
 INSTR(ArrayInit) { GWDEBUG_EXE // for litteral array
-  const m_uint off = instr->m_val * instr->m_val2;
-  const Type t = *(Type*)instr->ptr;
-  POP_REG(shred, off - SZ_INT);
-  const M_Object obj = new_array(t, instr->m_val);
-  vector_add(&shred->gc, (vtype)obj);
+  const Type t = (Type)instr->m_val;
+  const m_uint sz = *(m_uint*)REG(-SZ_INT);
+  const m_uint off = instr->m_val2 * sz;
+  POP_REG(shred, off /*- SZ_INT*/);
+  const M_Object obj = new_array(t, sz);
   memcpy(ARRAY(obj)->ptr + ARRAY_OFFSET, REG(-SZ_INT), off);
   *(M_Object*)REG(-SZ_INT) = obj;
 }