]> Nishi Git Mirror - gwion.git/commitdiff
:art: ReleaseObject by chunks
authorJérémie Astor <fennecdjay@gmail.com>
Sun, 19 Sep 2021 14:02:54 +0000 (16:02 +0200)
committerJérémie Astor <fennecdjay@gmail.com>
Sun, 19 Sep 2021 14:02:54 +0000 (16:02 +0200)
include/opcode.h
opcode.txt
src/emit/emit.c
src/lib/engine.c
src/vm/vm.c

index cd7219d2d025dc1f6871d9e84d397e1bc687012b..deb28418c6279c9bb616f08dbaa2da01ab820114 100644 (file)
@@ -179,6 +179,7 @@ enum {
   eObjectAssign,
   eAssign,
   eObjectRelease,
+  eObjectRelease2,
   eGWOP_EXCEPT,
   eAllocMember4,
   eDotMember,
@@ -397,6 +398,7 @@ enum {
 #define  ObjectAssign         (f_instr)eObjectAssign
 #define  Assign               (f_instr)eAssign
 #define  ObjectRelease        (f_instr)eObjectRelease
+#define  ObjectRelease2       (f_instr)eObjectRelease2
 #define  GWOP_EXCEPT          (f_instr)eGWOP_EXCEPT
 #define  AllocMember4         (f_instr)eAllocMember4
 #define  DotMember            (f_instr)eDotMember
@@ -1254,6 +1256,11 @@ ANN static inline void dump_opcodes(const VM_Code code) {
         gw_out(" {-R}%-14"UINT_F"{0}", instr->m_val);
         gw_out("\n");
         break;
+      case eObjectRelease2:
+        gw_out("{Y}┃{0}{-}% 4lu{0}: ObjectRelease2", j);
+        gw_out(" {-R}%-14p{0}", instr->m_val);
+        gw_out("\n");
+        break;
       case eGWOP_EXCEPT:
         gw_out("{Y}┃{0}{-}% 4lu{0}: GWOP_EXCEPT ", j);
         gw_out(" {-R}%-14"UINT_F"{0}", instr->m_val);
index 2bd04b7514e6a757d18947d547ac7079d5e5f9ca..5117b2d1889ed8555c280ea283ad51330a5a2d9e 100644 (file)
@@ -176,6 +176,7 @@ StructRegAddRefAddr~i
 ObjectAssign
 Assign
 ObjectRelease~u
+ObjectRelease2~p
 GWOP_EXCEPT~u
 AllocMember4~u
 DotMember~u
index 79f48b2a4647374f559e0cd7d45127656b1e0d8e..4009332803a9262140153aee3a486577d4da631e 100644 (file)
@@ -248,9 +248,19 @@ ANN static void free_code(MemPool p, Code *code) {
 
 ANN static void emit_pop_scope(const Emitter emit) {
   m_int offset;
-  while ((offset = frame_pop(emit)) > -1) {
+  struct Vector_ v;
+  vector_init(&v);
+  while ((offset = frame_pop(emit)) > -1)
+    vector_add(&v, offset);
+  if(!vector_size(&v))
+    vector_release(&v);
+  else if(vector_size(&v) == 1) {
     Instr instr  = emit_add_instr(emit, ObjectRelease);
-    instr->m_val = (m_uint)offset;
+    instr->m_val = vector_front(&v);
+    vector_release(&v);
+  } else {
+    Instr instr  = emit_add_instr(emit, ObjectRelease2);
+    instr->m_val = (m_uint)v.ptr;
   }
   vector_pop(&emit->info->pure);
   if (emit->info->debug) emit_add_instr(emit, DebugPop);
index c3e58abde06eff4613322c72dfb08c74d0275d78..16054eb596c2d05f808f69b3cba302fb0b97ba43 100644 (file)
@@ -76,6 +76,11 @@ static INSTR(PredicateCheck) {
   if (!*(m_uint *)REG(-SZ_INT)) handle(shred, "PredicateFail");
 }
 
+static FREEARG(freearg_release) {
+  struct Vector_ v = { .ptr = instr->m_val };
+  vector_release(&v);
+}
+
 ANN static m_bool import_core_libs(const Gwi gwi) {
   gwidoc(gwi, "one type to rule them all.");
   const Type t_class = gwi_mk_type(gwi, "Class", SZ_INT, NULL);
@@ -227,6 +232,9 @@ ANN static m_bool import_core_libs(const Gwi gwi) {
 gwi_enum_ini(gwi, "@hidden_enum");
 gwi_enum_add(gwi, "@hidden_enum", 0);
 gwi_enum_end(gwi);
+
+gwi_register_freearg(gwi, ObjectRelease2, freearg_release);
+
   return GW_OK;
 }
 
index a416577f492f00f6679fe9a4c4a14e8ab4bf03c3..14dcfe95946878b681f0dbcfeb0a08aa2345e30a 100644 (file)
@@ -487,7 +487,7 @@ vm_run(const VM *vm) { // lgtm [cpp/use-of-goto]
       &&branchnefloat, &&unroll, &&arrayappend, &&autounrollinit, &&autoloop,
       &&arraytop, &&arrayaccess, &&arrayget, &&arrayaddr, &&newobj, &&addref,
       &&addrefaddr, &&structaddref, &&structaddrefaddr, &&objassign, &&assign,
-      &&remref, &&except, &&allocmemberaddr, &&dotmember, &&dotfloat,
+      &&remref, &&remref2, &&except, &&allocmemberaddr, &&dotmember, &&dotfloat,
       &&dotother, &&dotaddr, &&unioncheck, &&unionint, &&unionfloat,
       &&unionother, &&unionaddr, &&staticint, &&staticfloat, &&staticother,
       &&upvalueint, &&upvaluefloat, &&upvalueother, &&upvalueaddr, &&dotfunc,
@@ -1102,6 +1102,11 @@ vm_run(const VM *vm) { // lgtm [cpp/use-of-goto]
     remref:
       release(*(M_Object *)(mem + VAL), shred);
       DISPATCH()
+    remref2:
+      struct Vector_ v = { .ptr = (m_uint*)VAL };
+      for(m_uint i = 0; i < vector_size(&v); i++)
+        release(*(M_Object *)(mem + vector_at(&v, i)), shred);
+      DISPATCH()
     except:
       /* TODO: Refactor except instruction             *
        * so that                                       *