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

bacek at svn.parrot.org bacek at svn.parrot.org
Wed May 20 12:24:53 UTC 2009


Author: bacek
Date: Wed May 20 12:24:53 2009
New Revision: 38981
URL: https://trac.parrot.org/parrot/changeset/38981

Log:
[pmc] Refactor Integer.(i_)?subtract 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	Wed May 20 11:34:23 2009	(r38980)
+++ branches/tt452_reduce_mmd/src/pmc/integer.pmc	Wed May 20 12:24:53 2009	(r38981)
@@ -396,8 +396,7 @@
                 break;
 
             case enum_class_BigInt:
-                pmc_reuse(INTERP, SELF, enum_class_BigInt, 0);
-                VTABLE_set_number_native(INTERP, SELF, a);
+                upgrade_self_to_bignum(INTERP, SELF);
                 VTABLE_i_add(INTERP, SELF, value);
                 break;
 
@@ -443,52 +442,9 @@
 
 */
 
-    MULTI PMC *subtract(Integer value, PMC *dest) {
-        const INTVAL a = SELF.get_integer();
-        const INTVAL b = VTABLE_get_integer(INTERP, value);
-        const INTVAL c = a - b;
-
-        if ((c^a) >= 0 || (c^~b) >= 0) {
-            dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
-            VTABLE_set_integer_native(INTERP, dest, c);
-            return dest;
-        }
-        else {
-            PMC *temp;
-            maybe_throw_overflow_error(interp);
-            temp = VTABLE_get_bignum(interp, SELF);
-            return VTABLE_subtract(interp, temp, value, dest);
-        }
-    }
-
-
-    MULTI PMC *subtract(Complex value, PMC *dest) {
-        const INTVAL a = SELF.get_integer();
-        dest           = pmc_new(INTERP, VTABLE_type(INTERP, value));
-
-        VTABLE_set_number_native(INTERP, dest,
-                a - VTABLE_get_number_keyed_int(INTERP, value, 0));
-        VTABLE_set_number_keyed_int(INTERP, dest, 1,
-                -VTABLE_get_number_keyed_int(INTERP, value, 1));
-
-        return dest;
-    }
-
-
-    MULTI PMC *subtract(BigInt value, PMC *dest) {
-        PMC *temp;
-        maybe_throw_overflow_error(interp);
-        temp = VTABLE_get_bignum(interp, SELF);
-        return VTABLE_subtract(interp, temp, value, dest);
-    }
-
-
-    MULTI PMC *subtract(DEFAULT value, PMC *dest) {
-        dest = pmc_new(INTERP, VTABLE_type(INTERP, value));
-
-        VTABLE_set_number_native(INTERP, dest,
-                SELF.get_integer() - VTABLE_get_number(INTERP, value));
+    VTABLE PMC *subtract(PMC *value, PMC *dest) {
+        dest = VTABLE_clone(INTERP, SELF);
+        VTABLE_i_subtract(INTERP, dest, value);
         return dest;
     }
 
@@ -536,35 +492,33 @@
 
 */
 
-    MULTI void i_subtract(Integer value) {
+    VTABLE void i_subtract(PMC *value) {
         const INTVAL a = SELF.get_integer();
-        const INTVAL b = VTABLE_get_integer(INTERP, value);
-        const INTVAL c = a - b;
+        const INTVAL type = value->vtable->base_type;
 
-        if ((c^a) >= 0 || (c^~b) >= 0)
-            VTABLE_set_integer_native(INTERP, SELF, c);
-        else {
-            maybe_throw_overflow_error(interp);
-            SELF = upgrade_self_to_bignum(interp, SELF);
-            VTABLE_i_subtract(interp, SELF, value);
-        }
-    }
-
-
-    MULTI void i_subtract(Complex value) {
-        const INTVAL a = SELF.get_integer();
+        switch (type) {
+            case enum_class_Integer:
+                STATICSELF.i_subtract_int(VTABLE_get_integer(INTERP, value));
+                break;
 
-        pmc_reuse(INTERP, SELF, enum_class_Complex, 0);
-        VTABLE_set_number_native(INTERP, SELF,
-                (FLOATVAL)a - VTABLE_get_number_keyed_int(INTERP, value, 0));
-        VTABLE_set_number_keyed_int(INTERP, SELF, 1,
-                -VTABLE_get_number_keyed_int(INTERP, value, 1));
-    }
+            case enum_class_Complex:
+                pmc_reuse(INTERP, SELF, enum_class_Complex, 0);
+                VTABLE_set_number_native(INTERP, SELF,
+                        (FLOATVAL)a - VTABLE_get_number_keyed_int(INTERP, value, 0));
+                VTABLE_set_number_keyed_int(INTERP, SELF, 1,
+                        -VTABLE_get_number_keyed_int(INTERP, value, 1));
+                break;
 
+            case enum_class_BigInt:
+                upgrade_self_to_bignum(INTERP, SELF);
+                VTABLE_i_subtract(INTERP, SELF, value);
+                break;
 
-    MULTI void i_subtract(DEFAULT value) {
-        VTABLE_set_number_native(INTERP, SELF,
-                SELF.get_integer() - VTABLE_get_number(INTERP, value));
+            default:
+                VTABLE_set_number_native(INTERP, SELF,
+                        a - VTABLE_get_number(INTERP, value));
+                break;
+        }
     }
 
 


More information about the parrot-commits mailing list