Răsfoiți Sursa

refactoring

Kajetan Johannes Hammerle 4 ani în urmă
părinte
comite
cdd65ddd7f
1 a modificat fișierele cu 8 adăugiri și 20 ștergeri
  1. 8 20
      vm/Script.c

+ 8 - 20
vm/Script.c

@@ -299,26 +299,14 @@ static void sVarRef(Script* sc) {
     }
 }
 
-static void sLoadIntRef(Script* sc) {
-    int address = 0;
-    if(sPopInt(sc, &address) && sCheckAddress(sc, address, sizeof(int))) {
-        sPush(sc, sc->stack + address, sizeof(int));
-    }
-}
-
-static void sLoadFloatRef(Script* sc) {
-    int address = 0;
-    if(sPopInt(sc, &address) && sCheckAddress(sc, address, sizeof(float))) {
-        sPush(sc, sc->stack + address, sizeof(float));
-    }
-}
-
-static void sLoadBoolRef(Script* sc) {
-    int address = 0;
-    if(sPopInt(sc, &address) && sCheckAddress(sc, address, sizeof(bool))) {
-        sPush(sc, sc->stack + address, sizeof(bool));
+#define LOAD_REF(type, Type)                                                   \
+    {                                                                          \
+        int address = 0;                                                       \
+        if(sPopInt(sc, &address) &&                                            \
+           sCheckAddress(sc, address, sizeof(type))) {                         \
+            sPush(sc, sc->stack + address, sizeof(type));                      \
+        }                                                                      \
     }
-}
 
 #define CASE_NUMBER_OP(name, op)                                               \
     case OP_##name##_INT: NUMBER_OP(int, Int, op); break;                      \
@@ -337,7 +325,7 @@ static void sLoadBoolRef(Script* sc) {
     case OP_PRINT_##TYPE: PRINT(type, Type, type##Printer); break;             \
     case OP_EQUAL_##TYPE: BOOL_OP(type, Type, ==); break;                      \
     case OP_REF_STORE_##TYPE: sStoreRef(sc, sizeof(type)); break;              \
-    case OP_REF_LOAD_##TYPE: sLoad##Type##Ref(sc); break;
+    case OP_REF_LOAD_##TYPE: LOAD_REF(type, Type); break;
 
 static void sConsumeInstruction(Script* sc) {
     switch(sReadOperation(sc)) {