]> Nishi Git Mirror - gwion.git/commitdiff
:art: Instr => Opcode : ArrayAppend
authorfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 26 Mar 2019 19:06:10 +0000 (20:06 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 26 Mar 2019 19:06:10 +0000 (20:06 +0100)
include/instr.h
include/opcode.h
opcode.txt
src/lib/array.c
src/vm/vm.c

index ec5baff37ff0295a1df7b9f623cf43dd74051adf..627c319919cb5c4d78588f2eae1b3749874aefce 100644 (file)
@@ -51,7 +51,6 @@ INSTR(ArrayInit);
 INSTR(ArrayAlloc);
 INSTR(ArrayAccess);
 INSTR(ArrayAccessMulti);
-INSTR(ArrayAppend);
 
 /* vararg */
 INSTR(VarargIni);
index 27c1ff82e08d98e48693955a686871c0e998fbba..55eb297be6506e93473bfd55d59882f2b20423e0 100644 (file)
@@ -141,6 +141,7 @@ enum {
   eBranchNeqFloat,
   eDecIntAddr,
   eInitLoopCounter,
+  eArrayAppend,
   eArrayTop,
   eObjectInstantiate,
   eRegAddRef,
@@ -306,6 +307,7 @@ enum {
 #define  BranchNeqFloat      (f_instr)eBranchNeqFloat
 #define  DecIntAddr          (f_instr)eDecIntAddr
 #define  InitLoopCounter     (f_instr)eInitLoopCounter
+#define  ArrayAppend         (f_instr)eArrayAppend
 #define  ArrayTop            (f_instr)eArrayTop
 #define  ObjectInstantiate   (f_instr)eObjectInstantiate
 #define  RegAddRef           (f_instr)eRegAddRef
index 00a918a244cd7d537b01ecaba841fa9788ab1592..e05385dde72d4897ba07f6896e33561bcfb7da06 100644 (file)
@@ -138,6 +138,7 @@ BranchEqFloat
 BranchNeqFloat
 DecIntAddr
 InitLoopCounter
+ArrayAppend
 ArrayTop
 ObjectInstantiate
 RegAddRef
index 18286313ff8c726e14bb1476d869dd716d364b39..57942735d007518affb7eae38e43b374f283833a 100644 (file)
@@ -135,16 +135,6 @@ static MFUN(vm_vector_cap) {
   *(m_uint*)RETURN = ARRAY_CAP(ARRAY(o));
 }
 
-INSTR(ArrayAppend) { GWDEBUG_EXE
-  POP_REG(shred, instr->m_val);
-  const M_Object o = *(M_Object*)REG(-SZ_INT);
-  if(!o)
-    Except(shred, "NullPtrException");
-  m_vector_add(ARRAY(o), REG(0));
-  release(o, shred);
-  *(M_Object*)REG(-SZ_INT) = o;
-}
-
 ANN static Type get_array_type(Type t) {
   while(t->d.base_type)
     t = t->d.base_type;
@@ -176,8 +166,10 @@ static OP_CHECK(opck_array_shift) {
 static OP_EMIT(opem_array_shift) {
   const Exp_Binary* bin = (Exp_Binary*)data;
   const Type type = bin->rhs->type;
-  Instr instr = emit_add_instr(emit, ArrayAppend);
-  instr->m_val = type->size;
+  const Instr pop = emit_add_instr(emit, RegPop);
+  pop->m_val = type->size;
+  emit_add_instr(emit, GWOP_EXCEPT);
+  emit_add_instr(emit, ArrayAppend);
   return GW_OK;
 }
 
@@ -221,7 +213,7 @@ GWION_IMPORT(array) {
   CHECK_BB(gwi_oper_end(gwi, op_ref, ObjectAssign))
   CHECK_BB(gwi_oper_add(gwi, opck_array_shift))
   CHECK_BB(gwi_oper_emi(gwi, opem_array_shift))
-  CHECK_BB(gwi_oper_end(gwi, op_shl, ArrayAppend))
+  CHECK_BB(gwi_oper_end(gwi, op_shl, NULL))
   CHECK_BB(gwi_oper_ini(gwi, "Array", "Array", NULL))
   CHECK_BB(gwi_oper_add(gwi, opck_array_cast))
   CHECK_BB(gwi_oper_emi(gwi, opem_basic_cast))
index 5be7524b15ed53da99b611c193360fb4ba5e94bb..f83441a8d9a5117a7b3a510187840181a511fedb 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "value.h"
 #include "gack.h"
+#include "array.h"
 
 
 static inline uint64_t splitmix64_stateless(uint64_t index) {
@@ -280,7 +281,7 @@ ANN void vm_run(const VM* vm) { // lgtm [cpp/use-of-goto]
     &&sporkini, &&sporkini, &&sporkfunc, &&sporkthis, &&sporkexp, &&forkend, &&sporkend,
     &&brancheqint, &&branchneint, &&brancheqfloat, &&branchnefloat,
     &&decintaddr, &&initloop,
-    &&arraytop, &&newobj,
+    &&arrayappend, &&arraytop, &&newobj,
     &&addref, &&assign, &&remref,
     &&except, &&allocmemberaddr, &&dotmember, &&dotfloat, &&dotother, &&dotaddr,
     &&staticint, &&staticfloat, &&staticother,
@@ -668,6 +669,10 @@ initloop:
   reg -= SZ_INT;
   (*(m_uint*)instr->m_val) = labs(*(m_int*)reg);
   DISPATCH()
+arrayappend:
+  m_vector_add(ARRAY(a.obj), reg);
+  release(a.obj, shred);
+  DISPATCH()
 arraytop:
   if(*(m_uint*)(reg - SZ_INT * 2) < *(m_uint*)(reg-SZ_INT))
     goto newobj;