From: fennecdjay Date: Sun, 10 Mar 2019 23:03:23 +0000 (+0100) Subject: :art: ArrayTop X-Git-Tag: nightly~2753^2~6 X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=460da568de2684e2dc2bc5f80764d3574d920e65;p=gwion.git :art: ArrayTop --- diff --git a/include/instr.h b/include/instr.h index f794bacd..ec5baff3 100644 --- a/include/instr.h +++ b/include/instr.h @@ -45,7 +45,6 @@ INSTR(ComplexImag); INSTR(DtorReturn); /* array */ -INSTR(ArrayTop); INSTR(ArrayBottom); INSTR(ArrayPost); INSTR(ArrayInit); diff --git a/include/lang_private.h b/include/lang_private.h index 116b2a61..f7bb22fe 100644 --- a/include/lang_private.h +++ b/include/lang_private.h @@ -1,7 +1,6 @@ #ifndef __LANG_PRIVATE #define __LANG_PRIVATE -ANN m_bool import_int(const Gwi gwi); -ANN m_bool import_float(const Gwi gwi); +ANN m_bool import_prim(const Gwi gwi); ANN m_bool import_complex(const Gwi gwi); ANN m_bool import_vec3(const Gwi gwi); ANN m_bool import_vec4(const Gwi gwi); diff --git a/include/opcode.h b/include/opcode.h index 04f8bb27..d43d3c18 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -139,6 +139,7 @@ enum { eBranchNeqFloat, eDecIntAddr, eInitLoopCounter, + eArrayTop, eObjectInstantiate, eRegAddRef, eObjectAssign, @@ -301,6 +302,7 @@ enum { #define BranchNeqFloat (f_instr)eBranchNeqFloat #define DecIntAddr (f_instr)eDecIntAddr #define InitLoopCounter (f_instr)eInitLoopCounter +#define ArrayTop (f_instr)eArrayTop #define ObjectInstantiate (f_instr)eObjectInstantiate #define RegAddRef (f_instr)eRegAddRef #define ObjectAssign (f_instr)eObjectAssign diff --git a/opcode.txt b/opcode.txt index d31f84be..92d958b3 100644 --- a/opcode.txt +++ b/opcode.txt @@ -136,6 +136,7 @@ BranchEqFloat BranchNeqFloat DecIntAddr InitLoopCounter +ArrayTop ObjectInstantiate RegAddRef ObjectAssign diff --git a/src/emit/emit.c b/src/emit/emit.c index be2fac75..420e2b90 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -214,7 +214,7 @@ ANN2(1,2) m_bool emit_instantiate_object(const Emitter emit, const Type type, info->is_ref = !!is_ref; } else if(!is_ref) { const Instr instr = emit_add_instr(emit, ObjectInstantiate); - instr->m_val = (m_uint)type; + instr->m_val2 = (m_uint)type; emit_pre_ctor(emit, type); } return GW_OK; @@ -720,13 +720,13 @@ ANN static Type_List tmpl_tl(const Env env, const m_str name) { } ANN m_bool traverse_dot_tmpl(const Emitter emit, const struct dottmpl_ *dt) { - const m_uint scope = env_push_type(emit->env, dt->owner); + const m_uint scope = emit_push_type(emit, dt->owner); m_bool ret = GW_ERROR; if(traverse_func_template(emit->env, dt->def, dt->tl) > 0) { ret = emit_func_def(emit, dt->def); nspc_pop_type(emit->env->curr); } - env_pop(emit->env, scope); + emit_pop(emit, scope); return ret; } diff --git a/src/lib/array.c b/src/lib/array.c index 7793b9cd..51e8bc70 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -229,13 +229,6 @@ GWION_IMPORT(array) { return GW_OK; } -INSTR(ArrayTop) { GWDEBUG_EXE - if(*(m_uint*)REG(-SZ_INT * 2) < *(m_uint*)REG(-SZ_INT)) - instantiate_object(shred, (Type)instr->m_val2); - else - shred->pc = instr->m_val; -} - INSTR(ArrayBottom) { GWDEBUG_EXE POP_REG(shred, SZ_INT); const M_Object obj = *(M_Object*)REG(0); diff --git a/src/lib/object.c b/src/lib/object.c index e84be8f0..5c4c7e68 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -49,7 +49,8 @@ M_Object new_string2(const VM_Shred shred, const m_str str) { } ANN void instantiate_object(const VM_Shred shred, const Type type) { - const M_Object object = new_object(NULL, type); +// const M_Object object = new_object(NULL, type); + const M_Object object = new_object(shred, type); *(M_Object*)REG(0) = object; PUSH_REG(shred, SZ_INT); } diff --git a/src/vm/vm.c b/src/vm/vm.c index e456afde..17d0dc47 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -264,7 +264,7 @@ ANN void vm_run(const VM* vm) { /* lgtm [cpp/use-of-goto] */ &&sporkini, &&sporkfunc, &&sporkthis, &&sporkexp, &&sporkend, &&brancheqint, &&branchneint, &&brancheqfloat, &&branchnefloat, &&decintaddr, &&initloop, - &&newobj, + &&arraytop, &&newobj, &&addref, &&assign, &&remref, &&except, &&allocmemberaddr, &&dotmember, &&dotfloat, &&dotother, &&dotaddr, &&staticint, &&staticfloat, &&staticother, @@ -646,8 +646,13 @@ initloop: reg -= SZ_INT; (*(m_uint*)instr->m_val) = labs(*(m_int*)reg); DISPATCH() +arraytop: + if(*(m_uint*)(reg - SZ_INT * 2) < *(m_uint*)(reg-SZ_INT)) + goto newobj; + else + goto _goto; newobj: - *(M_Object*)reg = new_object(shred, (Type)instr->m_val); + *(M_Object*)reg = new_object(shred, (Type)instr->m_val2); reg += SZ_INT; DISPATCH() addref: