From: Jérémie Astor Date: Sat, 5 Dec 2020 16:04:57 +0000 (+0100) Subject: :bug: Fix Objec @=> Object reference X-Git-Tag: nightly~1127 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=40e93a500755abd4527d3ed1ea848389d945e7f4;p=gwion.git :bug: Fix Objec @=> Object reference --- diff --git a/include/env/env.h b/include/env/env.h index 7bac4e9b..2e9e5bf5 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -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; diff --git a/src/lib/array.c b/src/lib/array.c index 1064d31e..5580439b 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -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)) diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 14fb911f..dfdf4cb8 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -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;