]> Nishi Git Mirror - gwion.git/commitdiff
:bug: Fix Objec @=> Object reference
authorJérémie Astor <fennecdjay@gmail.com>
Sat, 5 Dec 2020 16:04:57 +0000 (17:04 +0100)
committerJérémie Astor <fennecdjay@gmail.com>
Sat, 5 Dec 2020 16:04:57 +0000 (17:04 +0100)
include/env/env.h
src/lib/array.c
src/lib/object_op.c

index 7bac4e9ba2866f58dcc1cb7d356aa3e9e69503af..2e9e5bf58adfc7b4290c0e3a6e3f00be9fb70a3f 100644 (file)
@@ -12,7 +12,6 @@ struct Env_Scope_ {
   struct Vector_    known_ctx;
   struct Match_ *match;
   size_t depth;
-  size_t type_xid;
 };
 
 typedef struct Env_       * Env;
index 1064d31e49e18cfb675772bdfd5c16a837e844e2..5580439b594c2d4820d8c2953773bfbcbc25c508 100644 (file)
@@ -391,7 +391,7 @@ static OP_EMIT(opem_array_access) {
   info->array = next;
   return (Instr)(m_uint)(exp ? emit_array_access(emit, info) : GW_ERROR);
 }
-
+OP_EMIT(opem_at_object);
 GWION_IMPORT(array) {
   const Type t_array  = gwi_class_ini(gwi, "@Array", NULL);
   gwi->gwion->type[et_array] = t_array;
@@ -416,6 +416,7 @@ GWION_IMPORT(array) {
   GWI_BB(gwi_class_end(gwi))
   GWI_BB(gwi_oper_ini(gwi, "@Array", "@Array", NULL))
   GWI_BB(gwi_oper_add(gwi, opck_array_at))
+  GWI_BB(gwi_oper_emi(gwi, opem_at_object))
   GWI_BB(gwi_oper_end(gwi, "@=>", ObjectAssign))
   GWI_BB(gwi_oper_ini(gwi, "@null", "@Array", NULL))
   GWI_BB(gwi_oper_add(gwi, opck_array_at))
index 14fb911f1dc9e9d5f0c5bb4f17abd718dd403387..dfdf4cb87e7c8fbd89b5a035ba0be09c692d6b08 100644 (file)
@@ -63,10 +63,25 @@ static OP_CHECK(at_object) {
   return r;
 }
 
-static OP_EMIT(opem_at_object) {
+/*static*/ OP_EMIT(opem_at_object) {
   const Exp_Binary* bin = (Exp_Binary*)data;
   const Type l = bin->lhs->info->type;
   const Type r = bin->rhs->info->type;
+
+  const uint is_new = bin->lhs->exp_type == ae_exp_unary && bin->lhs->d.exp_unary.op == insert_symbol(emit->gwion->st, "new");
+  if(bin->lhs->exp_type == ae_exp_unary && bin->lhs->d.exp_unary.op == insert_symbol(emit->gwion->st, "new")) {
+    for(m_uint i = vector_size(&emit->code->instr); --i;) {
+      const Instr instr = (Instr)vector_at(&emit->code->instr, i - 1);
+      if(instr->opcode == GcAdd) {
+        vector_rem(&emit->code->instr, i - 1);
+        mp_free(emit->gwion->mp, Instr, instr);
+      }
+    }
+  } else if(bin->lhs->exp_type != ae_exp_primary || bin->lhs->d.prim.prim_type != ae_prim_array) {
+    const Instr instr = emit_add_instr(emit, RegAddRef);
+    instr->m_val = -SZ_INT*2;
+  }
+
   if(nonnull_check(l, r)) {
     const Instr instr = emit_add_instr(emit, GWOP_EXCEPT);
     instr->m_val = SZ_INT;