From: fennecdjay Date: Thu, 3 Nov 2022 11:20:00 +0000 (+0100) Subject: :art: more cleaning X-Git-Tag: nightly~207^2~94 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=85ceea1cdde644e97662c20d33beebae57812161;p=gwion.git :art: more cleaning --- diff --git a/include/emit.h b/include/emit.h index 535da5ae..6a540235 100644 --- a/include/emit.h +++ b/include/emit.h @@ -95,15 +95,15 @@ ANN static inline Instr emit_compound_addref(const Emitter emit, const Type t, : emit_struct_addref(emit, t, size, emit_var); } -ANN Instr emit_kind(Emitter, const m_uint size, const bool addr, +ANN Instr emit_kind(Emitter, const m_uint val, const m_uint size, const bool addr, const f_instr func[]); -ANN Instr emit_regpushimm(Emitter, const m_uint, const bool); -ANN Instr emit_regpushmem(Emitter, const m_uint, const bool); -ANN Instr emit_regpushbase(Emitter, const m_uint, const bool); -ANN Instr emit_dotstatic(Emitter, const m_uint, const bool); -ANN Instr emit_dotmember(Emitter, const m_uint, const bool); -ANN Instr emit_structmember(Emitter, const m_uint, const bool); -ANN Instr emit_unionmember(Emitter, const m_uint, const bool); +ANN Instr emit_regpushimm(Emitter, const m_uint, const m_uint, const bool); +ANN Instr emit_regpushmem(Emitter, const m_uint, const m_uint , const bool); +ANN Instr emit_regpushbase(Emitter, const m_uint, const m_uint, const bool); +ANN Instr emit_dotstatic(Emitter, const m_uint, const m_uint, const bool); +ANN Instr emit_dotmember(Emitter, const m_uint, const m_uint, const bool); +ANN Instr emit_structmember(Emitter, const m_uint, const m_uint, const bool); +ANN Instr emit_unionmember(Emitter, const m_uint, const m_uint, const bool); void emit_fast_except(const Emitter emit, const ValueFrom *vf, const loc_t loc); ANN static inline m_uint emit_code_size(const Emitter emit) { diff --git a/src/emit/emit.c b/src/emit/emit.c index dd10aae4..baf3c8e3 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -455,21 +455,19 @@ m_bool emit_instantiate_decl(const Emitter emit, const Type type, ANN static m_bool emit_symbol_builtin(const Emitter emit, const Symbol *data) { const Value v = prim_self(data)->value; + const bool emit_addr = exp_getvar(prim_exp(data)); if (vflag(v, vflag_direct)) { const m_uint size = v->type->size; - const Instr instr = emit_dotstatic(emit, size, exp_getvar(prim_exp(data))); - instr->m_val = (m_uint)&v->d.ptr; + emit_dotstatic(emit, (m_uint)&v->d.ptr, size, emit_addr); // prevent invalid access to global variables - if(!exp_getvar(exp_self(prim_self(data))) && + if(!emit_addr && isa(v->type, emit->gwion->type[et_object]) > 0) emit_fast_except(emit, v->from, prim_pos(data)); } else { const m_uint size = v->type->size; - const Instr instr = emit_regpushimm(emit, size, exp_getvar(prim_exp(data))); + const Instr instr = emit_regpushimm(emit, v->d.num, size, emit_addr); if (v->type->size == SZ_FLOAT) instr->f = v->d.fnum; - else - instr->m_val = v->d.num; } return GW_OK; } @@ -507,11 +505,10 @@ ANN static m_bool _emit_symbol(const Emitter emit, const Symbol *data) { return GW_OK; } const m_uint size = v->type->size; - const Instr instr = - !vflag(v, vflag_fglobal) - ? emit_regpushmem(emit, size, exp_getvar(prim_exp(data))) - : emit_regpushbase(emit, size, exp_getvar(prim_exp(data))); - instr->m_val = v->from->offset; + if(!vflag(v, vflag_fglobal)) + emit_regpushmem(emit, v->from->offset, size, exp_getvar(prim_exp(data))); + else + emit_regpushbase(emit, v->from->offset, size, exp_getvar(prim_exp(data))); if (GET_FLAG(v, late) && !exp_getvar(prim_exp(data)) && isa(v->type, emit->gwion->type[et_object]) > 0) emit_fast_except(emit, v->from, prim_pos(data)); @@ -893,9 +890,7 @@ ANN static m_bool emit_prim(const Emitter emit, Exp_Primary *const prim) { ANN static m_bool emit_dot_static_data(const Emitter emit, const Value v, const bool emit_var) { const m_uint size = v->type->size; - const Instr instr = emit_dotstatic(emit, size, emit_var); - instr->m_val = (m_uint)(v->from->owner->class_data + v->from->offset); - instr->m_val2 = size; + emit_dotstatic(emit, (m_uint)(v->from->owner->class_data + v->from->offset), size, emit_var); return GW_OK; } @@ -975,10 +970,10 @@ ANN static m_bool emit_exp_decl_static(const Emitter emit, const Exp_Decl *decl, ANN static Instr emit_struct_decl(const Emitter emit, const Value v, const bool emit_addr) { emit_add_instr(emit, RegPushMem); - const Instr instr = emit_structmember(emit, v->type->size, emit_addr); + const Instr instr = emit_structmember(emit, v->from->offset, v->type->size, emit_addr); if (!emit_addr) { const m_int sz = v->type->size - SZ_INT; - if (sz) emit_regmove(emit, v->type->size - SZ_INT); + if (sz) emit_regmove(emit, sz); } return instr; } @@ -1022,13 +1017,10 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, clean->m_val = v->from->offset; } } - const Instr instr = - !(safe_tflag(emit->env->class_def, tflag_struct) && - !emit->env->scope->depth) - ? emit_kind(emit, v->type->size, !struct_ctor(v) ? emit_addr : true, - exec) - : emit_struct_decl(emit, v, !struct_ctor(v) ? emit_addr : 1); - instr->m_val = v->from->offset; + if(!(safe_tflag(emit->env->class_def, tflag_struct) && !emit->env->scope->depth)) + emit_kind(emit, v->from->offset, v->type->size, !struct_ctor(v) ? emit_addr : true, + exec); + else emit_struct_decl(emit, v, !struct_ctor(v) ? emit_addr : 1); if (is_obj && !is_ref && !exp_self(decl)->ref) { if (!emit_var) emit_add_instr(emit, Assign); @@ -1055,13 +1047,10 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Exp_Decl *decl, if(!decl->args) CHECK_BB(emit_instantiate_decl(emit, type, decl->td, is_ref)); else CHECK_BB(emit_exp(emit, decl->args)); } - const Instr instr = - emit_dotstatic(emit, v->type->size, !struct_ctor(v) ? emit_addr : 1); - if (type->size > SZ_INT) //{ + if (type->size > SZ_INT) v->d.ptr = mp_calloc2(emit->gwion->mp, v->type->size); - instr->m_val = (m_uint)&v->d.ptr; + emit_dotstatic(emit, (m_uint)&v->d.ptr, v->type->size, !struct_ctor(v) ? emit_addr : 1); set_vflag(v, vflag_direct); // mpalloc - instr->m_val2 = v->type->size; if (is_obj && !is_ref) { const Instr assign = emit_add_instr(emit, Assign); assign->m_val = emit_var; @@ -1527,12 +1516,6 @@ typedef struct { m_uint arg_offset; } MemoizeEmitter; -ANN static Instr me_push(const MemoizeEmitter *me, const m_uint sz) { - const Instr instr = emit_regpushmem(me->emit, sz, false); - instr->m_val = me->arg_offset; - return instr; -} - static m_bool me_cmp(MemoizeEmitter *me, const Arg *arg) { const Emitter emit = me->emit; const Symbol sym = insert_symbol("?="); @@ -1580,11 +1563,10 @@ ANN static m_bool me_arg(MemoizeEmitter *me) { for(uint32_t i = 0; i < args->len; i++) { Arg *arg = mp_vector_at(args, Arg, i); const m_uint sz = arg->type->size; - (void)me_push(me, sz); - const Instr instr = me_push(me, sz); - instr->m_val += me->offset + SZ_INT * 2; + emit_regpushmem(me->emit, me->arg_offset, sz, false); + emit_regpushmem(me->emit, me->offset + SZ_INT * 2, sz, false); CHECK_BB(me_cmp(me, arg)); - me->arg_offset += arg->type->size; // sz? + me->arg_offset += sz; } return GW_OK; } @@ -2508,9 +2490,7 @@ ANN static Symbol case_op(const Emitter emit, const Exp base, const Exp e, const Instr check = emit_add_instr(emit, UnionCheck); check->m_val2 = i; vector_add(vec, (m_uint)check); - const Instr instr = - emit_unionmember(emit, v->type->size, false /*emit_addr*/); - instr->m_val = i; + emit_unionmember(emit, i, v->type->size, false); emit_regmove(emit, -v->type->size); case_op(emit, e->d.exp_call.args, e->d.exp_call.args, vec, i + 1); return CASE_PASS; @@ -2766,11 +2746,8 @@ ANN static void me_bottom(MemoizeEmitter *me, const m_uint pc) { } ANN static void me_ret(MemoizeEmitter *me) { - const Instr instr = - emit_regpushmem(me->emit, me->fdef->base->ret_type->size, false); - instr->m_val = (me->offset + SZ_INT) * 2; -// emit_add_instr(me->emit, FuncReturn); -vector_add(&me->emit->code->stack_return, (vtype)emit_add_instr(me->emit, Goto)); + emit_regpushmem(me->emit, (me->offset + SZ_INT) * 2, me->fdef->base->ret_type->size, false); + vector_add(&me->emit->code->stack_return, (vtype)emit_add_instr(me->emit, Goto)); } ANN static m_bool me_run(MemoizeEmitter *me, const m_uint pc) { diff --git a/src/emit/kind.c b/src/emit/kind.c index 404feb52..8fd78651 100644 --- a/src/emit/kind.c +++ b/src/emit/kind.c @@ -13,10 +13,11 @@ static inline enum Kind kindof(const m_uint size, const uint emit_var) { return size == SZ_INT ? KIND_INT : size == SZ_FLOAT ? KIND_FLOAT : KIND_OTHER; } -ANN Instr emit_kind(Emitter emit, const m_uint size, const bool addr, +ANN Instr emit_kind(Emitter emit, const m_uint val, const m_uint size, const bool addr, const f_instr func[]) { const enum Kind kind = kindof(size, addr); const Instr instr = emit_add_instr(emit, func[kind]); + instr->m_val = val; if(kind == KIND_OTHER) instr->m_val2 = size; return instr; } @@ -43,9 +44,9 @@ static const f_instr unionmember[KIND_END] = {UnionMember, UnionMember2, UnionMember3, UnionMember4}; // function factory -#define kind_func(name) \ - ANN Instr emit_##name(Emitter emit, const m_uint size, const bool addr) { \ - return emit_kind(emit, size, addr, name); \ +#define kind_func(name) \ + ANN Instr emit_##name(Emitter emit, const m_uint val, const m_uint size, const bool addr) { \ + return emit_kind(emit, val, size, addr, name); \ } kind_func(regpushimm); diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 7f386984..8ddf68bf 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -101,20 +101,16 @@ static OP_CHECK(opck_struct_scan) { ANN static void emit_dot_static_data(const Emitter emit, const Value v, const bool emit_addr) { const m_uint size = v->type->size; - const Instr instr = emit_dotstatic(emit, size, emit_addr); - instr->m_val = (m_uint)(v->from->owner->class_data + v->from->offset); - instr->m_val2 = size; + const m_uint data = (m_uint)(v->from->owner->class_data + v->from->offset); + emit_dotstatic(emit, data, size, emit_addr); } ANN static void emit_dot_static_import_data(const Emitter emit, const Value v, const bool emit_addr) { if (vflag(v, vflag_builtin) /*&& GET_FLAG(v, const)*/) { const m_uint size = v->type->size; - const Instr instr = emit_regpushimm(emit, size, emit_addr); - instr->m_val = (m_uint)v->d.ptr; - instr->m_val2 = size; - } else - emit_dot_static_data(emit, v, emit_addr); + emit_regpushimm(emit, (m_uint)v->d.ptr, size, emit_addr); + } else emit_dot_static_data(emit, v, emit_addr); } ANN static void emit_dottmpl(const Emitter emit, const Func f) { @@ -163,14 +159,12 @@ ANN static void emit_member_func(const Emitter emit, const Exp_Dot *member) { ANN static inline void emit_member(const Emitter emit, const Value v, const uint emit_addr) { const m_uint size = v->type->size; - const Instr instr = emit_dotmember(emit, size, emit_addr); - instr->m_val = v->from->offset; + emit_dotmember(emit, v->from->offset, size, emit_addr); } ANN static inline void emit_struct_data(const Emitter emit, const Value v, const bool emit_addr) { - const Instr instr = emit_structmember(emit, v->type->size, emit_addr); - instr->m_val = v->from->offset; + emit_structmember(emit, v->from->offset, v->type->size, emit_addr); if (!emit_addr) emit_regmove(emit, v->type->size - SZ_INT); } diff --git a/src/lib/union.c b/src/lib/union.c index 31a1f30f..420e46ff 100644 --- a/src/lib/union.c +++ b/src/lib/union.c @@ -43,9 +43,7 @@ static OP_EMIT(opem_union_dot) { if (VKEY(map, i) == (m_uint)member->xid) { const Value v = (Value)VVAL(map, i); const uint emit_addr = exp_getvar(exp_self(member)); - const Instr instr = emit_unionmember(emit, v->type->size, emit_addr); - instr->m_val = i; // + 1; - instr->m_val2 = v->type->size; + emit_unionmember(emit, i, v->type->size, emit_addr); return GW_OK; } }