[svn:parrot] r38938 - branches/tt452_reduce_mmd/src/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Tue May 19 14:43:12 UTC 2009


Author: bacek
Date: Tue May 19 14:43:12 2009
New Revision: 38938
URL: https://trac.parrot.org/parrot/changeset/38938

Log:
[pmc] Use less MULTIs in BigInt.pmc

Modified:
   branches/tt452_reduce_mmd/src/pmc/bigint.pmc

Modified: branches/tt452_reduce_mmd/src/pmc/bigint.pmc
==============================================================================
--- branches/tt452_reduce_mmd/src/pmc/bigint.pmc	Tue May 19 14:42:51 2009	(r38937)
+++ branches/tt452_reduce_mmd/src/pmc/bigint.pmc	Tue May 19 14:43:12 2009	(r38938)
@@ -836,28 +836,25 @@
         bigint_sub_bigint_int(INTERP, SELF, 1, SELF);
     }
 
-    MULTI PMC *add(BigInt value, PMC *dest) {
-        dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_add_bigint(INTERP, SELF, value, dest);
-        return dest;
-    }
-
-    MULTI PMC *add(Integer value, PMC *dest) {
+    VTABLE PMC *add(PMC *value, PMC *dest) {
         dest = pmc_new(INTERP, SELF->vtable->base_type);
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_add_bigint(INTERP, SELF, value, dest);
+                break;
+            case enum_class_Integer:
+                bigint_add_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'add' for %Ss",
+                    VTABLE_name(interp, value));
+        }
 
-        bigint_add_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
         return dest;
     }
 
-    MULTI PMC *add(DEFAULT value, PMC *dest) {
-        UNUSED(dest)
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'add' for %Ss",
-            VTABLE_name(interp, value));
-    }
-
     VTABLE PMC *add_int(INTVAL value, PMC *dest) {
         dest = pmc_new(INTERP, SELF->vtable->base_type);
 
@@ -865,19 +862,21 @@
         return dest;
     }
 
-    MULTI void i_add(BigInt value) {
-        bigint_add_bigint(INTERP, SELF, value, SELF);
-    }
-
-    MULTI void i_add(Integer value) {
-        bigint_add_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
-    }
+    VTABLE void i_add(PMC *value) {
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_add_bigint(INTERP, SELF, value, SELF);
+                break;
+            case enum_class_Integer:
+                bigint_add_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'i_add' for %Ss",
+                    VTABLE_name(interp, value));
+        }
 
-    MULTI void i_add(DEFAULT value) {
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'i_add' for %Ss",
-            VTABLE_name(interp, value));
     }
 
     VTABLE void i_add_int(INTVAL value) {
@@ -892,34 +891,24 @@
     }
 
 
-    MULTI PMC *subtract(BigInt value, PMC *dest) {
-        if (dest)
-            pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
-        else
-            dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_sub_bigint(INTERP, SELF, value, dest);
-        return dest;
-    }
-
-    MULTI PMC *subtract(Integer value, PMC *dest) {
-        if (dest)
-            pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
-        else
-            dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_sub_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
+    VTABLE PMC *subtract(PMC *value, PMC *dest) {
+        dest = pmc_new(INTERP, SELF->vtable->base_type);
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_sub_bigint(INTERP, SELF, value, dest);
+                break;
+            case enum_class_Integer:
+                bigint_sub_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'subtract' for %Ss",
+                    VTABLE_name(interp, value));
+        }
         return dest;
     }
 
-    MULTI PMC *subtract(DEFAULT value, PMC *dest) {
-        UNUSED(dest)
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'subtract' for %Ss",
-            VTABLE_name(interp, value));
-    }
-
     VTABLE PMC *subtract_int(INTVAL value, PMC *dest) {
         if (dest)
             pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
@@ -930,19 +919,20 @@
         return dest;
     }
 
-    MULTI void i_subtract(BigInt value) {
-        bigint_sub_bigint(INTERP, SELF, value, SELF);
-    }
-
-    MULTI void i_subtract(Integer value) {
-        bigint_sub_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
-    }
-
-    MULTI void i_subtract(DEFAULT value) {
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'i_subtract' for %Ss",
-            VTABLE_name(interp, value));
+    VTABLE void i_subtract(PMC *value) {
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_sub_bigint(INTERP, SELF, value, SELF);
+                break;
+            case enum_class_Integer:
+                bigint_sub_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'i_subtract' for %Ss",
+                    VTABLE_name(interp, value));
+        }
     }
 
     VTABLE void i_subtract_int(INTVAL value) {
@@ -957,28 +947,24 @@
     }
 
 
-    MULTI PMC *multiply(BigInt value, PMC *dest) {
-        dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_mul_bigint(INTERP, SELF, value, dest);
-        return dest;
-    }
-
-    MULTI PMC *multiply(Integer value, PMC *dest) {
+    VTABLE PMC *multiply(PMC *value, PMC *dest) {
         dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_mul_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_mul_bigint(INTERP, SELF, value, dest);
+                break;
+            case enum_class_Integer:
+                bigint_mul_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'multiply' for %Ss",
+                    VTABLE_name(interp, value));
+        }
         return dest;
     }
 
-    MULTI PMC *multiply(DEFAULT value, PMC *dest) {
-        UNUSED(dest)
-         Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'multiply' for %Ss",
-            VTABLE_name(interp, value));
-    }
-
     VTABLE PMC *multiply_int(INTVAL value, PMC *dest) {
         dest = pmc_new(INTERP, SELF->vtable->base_type);
 
@@ -986,17 +972,20 @@
         return dest;
     }
 
-    MULTI void i_multiply(BigInt value) {
-        bigint_mul_bigint(INTERP, SELF, value, SELF);
-    }
-    MULTI void i_multiply(Integer value) {
-        bigint_mul_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
-    }
-    MULTI void i_multiply(DEFAULT value) {
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'i_multiply' for %Ss",
-            VTABLE_name(interp, value));
+    VTABLE void i_multiply(PMC *value) {
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_mul_bigint(INTERP, SELF, value, SELF);
+                break;
+            case enum_class_Integer:
+                bigint_mul_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'multiply' for %Ss",
+                    VTABLE_name(interp, value));
+        }
     }
 
     VTABLE void i_multiply_int(INTVAL value) {
@@ -1029,14 +1018,22 @@
         return dest;
     }
 
-    MULTI PMC *divide(BigInt value, PMC *dest) {
+    VTABLE PMC *divide(PMC *value, PMC *dest) {
         BIGINT *bi;
-        if (dest)
-            pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
-        else
-            dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_div_bigint(INTERP, SELF, value, dest);
+        dest = pmc_new(INTERP, SELF->vtable->base_type);
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_div_bigint(INTERP, SELF, value, dest);
+                break;
+            case enum_class_Integer:
+                bigint_div_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'divide' for %Ss",
+                    VTABLE_name(interp, value));
+        }
 #if 0
         /* to downgrade or not that's the question */
         GETATTR_BigInt_bi(interp, dest, bi);
@@ -1049,24 +1046,6 @@
         return dest;
     }
 
-    MULTI PMC *divide(Integer value, PMC *dest) {
-        if (dest)
-            pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
-        else
-            dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_div_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
-        return dest;
-    }
-
-    MULTI PMC *divide(DEFAULT value, PMC *dest) {
-        UNUSED(dest)
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'divide' for %Ss",
-            VTABLE_name(interp, value));
-    }
-
     VTABLE PMC *divide_int(INTVAL value, PMC *dest) {
         if (dest)
             pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
@@ -1077,45 +1056,44 @@
         return dest;
     }
 
-    MULTI void i_divide(BigInt value) {
-        bigint_div_bigint(INTERP, SELF, value, SELF);
-    }
-    MULTI void i_divide(Integer value) {
-        bigint_div_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
-    }
-    MULTI void i_divide(DEFAULT value) {
-         Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'i_divide' for %Ss",
-            VTABLE_name(interp, value));
+    MULTI void i_divide(PMC *value) {
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_div_bigint(INTERP, SELF, value, SELF);
+                break;
+            case enum_class_Integer:
+                bigint_div_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'i_divide' for %Ss",
+                    VTABLE_name(interp, value));
+        }
     }
 
     VTABLE void i_divide_int(INTVAL value) {
         bigint_div_bigint_int(INTERP, SELF, value, SELF);
     }
 
-    MULTI PMC *floor_divide(BigInt value, PMC *dest) {
-        dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_fdiv_bigint(INTERP, SELF, value, dest);
-        return dest;
-    }
-
-    MULTI PMC *floor_divide(Integer value, PMC *dest) {
+    VTABLE PMC *floor_divide(PMC *value, PMC *dest) {
         dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_fdiv_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_fdiv_bigint(INTERP, SELF, value, dest);
+                break;
+            case enum_class_Integer:
+                bigint_fdiv_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'floor_divide' for %Ss",
+                    VTABLE_name(interp, value));
+        }
         return dest;
     }
 
-    MULTI PMC *floor_divide(DEFAULT value, PMC *dest) {
-        UNUSED(dest)
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'floor_divide' for %Ss",
-            VTABLE_name(interp, value));
-    }
-
     VTABLE PMC *floor_divide_int(INTVAL value, PMC *dest) {
         if (dest)
             pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
@@ -1126,94 +1104,86 @@
         return dest;
     }
 
