From d6c618e9f320cbc855f539adafbe599940f652a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Tue, 25 Feb 2020 01:09:11 +0100 Subject: [PATCH] :art: Improve gack --- include/opcode.h | 2 ++ opcode.txt | 1 + src/emit/emit.c | 9 +++++++-- src/lib/gack.c | 7 +------ src/vm/vm.c | 9 ++++++++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/opcode.h b/include/opcode.h index 0634386d..7d0df98b 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -169,6 +169,7 @@ enum { eGcIni, eGcAdd, eGcEnd, + eGackType, eGackEnd, eGack, eNoOp, @@ -345,6 +346,7 @@ enum { #define GcIni (f_instr)eGcIni #define GcAdd (f_instr)eGcAdd #define GcEnd (f_instr)eGcEnd +#define GackType (f_instr)eGackType #define GackEnd (f_instr)eGackEnd #define Gack (f_instr)eGack #define NoOp (f_instr)eNoOp diff --git a/opcode.txt b/opcode.txt index 12be3f3f..db75fbd5 100644 --- a/opcode.txt +++ b/opcode.txt @@ -166,6 +166,7 @@ PushStaticCode GcIni GcAdd GcEnd +GackType GackEnd Gack NoOp diff --git a/src/emit/emit.c b/src/emit/emit.c index 070515d0..7917fff2 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -618,9 +618,14 @@ ANN static m_bool emit_interp(const Emitter emit, const Exp exp) { e->next = next; return GW_ERROR; } + regseti(emit, (m_uint)e->type); + if(isa(e->type, emit->gwion->type[et_object]) > 0 && !GET_FLAG(e->type, force)) { + emit_add_instr(emit, GackType); + } const Instr instr = emit_add_instr(emit, Gack); - instr->m_val = (m_uint)e->type; - instr->m_val2 = emit_code_offset(emit); + if(isa(e->type, emit->gwion->type[et_object]) > 0 && !GET_FLAG(e->type, force)) + emit_add_instr(emit, GackType); + instr->m_val = emit_code_offset(emit); } while((e = e->next = next)); return GW_OK; } diff --git a/src/lib/gack.c b/src/lib/gack.c index 05bdecb8..7148ff96 100644 --- a/src/lib/gack.c +++ b/src/lib/gack.c @@ -62,12 +62,7 @@ ANN static void prepare_call(const VM_Shred shred, m_uint offset) { } ANN void gack(const VM_Shred shred, const Instr instr) { - Type t = (Type)instr->m_val; - if(isa(t, shred->info->vm->gwion->type[et_object]) > 0 && !GET_FLAG(t, force)) { - const M_Object o = *(M_Object*)(shred->reg - SZ_INT); - if(o) - t = o->type_ref; - } + const Type t = *(Type*)shred->reg; const VM_Code code = get_gack(t); if(GET_FLAG(code, builtin)) { ((f_gack)code->native_func)(t, (shred->reg - t->size), shred); diff --git a/src/vm/vm.c b/src/vm/vm.c index 8e64a63f..404fa3ce 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -340,7 +340,7 @@ ANN void vm_run(const VM* vm) { // lgtm [cpp/use-of-goto] &&staticint, &&staticfloat, &&staticother, &&dotfunc, &&dotstaticfunc, &&pushstaticcode, &&gcini, &&gcadd, &&gcend, - &&gackend, &&gack, &&noop, &®pushimm, &&other, &&eoc + &&gacktype, &&gackend, &&gack, &&noop, &®pushimm, &&other, &&eoc }; const Shreduler s = vm->shreduler; register VM_Shred shred; @@ -849,6 +849,13 @@ gcend: while((a.obj = (M_Object)vector_pop(&shred->gc))) _release(a.obj, shred); DISPATCH() +gacktype: +{ + const M_Object o = *(M_Object*)(reg - SZ_INT); + if(o) + *(Type*)reg = o->type_ref; + DISPATCH() +} gackend: { m_str str = *(m_str*)(reg - SZ_INT); -- 2.43.0