From: fennecdjay Date: Tue, 26 Mar 2019 19:06:10 +0000 (+0100) Subject: :art: Instr => Opcode : ArrayAppend X-Git-Tag: nightly~2591 X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=cab7025005890e6a26eab4a41f4da0b20bffd9eb;p=gwion.git :art: Instr => Opcode : ArrayAppend --- diff --git a/include/instr.h b/include/instr.h index ec5baff3..627c3199 100644 --- a/include/instr.h +++ b/include/instr.h @@ -51,7 +51,6 @@ INSTR(ArrayInit); INSTR(ArrayAlloc); INSTR(ArrayAccess); INSTR(ArrayAccessMulti); -INSTR(ArrayAppend); /* vararg */ INSTR(VarargIni); diff --git a/include/opcode.h b/include/opcode.h index 27c1ff82..55eb297b 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -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 diff --git a/opcode.txt b/opcode.txt index 00a918a2..e05385dd 100644 --- a/opcode.txt +++ b/opcode.txt @@ -138,6 +138,7 @@ BranchEqFloat BranchNeqFloat DecIntAddr InitLoopCounter +ArrayAppend ArrayTop ObjectInstantiate RegAddRef diff --git a/src/lib/array.c b/src/lib/array.c index 18286313..57942735 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -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)) diff --git a/src/vm/vm.c b/src/vm/vm.c index 5be7524b..f83441a8 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -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;