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

bacek at svn.parrot.org bacek at svn.parrot.org
Fri May 22 11:03:01 UTC 2009


Author: bacek
Date: Fri May 22 11:03:00 2009
New Revision: 39035
URL: https://trac.parrot.org/parrot/changeset/39035

Log:
[pmc] Rewrite Integer.modulus without MULTIs.

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

Modified: branches/tt452_reduce_mmd/src/pmc/integer.pmc
==============================================================================
--- branches/tt452_reduce_mmd/src/pmc/integer.pmc	Fri May 22 10:55:03 2009	(r39034)
+++ branches/tt452_reduce_mmd/src/pmc/integer.pmc	Fri May 22 11:03:00 2009	(r39035)
@@ -864,28 +864,9 @@
 
 
     VTABLE PMC *modulus(PMC *value, PMC *dest) {
-        switch (value->vtable->base_type) {
-            case enum_class_BigInt:
-                {
-                    PMC *temp = VTABLE_get_bignum(INTERP, SELF);
-                    maybe_throw_overflow_error(INTERP);
-                    return VTABLE_modulus(INTERP, temp, value, dest);
-                }
-                break;
-
-            default:
-                {
-                    INTVAL d = VTABLE_get_integer(INTERP, value);
-                    if (d == 0)
-                        Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
-                            "int modulus by zero");
-
-                    dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-                    VTABLE_set_integer_native(INTERP, dest,
-                        intval_mod(SELF.get_integer(), d));
-                }
-                return dest;
-        }
+        dest = VTABLE_clone(INTERP, SELF);
+        VTABLE_i_modulus(INTERP, dest, value);
+        return dest;
     }
 
 
@@ -915,22 +896,25 @@
     }
 
 
-    MULTI void i_modulus(BigInt value) {
-        maybe_throw_overflow_error(INTERP);
-        SELF = upgrade_self_to_bignum(INTERP, SELF);
-        VTABLE_i_modulus(INTERP, SELF, value);
-    }
-
-
-    MULTI void i_modulus(DEFAULT value) {
-        const INTVAL d = VTABLE_get_integer(INTERP, value);
+    VTABLE void i_modulus(PMC *value) {
+        switch (value->vtable->base_type) {
+            case enum_class_BigInt:
+                maybe_throw_overflow_error(INTERP);
+                SELF = upgrade_self_to_bignum(INTERP, SELF);
+                VTABLE_i_modulus(INTERP, SELF, value);
+                break;
+            default:
+                {
+                    const INTVAL d = VTABLE_get_integer(INTERP, value);
 
-        if (d == 0)
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
-                    "int modulus by zero");
+                    if (d == 0)
+                        Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
+                            "int modulus by zero");
 
-        VTABLE_set_integer_native(INTERP, SELF,
-                intval_mod(SELF.get_integer(), d));
+                    VTABLE_set_integer_native(INTERP, SELF,
+                        intval_mod(SELF.get_integer(), d));
+                }
+        }
     }
 
 


More information about the parrot-commits mailing list