From: fennecdjay Date: Mon, 24 Oct 2022 11:44:03 +0000 (+0200) Subject: :art: more convenience funcs X-Git-Tag: nightly~207^2~131 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=5d4404ed55db9f40e077e8060bba1c7587568f60;p=gwion.git :art: more convenience funcs --- diff --git a/include/emit.h b/include/emit.h index 12c95058..279c3002 100644 --- a/include/emit.h +++ b/include/emit.h @@ -122,4 +122,13 @@ ANN static inline void emit_regmove(const Emitter emit, const m_uint i) { instr->m_val = i; } +ANN static inline void emit_pushfunc(const Emitter emit, const Func f) { + if(f->code) { + const Instr instr = emit_add_instr(emit, RegPushImm); + instr->m_val = (m_uint)f->code; + } else { + const Instr instr = emit_add_instr(emit, SetFunc); + instr->m_val = (m_uint)f; + } +} #endif diff --git a/src/lib/object_op.c b/src/lib/object_op.c index cb88ad91..90f998b4 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -131,10 +131,7 @@ ANN static void emit_member_func(const Emitter emit, const Exp_Dot *member) { const Func f = exp_self(member)->type->info->func; if(!strcmp(s_name(f->def->base->xid), "new")) { - if(f != emit->env->func) { - const Instr instr = emit_add_instr(emit, f->code ? RegPushImm : SetFunc); - instr->m_val = (m_uint)f->code ?: (m_uint)f; - } + if(f != emit->env->func) emit_pushfunc(emit, f); return; } if (f->def->base->tmpl) { @@ -148,15 +145,10 @@ ANN static void emit_member_func(const Emitter emit, const Exp_Dot *member) { } } else if (is_static_call(emit->gwion, exp_self(member))) { if (member->is_call && f == emit->env->func && strcmp(s_name(f->def->base->xid), "new")) return; - const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : SetFunc); - func_i->m_val = (m_uint)f->code ?: (m_uint)f; - return; + return emit_pushfunc(emit, f); } else { - if (tflag(member->base->type, tflag_struct)) { - const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : SetFunc); - func_i->m_val = (m_uint)f->code ?: (m_uint)f; - return; - } + if (tflag(member->base->type, tflag_struct)) + return emit_pushfunc(emit, f); const Instr instr = emit_add_instr(emit, DotFunc); instr->m_val = f->def->vt_index; if (!vflag(f->value_ref, vflag_member)) diff --git a/src/parse/operator.c b/src/parse/operator.c index e33ae9cd..5cc642f1 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -375,9 +375,7 @@ ANN m_bool operator_set_func(const struct Op_Import *opi) { ANN static m_bool handle_instr(const Emitter emit, const M_Operator *mo) { if (mo->func) { - const Instr push = - emit_add_instr(emit, mo->func->code ? RegPushImm : SetFunc); - push->m_val = ((m_uint)mo->func->code ?: (m_uint)mo->func); + emit_pushfunc(emit, mo->func); CHECK_BB(emit_exp_call1(emit, mo->func, true)); if (mo->func->def->base->xid == insert_symbol(emit->gwion->st, "@conditional"))