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

index 46e7b325f931a7fba413760c3b22b72ddec815ec..e0abb3893adc34d73bf2bed3a8d3756bbbfecd1a 100644 (file)
@@ -322,6 +322,7 @@ ANN static m_bool prim_array(const Emitter emit, const Exp_Primary * primary) {
   const Instr instr = emit_add_instr(emit, ArrayInit);
   instr->m_val = (m_uint)type;
   instr->m_val2 = base->size;
+  emit_add_instr(emit, GcAdd);
   return GW_OK;
 }
 
@@ -342,11 +343,12 @@ ANN static m_bool emit_exp_array(const Emitter emit, const Exp_Array* array) { G
     instr->m_val = is_var;
     instr->m_val2 = is_var ? SZ_INT : array->self->type->size;
   } else {
+    const Instr push = emit_add_instr(emit, RegPushImm);
+    push->m_val = depth;
     const Instr instr = emit_add_instr(emit, ArrayAccessMulti);
     instr->m_val = is_var || array->self->type->array_depth;
     instr->m_val2 = (is_var || array->self->type->array_depth) ?
       SZ_INT : array_base(array->base->type)->size;
-    *(m_uint*)instr->ptr = depth;
   }
   return GW_OK;
 }
index bf14578ca9f69c42252691ba866e709b77cb68bc..6a3bfba41436c491529ee0cf8cdd9ec56d05a168 100644 (file)
@@ -371,8 +371,8 @@ INSTR(ArrayAccess) { GWDEBUG_EXE
 #define DIM(a) gw_err("\t... at dim [%" INT_F "]\n", (a))
 
 INSTR(ArrayAccessMulti) { GWDEBUG_EXE
-  const m_uint depth = *(m_uint*)instr->ptr;
-  POP_REG(shred, SZ_INT * (depth + 1));
+  const m_uint depth = *(m_uint*)REG(-SZ_INT);
+  POP_REG(shred, SZ_INT * (depth + 2))
   const M_Object base = *(M_Object*)REG(0);
   M_Object obj = base;
   if(!obj)