-    MULTI void i_floor_divide(BigInt value) {
-        bigint_fdiv_bigint(INTERP, SELF, value, SELF);
-    }
-
-    MULTI void i_floor_divide(Integer value) {
-        bigint_fdiv_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
-    }
-
-    MULTI void i_floor_divide(DEFAULT value) {
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'i_floor_divide' for %Ss",
-            VTABLE_name(interp, value));
+    VTABLE void i_floor_divide(PMC *value) {
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_fdiv_bigint(INTERP, SELF, value, SELF);
+                break;
+            case enum_class_Integer:
+                bigint_fdiv_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'i_floor_divide' for %Ss",
+                    VTABLE_name(interp, value));
+        }
     }
 
     VTABLE void i_floor_divide_int(INTVAL value) {
         bigint_fdiv_bigint_int(INTERP, SELF, value, SELF);
     }
 
-    MULTI PMC *modulus(BigInt value, PMC *dest) {
-        if (dest)
-            pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
-        else
-            dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_mod_bigint(INTERP, SELF, value, dest);
-        return dest;
-    }
-
-    MULTI PMC *modulus(Integer value, PMC *dest) {
-        if (dest)
-            pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
-        else
-            dest = pmc_new(INTERP, SELF->vtable->base_type);
-
-        bigint_mod_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
+    VTABLE PMC *modulus(PMC *value, PMC *dest) {
+        dest = pmc_new(INTERP, SELF->vtable->base_type);
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_mod_bigint(INTERP, SELF, value, dest);
+                break;
+            case enum_class_Integer:
+                bigint_mod_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'modulus' for %Ss",
+                    VTABLE_name(interp, value));
+        }
         return dest;
     }
 
-    MULTI PMC *modulus(DEFAULT value, PMC *dest) {
-        UNUSED(dest)
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'modulus' for %Ss",
-            VTABLE_name(interp, value));
-    }
-
-    MULTI void i_modulus(BigInt value) {
-        bigint_mod_bigint(INTERP, SELF, value, SELF);
-    }
-    MULTI void i_modulus(Integer value) {
-        bigint_mod_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
-    }
-    MULTI void i_modulus(DEFAULT value) {
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'i_modulus' for %Ss",
-            VTABLE_name(interp, value));
-    }
-
-    MULTI INTVAL cmp(BigInt value) {
-        return bigint_cmp(INTERP, SELF, value);
-    }
-
-    MULTI INTVAL cmp(Integer value) {
-        return bigint_cmp_int(INTERP, SELF, VTABLE_get_integer(interp, value));
-    }
-
-    MULTI INTVAL cmp(DEFAULT value) {
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'cmp' for %Ss",
-            VTABLE_name(interp, value));
-    }
-
-    MULTI INTVAL is_equal(BigInt value) {
-        return bigint_cmp(INTERP, SELF, value) == 0;
+    VTABLE void i_modulus(PMC *value) {
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                bigint_mod_bigint(INTERP, SELF, value, SELF);
+                break;
+            case enum_class_Integer:
+                bigint_mod_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), SELF);
+                break;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'i_modulus' for %Ss",
+                    VTABLE_name(interp, value));
+        }
     }
 
-    MULTI INTVAL is_equal(Integer value) {
-        return bigint_cmp_int(INTERP, SELF, VTABLE_get_integer(interp, value)) == 0;
+    VTABLE INTVAL cmp(PMC *value) {
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                return bigint_cmp(INTERP, SELF, value);
+            case enum_class_Integer:
+                return bigint_cmp_int(INTERP, SELF, VTABLE_get_integer(interp, value));
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'cmp' for %Ss",
+                    VTABLE_name(interp, value));
+        }
     }
 
-    MULTI INTVAL is_equal(DEFAULT value) {
-        Parrot_ex_throw_from_c_args(INTERP, NULL,
-            EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
-            "BigInt: no multiple dispatch variant 'is_equal' for %Ss",
-            VTABLE_name(interp, value));
+    VTABLE INTVAL is_equal(PMC *value) {
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                return bigint_cmp(INTERP, SELF, value) == 0;
+            case enum_class_Integer:
+                return bigint_cmp_int(INTERP, SELF, VTABLE_get_integer(interp, value)) == 0;
+            default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL,
+                    EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
+                    "BigInt: no multiple dispatch variant 'is_equal' for %Ss",
+                    VTABLE_name(interp, value));
+        }
     }
 
 /*


More information about the parrot-commits mailing list