]> Nishi Git Mirror - gwion.git/commitdiff
:art: emit_pushimm
authorfennecdjay <fennecdjay@gmail.com>
Mon, 24 Oct 2022 14:55:56 +0000 (16:55 +0200)
committerfennecdjay <fennecdjay@gmail.com>
Mon, 24 Oct 2022 14:58:45 +0000 (16:58 +0200)
include/emit.h
src/emit/emit.c
src/lib/closure.c
src/lib/dict.c
src/lib/lib_class.c
src/lib/object_op.c
src/lib/union.c

index 279c30021a269c242b033f50960507f6aee44ae7..e77a41c455e8e74bc6851617384041375e90d2bf 100644 (file)
@@ -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
index 28df8a443f7093af667c910fff878fd440180ee2..ffd9ab4915fba1b084e8ef8f6097afd84ff87323 100644 (file)
@@ -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);
index 3e95847423f68189e35013d2ac9e466a72763d19..842f313968b73788b52a44b3a061f114bbe45bdf 100644 (file)
@@ -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);
 }
 
index a1ee9ece6f00092ed2a0f3fecc25c8943000f8e2..c055dfe0ae98f191b621d2d1bb90a2d94f2867f2 100644 (file)
@@ -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);
index 783c93f4c4c714c3e961a7e87bc58647833d7ca0..b4af11ebdbd6b2db77948b23b26c35d0521304e8 100644 (file)
@@ -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);
 }
 
index 2ce91b7dda2e6d32f979a0dc35018860e337ee9e..9a9ba746c81920c3b09366c63856f1712c0e63e1 100644 (file)
@@ -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)))
index defac498f2aece63b34894ec21511afa94647f27..a1c89e1367f102c3ce9056c1f4fc56bb2dbca361 100644 (file)
@@ -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")) {