From 6087ad447b58c1d0da2d47e5a1533be35394bd30 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 20 Jan 2021 00:17:12 +0100 Subject: [PATCH] :art: Few improvements --- ast | 2 +- include/object.h | 2 +- include/opcode.h | 2 -- opcode.txt | 1 - src/emit/emit.c | 6 +++--- src/lib/object.c | 2 +- src/lib/object_op.c | 8 +++++++- src/parse/check.c | 4 ++-- src/vm/vm.c | 12 ++---------- 9 files changed, 17 insertions(+), 22 deletions(-) diff --git a/ast b/ast index 2b7ad3f0..2814d301 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 2b7ad3f0e5b241640e7be0576332e3fec0296662 +Subproject commit 2814d30169430cb2b1bff740b1a806736b11238a diff --git a/include/object.h b/include/object.h index 2ed67898..af7043e2 100644 --- a/include/object.h +++ b/include/object.h @@ -4,7 +4,7 @@ typedef struct M_Object_ * M_Object; struct M_Object_ { m_bit* data; Type type_ref; - Vector vtable; + struct Vector_ vtable; volatile size_t ref; }; diff --git a/include/opcode.h b/include/opcode.h index d534088e..22ed841f 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -177,7 +177,6 @@ enum { eUpvalueOther, eUpvalueAddr, eDotFunc, - eDotStaticFunc, eGcIni, eGcAdd, eGcEnd, @@ -366,7 +365,6 @@ enum { #define UpvalueOther (f_instr)eUpvalueOther #define UpvalueAddr (f_instr)eUpvalueAddr #define DotFunc (f_instr)eDotFunc -#define DotStaticFunc (f_instr)eDotStaticFunc #define GcIni (f_instr)eGcIni #define GcAdd (f_instr)eGcAdd #define GcEnd (f_instr)eGcEnd diff --git a/opcode.txt b/opcode.txt index 850be415..11c30d5e 100644 --- a/opcode.txt +++ b/opcode.txt @@ -174,7 +174,6 @@ UpvalueFloat UpvalueOther UpvalueAddr DotFunc -DotStaticFunc GcIni GcAdd GcEnd diff --git a/src/emit/emit.c b/src/emit/emit.c index d4b3924e..4203d5a4 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1164,7 +1164,7 @@ ANN m_bool emit_exp_call1(const Emitter emit, const Func f) { push_func_code(emit, f); else if(vector_size(&emit->code->instr)) { const Instr back = (Instr)vector_back(&emit->code->instr); - if((f_instr)(m_uint)back->opcode == DotFunc || (f_instr)(m_uint)back->opcode == DotStaticFunc) + if((f_instr)(m_uint)back->opcode == DotFunc) back->m_val = f->vt_index; } if(vector_size(&emit->code->instr) && vflag(f->value_ref, vflag_member) && @@ -1790,10 +1790,10 @@ ANN static Symbol case_op(const Emitter emit, const Exp base, const Exp e, const return CASE_PASS; } } - } else if(isa(actual_type(emit->gwion, base->type), emit->gwion->type[et_union]) > 0 && e->exp_type == ae_exp_call) { + } else if(isa(base->type, emit->gwion->type[et_union]) > 0 && e->exp_type == ae_exp_call) { const Exp func = e->d.exp_call.func; if(func->d.prim.prim_type == ae_prim_id) { - const Map map = &actual_type(emit->gwion, base->type)->nspc->info->value->map; + const Map map = &base->type->nspc->info->value->map; for(m_uint i = 0; i < map_size(map); ++i) { if(VKEY(map, i) == (m_uint)func->d.prim.d.var) { const Value v = (Value)VVAL(map, i); diff --git a/src/lib/object.c b/src/lib/object.c index be66223d..d69f6695 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -30,7 +30,7 @@ M_Object new_object(MemPool p, const VM_Shred shred, const Type t) { a->ref = 1; a->type_ref = t; if(t->nspc) { - a->vtable = &t->nspc->info->vtable; + a->vtable.ptr = t->nspc->info->vtable.ptr; if(t->nspc->info->offset) a->data = (m_bit*)_mp_calloc(p, t->nspc->info->offset); } diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 5daf42e4..0f9ab262 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -116,8 +116,14 @@ else func_i->m_val = (m_uint)f->code ?: (m_uint)f; return; } - const Instr instr = emit_add_instr(emit, vflag(f->value_ref, vflag_member) ? DotFunc : DotStaticFunc); + const Instr instr = emit_add_instr(emit, DotFunc); instr->m_val = f->vt_index; + if(!vflag(f->value_ref, vflag_member)) + instr->m_val2 = -SZ_INT; + else { + const Instr instr = emit_add_instr(emit, RegMove); + instr->m_val = SZ_INT; + } } return; } diff --git a/src/parse/check.c b/src/parse/check.c index 7680c1bb..5d7d39b8 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1018,10 +1018,10 @@ ANN static Symbol case_op(const Env env, const Type base, const Exp e) { return NULL; } } - } else if(isa(actual_type(env->gwion, base), env->gwion->type[et_union]) > 0 && e->exp_type == ae_exp_call) { + } else if(isa(base, env->gwion->type[et_union]) > 0 && e->exp_type == ae_exp_call) { const Exp func = e->d.exp_call.func; if(func->d.prim.prim_type == ae_prim_id) { - const Value v= find_value(actual_type(env->gwion, base), func->d.prim.d.var); + const Value v= find_value(base, func->d.prim.d.var); if(v) { e->type = v->type; case_op(env, v->type, e->d.exp_call.args); diff --git a/src/vm/vm.c b/src/vm/vm.c index b8f7d341..c1d15490 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -329,7 +329,7 @@ ANN void vm_run(const VM* vm) { // lgtm [cpp/use-of-goto] &&unioncheck, &&unionint, &&unionfloat, &&unionother, &&unionaddr, &&staticint, &&staticfloat, &&staticother, &&upvalueint, &&upvaluefloat, &&upvalueother, &&upvalueaddr, - &&dotfunc, &&dotstaticfunc, + &&dotfunc, &&gcini, &&gcadd, &&gcend, &&gacktype, &&gackend, &&gack, &&noop, &&eoc, &&other, &®pushimm }; @@ -903,15 +903,7 @@ upvalueaddr: reg += SZ_INT; DISPATCH() dotfunc: -PRAGMA_PUSH() - *(VM_Code*)(reg) = ((Func)vector_at((*(M_Object*)(reg-SZ_INT))->vtable, VAL))->code; - reg += SZ_INT; -PRAGMA_POP() - DISPATCH() -dotstaticfunc: -PRAGMA_PUSH() - *(VM_Code*)(reg-SZ_INT) = ((Func)vector_at((*(M_Object*)(reg-SZ_INT))->vtable, VAL))->code; -PRAGMA_POP() + *(VM_Code*)(reg+(m_uint)VAL2) = ((Func)(*(M_Object*)(reg-SZ_INT))->vtable.ptr[OFFSET + VAL])->code; DISPATCH() gcini: vector_add(&shred->gc, 0); -- 2.43.0