From 874a8f8caa73d6fb783a8244b855a59c275f9ad9 Mon Sep 17 00:00:00 2001
From: fennecdjay <fennecdjay@gmail.com>
Date: Mon, 24 Oct 2022 16:55:56 +0200
Subject: [PATCH] :art: emit_pushimm

---
 include/emit.h      |  5 +++++
 src/emit/emit.c     |  2 +-
 src/lib/closure.c   |  3 +--
 src/lib/dict.c      |  3 +--
 src/lib/lib_class.c |  3 +--
 src/lib/object_op.c | 11 +++--------
 src/lib/union.c     |  3 +--
 7 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/include/emit.h b/include/emit.h
index 279c3002..e77a41c4 100644
--- a/include/emit.h
+++ b/include/emit.h
@@ -131,4 +131,9 @@ ANN static inline void emit_pushfunc(const Emitter emit, const Func f) {
     instr->m_val = (m_uint)f;
   }
 }
+
+ANN static inline void emit_pushimm(const Emitter emit, const m_uint value) {
+  const Instr instr = emit_add_instr(emit, RegPushImm);
+  instr->m_val = value;
+}
 #endif
diff --git a/src/emit/emit.c b/src/emit/emit.c
index 28df8a44..ffd9ab49 100644
--- a/src/emit/emit.c
+++ b/src/emit/emit.c
@@ -1718,7 +1718,7 @@ struct Sporker {
 
 ANN static m_bool spork_prepare_code(const Emitter         emit,
                                      const struct Sporker *sp) {
-  emit_add_instr(emit, RegPushImm);
+  emit_pushimm(emit, 0);
   push_spork_code(emit, sp->is_spork ? SPORK_CODE_PREFIX : FORK_CODE_PREFIX,
                   sp->pos);
   if (emit->env->class_def) stack_alloc(emit);
diff --git a/src/lib/closure.c b/src/lib/closure.c
index 3e958474..842f3139 100644
--- a/src/lib/closure.c
+++ b/src/lib/closure.c
@@ -518,8 +518,7 @@ static OP_EMIT(opem_op_impl) {
   struct Implicit *impl = (struct Implicit *)data;
   if(!impl->e->type->info->func->code)
     emit_ensure_func(emit, impl->e->type->info->func);
-  const Instr instr = emit_add_instr(emit, RegPushImm);
-  instr->m_val = (m_uint)impl->e->type->info->func->code;
+  emit_pushimm(emit, (m_uint)impl->e->type->info->func->code);
   return emit_fptr_assign(emit, impl->e->type, impl->t);
 }
 
diff --git a/src/lib/dict.c b/src/lib/dict.c
index a1ee9ece..c055dfe0 100644
--- a/src/lib/dict.c
+++ b/src/lib/dict.c
@@ -362,8 +362,7 @@ static OP_CHECK(opck_dict_remove_toop) {
 
 ANN static m_bool emit_dict_iter(const Emitter emit, const HMapInfo *hinfo,
                           const struct Op_Import *opi, const Exp call, const Exp exp) {
-  const Instr room_for_tombstone = emit_add_instr(emit, RegPushImm);
-  room_for_tombstone->m_val = -1;
+  emit_pushimm(emit, -1); // room for tombstone
   CHECK_BB(emit_exp(emit, call));
   const m_uint pc = emit_code_size(emit);
   const Instr iter = emit_add_instr(emit, hmap_iter);
diff --git a/src/lib/lib_class.c b/src/lib/lib_class.c
index 783c93f4..b4af11eb 100644
--- a/src/lib/lib_class.c
+++ b/src/lib/lib_class.c
@@ -41,8 +41,7 @@ static OP_CHECK(opck_basic_ctor) {
 static OP_EMIT(opem_implicit_class) {
   struct Implicit *imp = (struct Implicit*)data;
   const Type t = actual_type(emit->gwion, imp->e->type);
-  const Instr instr = emit_add_instr(emit, RegPushImm);
-  instr->m_val = map_size(&t->nspc->info->value->map);
+  emit_pushimm(emit, map_size(&t->nspc->info->value->map));
   return GW_OK; emit_exp(emit, imp->e);
 }
 
diff --git a/src/lib/object_op.c b/src/lib/object_op.c
index 2ce91b7d..9a9ba746 100644
--- a/src/lib/object_op.c
+++ b/src/lib/object_op.c
@@ -139,8 +139,7 @@ ANN static void emit_member_func(const Emitter emit, const Exp_Dot *member) {
     else {
       if(vflag(f->value_ref, vflag_member))
         emit_regmove(emit, -SZ_INT);
-      const Instr instr = emit_add_instr(emit, RegPushImm);
-      instr->m_val = (m_uint)f;
+      emit_pushimm(emit, (m_uint)f);
       return;
     }
   } else if (is_static_call(emit->gwion, exp_self(member))) {
@@ -276,8 +275,7 @@ OP_EMIT(opem_object_dot) {
       ensure_emit(emit, t_base);
   }
   if (is_class(emit->gwion, value->type)) {
-    const Instr instr = emit_add_instr(emit, RegPushImm);
-    instr->m_val      = (m_uint)value->type;
+    emit_pushimm(emit, (m_uint)value->type);
     return GW_OK;
   }
   if (tflag(t_base, tflag_struct) && !GET_FLAG(value, static)) {
@@ -300,10 +298,7 @@ OP_EMIT(opem_object_dot) {
       emit_struct_data(emit, value, exp_getvar(exp_self(member)));
   } else if (GET_FLAG(value, static))
     emit_dot_static_import_data(emit, value, exp_getvar(exp_self(member)));
-  else { // member type
-    const Instr instr = emit_add_instr(emit, RegPushImm);
-    instr->m_val      = (m_uint)value->type;
-  }
+  else emit_pushimm(emit, (m_uint)value->type);
   if(isa(value->type, emit->gwion->type[et_object]) > 0 &&
      !exp_getvar(exp_self(member)) &&
     (GET_FLAG(value, static) || GET_FLAG(value, late)))
diff --git a/src/lib/union.c b/src/lib/union.c
index defac498..a1c89e13 100644
--- a/src/lib/union.c
+++ b/src/lib/union.c
@@ -32,8 +32,7 @@ static OP_EMIT(opem_union_dot) {
   const Map      map    = &member->base->type->nspc->info->value->map;
   CHECK_BB(emit_exp(emit, member->base));
   if (is_func(emit->gwion, exp_self(member)->type)) { // is_callable? can only be a func
-    const Instr instr = emit_add_instr(emit, RegPushImm);
-    instr->m_val = (m_uint)exp_self(member)->type->info->func->code;
+    emit_pushimm(emit, (m_uint)exp_self(member)->type->info->func->code);
     return GW_OK;
   }
   if (!strcmp(s_name(member->xid), "index")) {
-- 
2.43.0