]> Nishi Git Mirror - gwion.git/commitdiff
:art: some emitter clean
authorfennecdjay <fennecdjay@gmail.com>
Sat, 15 Oct 2022 19:37:45 +0000 (21:37 +0200)
committerfennecdjay <fennecdjay@gmail.com>
Sat, 15 Oct 2022 19:37:45 +0000 (21:37 +0200)
include/opcode.h
opcode.txt
src/emit/emit.c
src/vm/vm.c
src/vm/vm_code.c

index 7daf9908ff2bcb0a18507137e0cea36fe484db87..26655c39bdd2576061cce43e04c9d088df6a4bde 100644 (file)
@@ -6,6 +6,7 @@ enum {
   eRegPushImm2,
   eRegPushImm3,
   eRegPushImm4,
+  eRegPush2Imm,
   eRegPushMem,
   eRegPushMem2,
   eRegPushMem3,
@@ -224,6 +225,7 @@ enum {
 #define  RegPushImm2          (f_instr)eRegPushImm2
 #define  RegPushImm3          (f_instr)eRegPushImm3
 #define  RegPushImm4          (f_instr)eRegPushImm4
+#define  RegPush2Imm          (f_instr)eRegPush2Imm
 #define  RegPushMem           (f_instr)eRegPushMem
 #define  RegPushMem2          (f_instr)eRegPushMem2
 #define  RegPushMem3          (f_instr)eRegPushMem3
@@ -473,6 +475,12 @@ ANN static inline void dump_opcodes(const VM_Code code) {
         gw_out(" {-M}%-14"UINT_F"{0}", instr->m_val2);
         gw_out("\n");
         break;
+      case eRegPush2Imm:
+        gw_out("{Y}┃{0}{-}% 4lu{0}: RegPush2Imm ", j);
+        gw_out(" {-R}%-14p{0}", instr->m_val);
+        gw_out(" {-M}%-14"UINT_F"{0}", instr->m_val2);
+        gw_out("\n");
+        break;
       case eRegPushMem:
         gw_out("{Y}┃{0}{-}% 4lu{0}: RegPushMem  ", j);
         gw_out(" {-R}%-14"UINT_F"{0}", instr->m_val);
index 9cbb9db3bf1f9fc952d62de9953c3af649fb25ee..073470918e64c7d8038db6e53a164cb6e09f47c2 100644 (file)
@@ -3,6 +3,7 @@ RegPushImm~p~u
 RegPushImm2~f~u
 RegPushImm3~p~u
 RegPushImm4~p~u
+RegPush2Imm~p~u
 RegPushMem~u~u
 RegPushMem2~f~u
 RegPushMem3~u~u
index 3da44aa00b1ec9f04b9097f67f1c52d254b87f7c..f0f8883eda11e20ed67f64ef6b6165814c2c4629 100644 (file)
@@ -2438,10 +2438,9 @@ ANN static inline m_bool emit_handler_list(const restrict Emitter emit,
   const m_uint offset = emit_local(emit, emit->gwion->type[et_int]);
   for(uint32_t i = 0; i < handlers->len; i++) {
     Handler *handler = mp_vector_at(handlers, Handler, i);
-    // useless args. should be not in the VM
     const Instr instr = emit_add_instr(emit, HandleEffect);
     instr->m_val      = emit->status.effect = offset;
-    instr->m_val2     = (m_uint)handler->xid; // are we even using this?
+    instr->m_val2     = (m_uint)handler->xid;
     CHECK_BB(scoped_stmt(emit, handler->stmt));
     emit_try_goto(emit, v);
     instr->m_val = emit_code_size(emit);
@@ -2959,24 +2958,14 @@ ANN static m_bool _emit_class_def(const Emitter emit, const Class_Def cdef) {
     CHECK_BB(cdef_parent(emit, c));
   if (c->body) {
     emit_class_code(emit, t->name);
-//    if (scanx_body(emit->env, c, (_exp_func)emit_section, emit) > 0 && vector_size(&emit->code->instr) > 1)
-    if (scanx_body(emit->env, c, (_exp_func)emit_section, emit) > 0)
-{
-//    if (vector_size(&emit->code->instr))
-//    if (tflag(t, tflag_ctor))
+    const m_bool ret = scanx_body(emit->env, c, (_exp_func)emit_section, emit);
+    if (ret > 0 && tflag(t, tflag_ctor))
       t->nspc->pre_ctor = finalyze(emit, FuncReturn);
-/*
-else{
-puts("hehe");
-free_code(emit->gwion->mp, emit->code);
-      emit_pop_code(emit);
-}
-*/
-}    else {
+    else{
       free_code(emit->gwion->mp, emit->code);
       emit_pop_code(emit);
-      return GW_ERROR;
     }
+    return ret;
   }
   return GW_OK;
 }
index 949254063ee11e47ac2e34d40d01dc2011ffeee1..9addd9acd355792fdf3f79ac123a86bbd8337afc 100644 (file)
@@ -420,7 +420,7 @@ _Pragma(STRINGIFY(COMPILER diagnostic ignored UNINITIALIZED)
 __attribute__((hot)) void
 vm_prepare(const VM *vm, m_bit *prepare_code) { // lgtm [cpp/use-of-goto]
   static const void *dispatch[] = {
-      &&regsetimm, &&regpushimm, &&regpushfloat, &&regpushother, &&regpushaddr,
+      &&regsetimm, &&regpushimm, &&regpushfloat, &&regpushother, &&regpushaddr, &&regpushtwoimm,
       &&regpushmem, &&regpushmemfloat, &&regpushmemother, &&regpushmemaddr,
       &&regpushmemderef, &&pushnow, &&baseint, &&basefloat, &&baseother,
       &&baseaddr, &&regtoreg, &&regtoregother, &&regtoregother2, &&regtoregaddr, &&regtoregderef,
@@ -518,6 +518,11 @@ vm_prepare(const VM *vm, m_bit *prepare_code) { // lgtm [cpp/use-of-goto]
       *(m_uint **)reg = &VAL;
       reg += SZ_INT;
       DISPATCH()
+    regpushtwoimm:
+      *(m_uint *)reg = VAL;
+      *(m_uint *)(reg + SZ_INT)= VAL2;
+      reg += SZ_INT*2;
+      DISPATCH()
     regpushmem:
       *(m_uint *)reg = *(m_uint *)(mem + IVAL);
       reg += SZ_INT;
@@ -1276,7 +1281,7 @@ fflush(stdout);
 } else {
 
 static void *_dispatch[] = {
-      &&_regsetimm, &&_regpushimm, &&_regpushfloat, &&_regpushother, &&_regpushaddr,
+      &&_regsetimm, &&_regpushimm, &&_regpushfloat, &&_regpushother, &&_regpushaddr, &&_regpushtwoimm,
       &&_regpushmem, &&_regpushmemfloat, &&_regpushmemother, &&_regpushmemaddr,
       &&_regpushmemderef, &&_pushnow, &&_baseint, &&_basefloat, &&_baseother,
       &&_baseaddr, &&_regtoreg, &&_regtoregother, &&_regtoregother2, &&_regtoregaddr, &&_regtoregderef,
@@ -1337,6 +1342,7 @@ goto *_dispatch[*(m_bit*)prepare_code];
     PREPARE(regpushfloat);
     PREPARE(regpushother);
     PREPARE(regpushaddr);
+    PREPARE(regpushtwoimm);
     PREPARE(regpushmem);
     PREPARE(regpushmemfloat);
     PREPARE(regpushmemother);
index e8602b8c333694d97320eef016f780d974426230..940b9ae37316b9a0bf209c97f9164736a40ad831 100644 (file)
@@ -103,6 +103,13 @@ ANN static m_bit *tobytecode(MemPool p, const VM_Code code) {
           instr->m_val = next->m_val;
           next->opcode = eNoOp;
         }
+      } else if (instr->opcode == eRegPushImm) {
+        const Instr next = (Instr)vector_at(v, i+1);
+        if (next->opcode == eRegPushImm) {
+          instr->opcode = eRegPush2Imm;
+          instr->m_val2 = next->m_val;
+          next->opcode = eNoOp;
+        }
       } else if (instr->opcode == eUnroll2) {
         const Instr  unroll     = (Instr)instr->m_val;
         const m_uint pc         = vector_find(v, (m_uint)unroll);