From: fennecdjay Date: Fri, 7 Jun 2019 21:31:34 +0000 (+0200) Subject: :art: Improve vm. X-Git-Tag: nightly~2443^2~18 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=d49b8917abc74500e967c4789cf51fbf90f62ea6;p=gwion.git :art: Improve vm. --- diff --git a/include/opcode.h b/include/opcode.h index f1d678fc..7405cd8a 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -151,6 +151,7 @@ enum { eObjectInstantiate, eRegAddRef, eObjectAssign, + eAssign, eObjectRelease, eGWOP_EXCEPT, eAllocMember4, @@ -324,6 +325,7 @@ enum { #define ObjectInstantiate (f_instr)eObjectInstantiate #define RegAddRef (f_instr)eRegAddRef #define ObjectAssign (f_instr)eObjectAssign +#define Assign (f_instr)eAssign #define ObjectRelease (f_instr)eObjectRelease #define GWOP_EXCEPT (f_instr)eGWOP_EXCEPT #define AllocMember4 (f_instr)eAllocMember4 diff --git a/opcode.txt b/opcode.txt index 88498ce7..0318bd4b 100644 --- a/opcode.txt +++ b/opcode.txt @@ -148,6 +148,7 @@ ArrayValid ObjectInstantiate RegAddRef ObjectAssign +Assign ObjectRelease GWOP_EXCEPT AllocMember4 diff --git a/src/emit/emit.c b/src/emit/emit.c index ae120fac..a451542e 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -538,7 +538,7 @@ ANN static m_bool decl_static(const Emitter emit, const Var_Decl var_decl, const emit->code = (Code*)vector_back(&emit->stack); CHECK_BB(emit_instantiate_object(emit, v->type, var_decl->array, is_ref)) CHECK_BB(emit_dot_static_data(emit, v, 1)) - emit_add_instr(emit, ObjectAssign); + emit_add_instr(emit, Assign); emit->code = code; return GW_OK; } @@ -570,7 +570,7 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, const Var_Decl va instr->m_val = v->offset; instr->m_val2 = v->type->size; if(is_obj && (is_array || !is_ref)) { - const Instr assign = emit_add_instr(emit, ObjectAssign); + const Instr assign = emit_add_instr(emit, Assign); assign->m_val = emit_var; const size_t missing_depth = type->array_depth - (array ? array->depth : 0); if((is_array || missing_depth) && !emit->env->scope->depth) @@ -601,7 +601,7 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Var_Decl var_de instr->m_val = (m_uint)v->d.ptr; instr->m_val2 = v->type->size; if(is_obj && (is_array || !is_ref)) { - const Instr assign = emit_add_instr(emit, ObjectAssign); + const Instr assign = emit_add_instr(emit, Assign); assign->m_val = emit_var; if(is_array && !emit->env->scope->depth) ADD_REF(type) diff --git a/src/vm/vm.c b/src/vm/vm.c index 876fcf09..7a801182 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -276,7 +276,7 @@ ANN void vm_run(const VM* vm) { // lgtm [cpp/use-of-goto] &&sporkini, &&sporkini, &&sporkfunc, &&sporkexp, &&forkend, &&sporkend, &&brancheqint, &&branchneint, &&brancheqfloat, &&branchnefloat, &&arrayappend, &&autoloop, &&autoloopptr, &&autoloopcount, &&arraytop, &&arrayaccess, &&arrayget, &&arrayaddr, &&arrayvalid, - &&newobj, &&addref, &&assign, &&remref, + &&newobj, &&addref, &&objassign, &&assign, &&remref, &&except, &&allocmemberaddr, &&dotmember, &&dotfloat, &&dotother, &&dotaddr, &&staticint, &&staticfloat, &&staticother, &&dotfunc, &&dotstaticfunc, &&staticcode, &&pushstr, @@ -402,7 +402,6 @@ allocother: reg += instr->m_val2; DISPATCH() allocaddr: - *(m_uint*)(mem+instr->m_val) = 0; // just set object to null in *(m_bit**)reg = mem + instr->m_val; reg += SZ_INT; DISPATCH() @@ -696,16 +695,19 @@ addref: *(M_Object*)(reg-SZ_INT))) ++a.obj->ref; DISPATCH() -assign: - reg -= SZ_INT; - a.obj = *(M_Object*)(reg-SZ_INT); - const M_Object tgt = **(M_Object**)reg; +objassign: +{ + const M_Object tgt = **(M_Object**)(reg -SZ_INT); if(tgt) { --tgt->ref; _release(tgt, shred); - } +} +assign: + reg -= SZ_INT; + a.obj = *(M_Object*)(reg-SZ_INT); **(M_Object**)reg = a.obj; DISPATCH() +} remref: release(*(M_Object*)(mem + instr->m_val), shred); DISPATCH()