Author: leo
Date: Fri Apr 15 08:38:47 2005
New Revision: 7845

Modified:
   trunk/classes/bigint.pmc
   trunk/classes/complex.pmc
   trunk/classes/float.pmc
   trunk/classes/integer.pmc
   trunk/classes/intlist.pmc
   trunk/classes/perlstring.pmc
   trunk/classes/perlundef.pmc
   trunk/classes/resizablepmcarray.pmc
   trunk/classes/scalar.pmc
   trunk/dynclasses/pyint.pmc
   trunk/dynclasses/pylist.pmc
   trunk/dynclasses/pylong.pmc
   trunk/imcc/parser_util.c
   trunk/imcc/t/syn/keyed.t
   trunk/t/pmc/intlist.t
   trunk/vtable.tbl
Log:
MMD 25 - multiply

Modified: trunk/classes/bigint.pmc
==============================================================================
--- trunk/classes/bigint.pmc    (original)
+++ trunk/classes/bigint.pmc    Fri Apr 15 08:38:47 2005
@@ -125,7 +125,6 @@
 static void
 bigint_mul_bigint(Interp *interpreter, PMC* self, PMC *value, PMC *dest)
 {
-    VTABLE_morph(interpreter, dest, enum_class_BigInt);
     mpz_mul(BN(dest), BN(self), BN(value));
 }
 
@@ -133,7 +132,6 @@
 bigint_mul_bigint_int(Interp *interpreter, PMC* self, INTVAL value,
         PMC *dest)
 {
-    VTABLE_morph(interpreter, dest, enum_class_BigInt);
     mpz_mul_ui(BN(dest), BN(self), value);
 }
 
@@ -713,20 +711,56 @@
     }
 
 
-    void multiply(PMC* value, PMC* dest) {
+    PMC* multiply(PMC* value, PMC* dest) {
 MMD_BigInt: {
-                bigint_mul_bigint(INTERP, SELF, value, dest);
-            }
+            if (dest)
+                VTABLE_morph(interpreter, dest, SELF->vtable->base_type);
+            else
+                dest = pmc_new(INTERP, SELF->vtable->base_type);
+            bigint_mul_bigint(INTERP, SELF, value, dest);
+            return dest;
+        }
 MMD_Integer: {
+            if (dest)
+                VTABLE_morph(interpreter, dest, SELF->vtable->base_type);
+            else
+                dest = pmc_new(INTERP, SELF->vtable->base_type);
             bigint_mul_bigint_int(INTERP, SELF, PMC_int_val(value), dest);
+            return dest;
+         }
+MMD_DEFAULT: {
+             internal_exception(1, "unimp mul");
+            return dest;
+         }
+    }
+
+    PMC* multiply_int(INTVAL value, PMC* dest) {
+        if (dest)
+            VTABLE_morph(interpreter, dest, SELF->vtable->base_type);
+        else
+                dest = pmc_new(INTERP, SELF->vtable->base_type);
+        bigint_mul_bigint_int(INTERP, SELF, value, dest);
+        return dest;
+    }
+
+    void i_multiply (PMC* value) {
+MMD_BigInt: {
+                bigint_mul_bigint(INTERP, SELF, value, SELF);
+            }
+MMD_Integer: {
+                bigint_mul_bigint_int(INTERP, SELF, PMC_int_val(value), SELF);
              }
 MMD_DEFAULT: {
-                 internal_exception(1, "unimp mul");
+                internal_exception(1, "unimp mul");
              }
     }
 
-    void multiply_int(INTVAL value, PMC* dest) {
-        bigint_mul_bigint_int(INTERP, SELF, value, dest);
+    void i_multiply_int (INTVAL value) {
+        bigint_mul_bigint_int(INTERP, SELF, value, SELF);
+    }
+
+    void i_multiply_float (FLOATVAL value) {
+        internal_exception(1, "unimp mul");
     }
 
     void divide(PMC* value, PMC* dest) {

Modified: trunk/classes/complex.pmc
==============================================================================
--- trunk/classes/complex.pmc   (original)
+++ trunk/classes/complex.pmc   Fri Apr 15 08:38:47 2005
@@ -723,14 +723,22 @@
     }
 /*
 
-=item C<void multiply (PMC* value, PMC* dest)>
+=item C<PMC* multiply (PMC* value, PMC* dest)>
 
-=item C<void multiply_int (INTVAL value, PMC* dest)>
+=item C<PMC* multiply_int (INTVAL value, PMC* dest)>
 
-=item C<void multiply_float (FLOATVAL value, PMC* dest)>
+=item C<PMC* multiply_float (FLOATVAL value, PMC* dest)>
 
 Multiplies the complex number with C<value>, placing the result in C<dest>.
 
+=item C<void i_multiply (PMC* value)>
+
+=item C<void i_multiply_int (INTVAL value)>
+
+=item C<void i_multiply_float (FLOATVAL value)>
+
+Multiplies the complex number SELF inplace with C<value>.
+
 =cut
 
 */
@@ -742,40 +750,76 @@
   (a+ib)(c+id)=(ac-bd)+i((a+b)(c+d)-ac-bd).
 
 */
-    void multiply (PMC* value, PMC* dest) {
-MMD_Integer: {
-        FLOATVAL re = RE(SELF) * PMC_int_val(value);
-        FLOATVAL im = IM(SELF) * PMC_int_val(value);
-        VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
-        RE(dest) = re;
-        IM(dest) = im;
-        }
+    PMC* multiply (PMC* value, PMC* dest) {
 MMD_Complex: {
-        FLOATVAL re = RE(SELF) * RE(value) - IM(SELF) * IM(value);
-        FLOATVAL im = IM(SELF) * RE(value) + RE(SELF) * IM(value);
-        VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
-        RE(dest) = re;
-        IM(dest) = im;
+            FLOATVAL re = RE(SELF) * RE(value) - IM(SELF) * IM(value);
+            FLOATVAL im = IM(SELF) * RE(value) + RE(SELF) * IM(value);
+            if (dest)
+                VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
+            else {
+                dest = pmc_new(INTERP, SELF->vtable->base_type);
+            }
+            RE(dest) = re;
+            IM(dest) = im;
+            return dest;
         }
 MMD_DEFAULT: {
-        FLOATVAL re = RE(SELF) * VTABLE_get_number(INTERP, value);
-        FLOATVAL im = IM(SELF) * VTABLE_get_number(INTERP, value);
-        VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
-        RE(dest) = re;
-        IM(dest) = im;
+            FLOATVAL re = RE(SELF) * VTABLE_get_number(INTERP, value);
+            FLOATVAL im = IM(SELF) * VTABLE_get_number(INTERP, value);
+            if (dest)
+                VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
+            else {
+                dest = pmc_new(INTERP, SELF->vtable->base_type);
+            }
+            RE(dest) = re;
+            IM(dest) = im;
+            return dest;
         }
     }
 
-    void multiply_int (INTVAL value, PMC* dest) {
-        VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
+    PMC* multiply_int (INTVAL value, PMC* dest) {
+        if (dest)
+            VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
+        else {
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
+        }
         RE(dest) = RE(SELF) * value;
         IM(dest) = IM(SELF) * value;
+        return dest;
     }
 
-    void multiply_float (FLOATVAL value, PMC* dest) {
-        VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
+    PMC* multiply_float (FLOATVAL value, PMC* dest) {
+        if (dest)
+            VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
+        else {
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
+        }
         RE(dest) = RE(SELF) * value;
         IM(dest) = IM(SELF) * value;
+        return dest;
+    }
+
+    void i_multiply (PMC* value) {
+MMD_Complex: {
+            FLOATVAL re = RE(SELF) * RE(value) - IM(SELF) * IM(value);
+            FLOATVAL im = IM(SELF) * RE(value) + RE(SELF) * IM(value);
+            RE(SELF) = re;
+            IM(SELF) = im;
+        }
+MMD_DEFAULT: {
+            RE(SELF) *= VTABLE_get_number(INTERP, value);
+            IM(SELF) *= VTABLE_get_number(INTERP, value);
+        }
+    }
+
+    void i_multiply_int (INTVAL value) {
+        RE(SELF) *= value;
+        IM(SELF) *= value;
+    }
+
+    void i_multiply_float (FLOATVAL value) {
+        RE(SELF) *= value;
+        IM(SELF) *= value;
     }
 
 /*

Modified: trunk/classes/float.pmc
==============================================================================
--- trunk/classes/float.pmc     (original)
+++ trunk/classes/float.pmc     Fri Apr 15 08:38:47 2005
@@ -400,52 +400,66 @@
 
 /*
 
-=item C<void multiply(PMC *value, PMC *dest)>
+=item C<PMC* multiply(PMC *value, PMC *dest)>
 
-Multiplies the number by C<*value> and returns the result in C<*dest>.
+=item C<PMC* multiply_int(INTVAL value, PMC *dest)>
+
+=item C<PMC* multiply_float(FLOATVAL value, PMC *dest)>
+
+Multiplies the number by C<value> and returns the result in C<*dest>.
 
 =cut
 
 */
 
-    void multiply (PMC* value, PMC* dest) {
-MMD_Float: {
-        VTABLE_set_number_native(INTERP, dest,
-            PMC_num_val(SELF) * PMC_num_val(value));
+    PMC* multiply (PMC* value, PMC* dest) {
+MMD_Complex: {
+            internal_exception(1, "TODO mul<Float, Complex>");
+            return dest;
         }
 MMD_DEFAULT: {
-        VTABLE_set_number_native(INTERP, dest,
-            PMC_num_val(SELF) * VTABLE_get_number(INTERP, value));
-         }
+            if (!dest)
+                dest = pmc_new(INTERP, SELF->vtable->base_type);
+            VTABLE_set_number_native(INTERP, dest,
+                DYNSELF.get_number() * VTABLE_get_number(INTERP, value));
+            return dest;
+        }
     }
 
-/*
-
-=item C<void multiply_int(INTVAL value, PMC *dest)>
-
-Multiplies the number by C<value> and returns the result in C<*dest>.
-
-=cut
-
-*/
-
-    void multiply_int (INTVAL value, PMC* dest) {
+    PMC* multiply_int (INTVAL value, PMC* dest) {
+        if (!dest)
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
         VTABLE_set_number_native(INTERP, dest,
-            PMC_num_val(SELF) * value);
+            DYNSELF.get_number() * value);
+        return dest;
     }
-/*
 
-=item C<void multiply_float(FLOATVAL value, PMC *dest)>
-
-Multiplies the number by C<value> and returns the result in C<*dest>.
+    PMC* multiply_float (FLOATVAL value, PMC* dest) {
+        if (!dest)
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
+        VTABLE_set_number_native(INTERP, dest,
+            DYNSELF.get_number() * value);
+        return dest;
+    }
 
-=cut
+    void i_multiply (PMC* value) {
+MMD_Complex: {
+            internal_exception(1, "TODO i_mul<Float, Complex>");
+        }
+MMD_DEFAULT: {
+            VTABLE_set_number_native(INTERP, SELF,
+                DYNSELF.get_number() * VTABLE_get_number(INTERP, value));
+        }
+    }
 
-*/
+    void i_multiply_int (INTVAL value) {
+        VTABLE_set_number_native(INTERP, SELF,
+            DYNSELF.get_number() * (FLOATVAL)value);
+    }
 
-    void multiply_float (FLOATVAL value, PMC* dest) {
-        VTABLE_set_number_native(INTERP, dest,
-            PMC_num_val(SELF) * value);
+    void i_multiply_float (FLOATVAL value) {
+        VTABLE_set_number_native(INTERP, SELF,
+            DYNSELF.get_number() * value);
     }
 
 /*

Modified: trunk/classes/integer.pmc
==============================================================================
--- trunk/classes/integer.pmc   (original)
+++ trunk/classes/integer.pmc   Fri Apr 15 08:38:47 2005
@@ -25,7 +25,7 @@
 
 /* XXX create MMD headers to in Pmc2c.pm */
 extern INTVAL Parrot_BigInt_is_equal_BigInt(Interp*, PMC*, PMC*);
-extern void Parrot_BigInt_multiply_int(Interp* interpreter,
+extern PMC* Parrot_BigInt_multiply_int(Interp* interpreter,
         PMC* pmc, INTVAL value, PMC* dest) ;
 
 static PMC*
@@ -597,50 +597,114 @@
 
 /*
 
-=item C<void multiply(PMC *value, PMC *dest)>
+=item C<PMC* multiply(PMC *value, PMC *dest)>
+
+=item C<PMC* multiply_int(INTVAL value, PMC *dest)>
 
 Multiplies the integer by C<*value> and returns the result in C<*dest>.
 
 =cut
 
 */
-    void multiply (PMC* value, PMC* dest) {
+    PMC* multiply (PMC* value, PMC* dest) {
 MMD_Integer: {
-        INTVAL a = VTABLE_get_integer(INTERP, SELF);
-        INTVAL b = VTABLE_get_integer(INTERP, value);
-        double cf = (double)a * (double)b;
-        INTVAL c = a * b;
-        if ((double) c == cf)
-            VTABLE_set_integer_native(INTERP, dest, c);
-        else
-            overflow(INTERP, SELF, b, dest, MMD_MULTIPLY);
-    }
+            INTVAL a = VTABLE_get_integer(INTERP, SELF);
+            INTVAL b = VTABLE_get_integer(INTERP, value);
+            double cf = (double)a * (double)b;
+            INTVAL c = a * b;
+            if ((double) c == cf) {
+                if (!dest)
+                    dest = pmc_new(INTERP, SELF->vtable->base_type);
+                VTABLE_set_integer_native(INTERP, dest, c);
+                return dest;
+            }
+            else
+                return overflow(INTERP, SELF, b, dest, MMD_MULTIPLY);
+        }
+MMD_Complex: {
+                internal_exception(1, "TODO mul<Integer, Complex>");
+                return dest;
+            }
 MMD_BigInt:     {
-        Parrot_BigInt_multiply_int(INTERP, value, PMC_int_val(SELF), dest);
+            return Parrot_BigInt_multiply_int(INTERP, value,
+                    DYNSELF.get_integer(), dest);
         }
 MMD_String: {
+            return Parrot_Integer_multiply_Integer(INTERP, SELF, value, dest);
+        }
+MMD_DEFAULT: {
+            FLOATVAL valf = VTABLE_get_number(INTERP, value);
+            if (!dest)
+                dest = pmc_new(INTERP, SELF->vtable->base_type);
+            VTABLE_set_number_native(INTERP, dest, valf * PMC_int_val(SELF));
+            return dest;
+        }
+    }
+
+    PMC* multiply_int (INTVAL b, PMC* dest) {
         INTVAL a = PMC_int_val(SELF);
-        INTVAL b = VTABLE_get_integer(INTERP, value);
         double cf = (double)a * (double)b;
         INTVAL c = a * b;
-        if ((double) c == cf)
+        if ((double) c == cf) {
+            if (!dest)
+                dest = pmc_new(INTERP, SELF->vtable->base_type);
             VTABLE_set_integer_native(INTERP, dest, c);
+            return dest;
+        }
         else
-            overflow(INTERP, SELF, b, dest, MMD_MULTIPLY);
+            return overflow(INTERP, SELF, b, dest, MMD_MULTIPLY);
     }
 
-MMD_PerlUndef: {
-        VTABLE_set_integer_native(INTERP, dest, 0);
-    }
+/*
+
+=item C<void i_multiply(PMC *value)>
+
+=item C<void i_multiply_int(INTVAL value)>
+
+=item C<void i_multiply_float(FLOATVAL value)>
+
+Multiply C<value> with C<SELF> inplace.
+
+=cut
+
+*/
+
+    void i_multiply (PMC* value) {
+MMD_Integer: {
+            SELF.i_multiply_int(VTABLE_get_integer(INTERP, value));
+        }
+MMD_BigInt: {
+            Parrot_BigInt_multiply_int(INTERP, value,
+                    DYNSELF.get_integer(), SELF);
+        }
+MMD_Complex: {
+                internal_exception(1, "TODO i_mul<Integer, Complex>");
+        }
 MMD_DEFAULT: {
-        FLOATVAL valf = VTABLE_get_number(INTERP, value);
-        VTABLE_set_number_native(INTERP, dest, valf * PMC_int_val(SELF));
+        VTABLE_set_number_native(INTERP, SELF,
+            PMC_int_val(SELF) * VTABLE_get_number(INTERP, value));
+        }
     }
+
+    void i_multiply_int (INTVAL b) {
+        INTVAL a = PMC_int_val(SELF);
+        double cf = (double)a * (double)b;
+        INTVAL c = a * b;
+        if ((double) c == cf) {
+            DYNSELF.set_integer_native(c);
+        }
+        else
+            overflow(INTERP, SELF, b, SELF, MMD_MULTIPLY);
+    }
+
+    void i_multiply_float (FLOATVAL value) {
+        INTVAL a = DYNSELF.get_integer();
+        VTABLE_set_number_native(INTERP, SELF, a * value);
     }
 
+
 /*
 
-=item C<void multiply_int(INTVAL value, PMC *dest)>
 
 Multiplies the integer by C<value> and returns the result in C<*dest>.
 
@@ -667,15 +731,6 @@
 =cut
 
 */
-    void multiply_int (INTVAL b, PMC* dest) {
-        INTVAL a = PMC_int_val(SELF);
-        double cf = (double)a * (double)b;
-        INTVAL c = a * b;
-        if ((double) c == cf)
-            VTABLE_set_integer_native(INTERP, dest, c);
-        else
-            overflow(INTERP, SELF, b, dest, MMD_MULTIPLY);
-    }
 
 /*
 

Modified: trunk/classes/intlist.pmc
==============================================================================
--- trunk/classes/intlist.pmc   (original)
+++ trunk/classes/intlist.pmc   Fri Apr 15 08:38:47 2005
@@ -241,41 +241,6 @@
             PMC_int_val(key) = -1;
         return iter;
     }
-/*
-
-=item C<void multiply_int(INTVAL value,  PMC *dest)>
-
-Python (b6.main):
-
- # L = [1] * 1000000
-
-  4           0 LOAD_CONST               1 (1)
-              3 BUILD_LIST               1
-              6 LOAD_CONST               2 (1000000)
-              9 BINARY_MULTIPLY
-             10 STORE_FAST               2 (L)
-
-Build a list by duplicating the passed list N times. Only implemented for
-list.elements == 1.
-
-=cut
-
-*/
-
-    void multiply_int (INTVAL value,  PMC* dest) {
-        INTVAL k = DYNSELF.elements();
-        INTVAL i, elem;
-        IntList *l = PMC_struct_val(SELF);
-        List *n;
-        if (k != 1)
-            internal_exception(1, "multiply_int: unimplemented list size");
-        elem = intlist_get(INTERP, l, 0);
-        n = list_new(INTERP, enum_type_INTVAL);
-        PMC_struct_val(SELF) = n;
-        list_set_length(INTERP, n, value);
-        for (i = 0; i < value; ++i)
-            list_assign(INTERP, n, i, INTVAL2PTR(void *, elem), 
enum_type_INTVAL);
-    }
 
 }
 

Modified: trunk/classes/perlstring.pmc
==============================================================================
--- trunk/classes/perlstring.pmc        (original)
+++ trunk/classes/perlstring.pmc        Fri Apr 15 08:38:47 2005
@@ -150,7 +150,7 @@
 
 /*
 
-=item C<void multiply(PMC *value, PMC *dest)>
+=item C<PMC* multiply(PMC *value, PMC *dest)>
 
 Multiplies the string by C<*value> and returns the result in C<*dest>.
 
@@ -158,33 +158,13 @@
 
 */
 
-    void multiply (PMC* value, PMC* dest) {
-MMD_PerlString: {
-            /* work around MMD setup bug */
-            VTABLE_set_number_native(INTERP, dest,
-                    VTABLE_get_number(INTERP, SELF) *
-                    VTABLE_get_number(INTERP, value));
-        }
-MMD_PerlNum: {
-            VTABLE_set_number_native(INTERP, dest,
-                    VTABLE_get_number(INTERP, SELF) *
-                    PMC_num_val(value)
-                    );
-        }
-MMD_DEFAULT: {
-            FLOATVAL pmcf, valf;
-            INTVAL  pmci, vali;
-
-            pmcf = VTABLE_get_number(INTERP, SELF);
-            pmci = VTABLE_get_integer(INTERP, SELF);
-            valf = VTABLE_get_number(INTERP, value);
-            vali = VTABLE_get_integer(INTERP, value);
-
-            if (pmcf == pmci && valf == vali)
-                VTABLE_set_integer_native(INTERP, dest, pmci * vali);
-            else
-                VTABLE_set_number_native(INTERP, dest, pmcf * valf);
-        }
+    PMC* multiply (PMC* value, PMC* dest) {
+        if (!dest)
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
+         VTABLE_set_number_native(INTERP, dest,
+                 VTABLE_get_number(INTERP, SELF) *
+                 VTABLE_get_number(INTERP, value));
+         return dest;
     }
 
 /*

Modified: trunk/classes/perlundef.pmc
==============================================================================
--- trunk/classes/perlundef.pmc (original)
+++ trunk/classes/perlundef.pmc Fri Apr 15 08:38:47 2005
@@ -253,45 +253,45 @@
 
 /*
 
-=item C<void multiply(PMC *value, PMC *dest)>
+=item C<PMC* multiply(PMC *value, PMC *dest)>
 
 =cut
 
 */
 
-    void multiply (PMC* value,  PMC* dest) {
+    PMC* multiply (PMC* value,  PMC* dest) {
         Parrot_warn(INTERP, PARROT_WARNINGS_UNDEF_FLAG,
-        "Use of uninitialized value in multiplication");
-        VTABLE_set_integer_native(INTERP, dest, 0);
+                "Use of uninitialized value in multiplication");
+        return SUPER(value, dest);
     }
 
 /*
 
-=item C<void multiply_int(INTVAL value, PMC *dest)>
+=item C<PMC* multiply_int(INTVAL value, PMC *dest)>
 
 =cut
 
 */
 
-    void multiply_int (INTVAL value,  PMC* dest) {
+    PMC* multiply_int (INTVAL value,  PMC* dest) {
         Parrot_warn(INTERP, PARROT_WARNINGS_UNDEF_FLAG,
-        "Use of uninitialized value in integer multiplication");
-        VTABLE_set_integer_native(INTERP, dest, 0);
+                "Use of uninitialized value in integer multiplication");
+        return SUPER(value, dest);
     }
 
 
 /*
 
-=item C<void multiply_float(FLOATVAL value, PMC *dest)>
+=item C<PMC* multiply_float(FLOATVAL value, PMC *dest)>
 
 =cut
 
 */
 
-    void multiply_float (FLOATVAL value,  PMC* dest) {
+    PMC* multiply_float (FLOATVAL value,  PMC* dest) {
         Parrot_warn(INTERP, PARROT_WARNINGS_UNDEF_FLAG,
-        "Use of uninitialized value in numeric multiplication");
-        VTABLE_set_integer_native(INTERP, dest, 0);
+                "Use of uninitialized value in numeric multiplication");
+        return SUPER(value, dest);
     }
 
 /*

Modified: trunk/classes/resizablepmcarray.pmc
==============================================================================
--- trunk/classes/resizablepmcarray.pmc (original)
+++ trunk/classes/resizablepmcarray.pmc Fri Apr 15 08:38:47 2005
@@ -283,43 +283,6 @@
         }
         return 1;
     }
-/*
-
-=item C<void multiply_int(INTVAL value,  PMC *dest)>
-
-Python (b6.main):
-
- # L = [1] * 1000000
-
-  4           0 LOAD_CONST               1 (1)
-              3 BUILD_LIST               1
-              6 LOAD_CONST               2 (1000000)
-              9 BINARY_MULTIPLY
-             10 STORE_FAST               2 (L)
-
-Build a list by duplicating the passed list N times. Only implemented for
-list.elements == 1.
-
-=cut
-
-*/
-
-    void multiply_int (INTVAL value,  PMC* dest) {
-        INTVAL k = DYNSELF.elements();
-        INTVAL i;
-        PMC *elem;
-        PMC **data;
-
-        if (k != 1)
-            internal_exception(1, "multiply_int: unimplemented list size");
-        elem = VTABLE_get_pmc_keyed_int(INTERP, SELF, 0);
-        pmc_reuse(INTERP, dest, enum_class_ResizablePMCArray, 0);
-        VTABLE_set_integer_native(INTERP, dest, value);
-        data = PMC_data(dest);
-        for (i = 0; i < value; ++i)
-            data[i] = elem;
-    }
-
 
 }
 

Modified: trunk/classes/scalar.pmc
==============================================================================
--- trunk/classes/scalar.pmc    (original)
+++ trunk/classes/scalar.pmc    Fri Apr 15 08:38:47 2005
@@ -256,9 +256,7 @@
     PMC* subtract_float (FLOATVAL value,  PMC* dest) {
         FLOATVAL result;
 
-        result = DYNSELF.get_number()
-            - value;
-
+        result = DYNSELF.get_number() - value;
         if (!dest)
             dest = pmc_new(INTERP, SELF->vtable->base_type);
         VTABLE_set_number_native(INTERP, dest, result);
@@ -267,65 +265,62 @@
 
 /*
 
-=item C<void multiply (PMC* value,  PMC* dest)>
+=item C<PMC* multiply (PMC* value,  PMC* dest)>
 
 Multiplies the scalar by C<*value> and returns the result in C<*dest>.
 
-TODO - overflow detection, bigint promotion?
-
 =cut
 
 */
 
-    void multiply (PMC* value,  PMC* dest) {
+    PMC* multiply (PMC* value,  PMC* dest) {
         FLOATVAL result;
 
-        result = DYNSELF.get_number()
-            * VTABLE_get_number(INTERP, value);
-
+        result = DYNSELF.get_number() * VTABLE_get_number(INTERP, value);
+        if (!dest)
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
         VTABLE_set_number_native(INTERP, dest, result);
+        return dest;
     }
 
 /*
 
-=item C<void multiply_int(INTVAL value,  PMC *dest)>
+=item C<PMC* multiply_int(INTVAL value,  PMC *dest)>
 
 Multiplies the scalar by C<value> and returns the result in C<*dest>.
 
-TODO - overflow detection, bigint promotion?
-
 =cut
 
 */
 
-    void multiply_int (INTVAL value,  PMC* dest) {
+    PMC* multiply_int (INTVAL value,  PMC* dest) {
         FLOATVAL result;
 
-        result = DYNSELF.get_number()
-            * value;
-
+        result = DYNSELF.get_number() * value;
+        if (!dest)
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
         VTABLE_set_number_native(INTERP, dest, result);
+        return dest;
     }
 
 /*
 
-=item C<void multiply_float(FLOATVAL value, PMC *dest)>
+=item C<PMC* multiply_float(FLOATVAL value, PMC *dest)>
 
 Multiplies the scalar by C<value> and returns the result in C<*dest>.
 
-TODO - overflow detection, bigint promotion?
-
 =cut
 
 */
 
-    void multiply_float (FLOATVAL value,  PMC* dest) {
+    PMC* multiply_float (FLOATVAL value,  PMC* dest) {
         FLOATVAL result;
 
-        result = DYNSELF.get_number()
-            * value;
-
+        result = DYNSELF.get_number() * value;
         VTABLE_set_number_native(INTERP, dest, result);
+        if (!dest)
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
+        return dest;
     }
 
 /*

Modified: trunk/dynclasses/pyint.pmc
==============================================================================
--- trunk/dynclasses/pyint.pmc  (original)
+++ trunk/dynclasses/pyint.pmc  Fri Apr 15 08:38:47 2005
@@ -730,57 +730,6 @@
         VTABLE_set_integer_native(INTERP, dest, xmody);
     }
 
-/*
-
-=item C<void multiply(PMC *value, PMC *dest)>
-
-Multiplies C<*value> with the integer and returns the result in C<*dest>.
-
-=cut
-
-*/
-
-    void multiply (PMC* value, PMC* dest) {
-MMD_PyInt: {
-            INTVAL a = PMC_int_val(SELF);
-            INTVAL b = PMC_int_val(value);
-            double cf = (double)a * (double)b;
-            INTVAL c = a * b;
-            if ((double) c == cf)
-                VTABLE_set_integer_native(INTERP, dest, c);
-            else
-                overflow(INTERP, SELF, b, dest, MMD_MULTIPLY);
-        }
-MMD_PyLong: {
-            promote(INTERP, SELF, value, dest, MMD_MULTIPLY);
-        }
-MMD_PyFloat: {
-            INTVAL pmci = PMC_int_val(SELF);
-            FLOATVAL valf = VTABLE_get_number(INTERP, value);
-            /* XXX: Morph? */
-            VTABLE_set_number_native(INTERP, dest, pmci * valf);
-        }
-    }
-
-/*
-
-=item C<void multiply_int(INTVAL value, PMC *dest)>
-
-Multiplies C<*value> with the integer and returns the result in C<*dest>.
-
-=cut
-
-*/
-
-    void multiply_int (INTVAL b, PMC* dest) {
-        INTVAL a = PMC_int_val(SELF);
-        double cf = (double)a * (double)b;
-        INTVAL c = a * b;
-        if ((double) c == cf)
-            VTABLE_set_integer_native(INTERP, dest, c);
-        else
-            overflow(INTERP, SELF, b, dest, MMD_MULTIPLY);
-    }
 
 /*
 

Modified: trunk/dynclasses/pylist.pmc
==============================================================================
--- trunk/dynclasses/pylist.pmc (original)
+++ trunk/dynclasses/pylist.pmc Fri Apr 15 08:38:47 2005
@@ -32,13 +32,13 @@
 
     while (right > left) {
         INTVAL cursor = left;
-        INTVAL index = (left + right) / 2;
-        PMC *pivot = *(PMC**)list_get(interpreter, list, index, enum_type_PMC);
+        INTVAL idx = (left + right) / 2;
+        PMC *pivot = *(PMC**)list_get(interpreter, list, idx, enum_type_PMC);
         PMC *temp = *(PMC**)list_get(interpreter, list, right, enum_type_PMC);
-        list_assign(interpreter, list, index, temp, enum_type_PMC);
+        list_assign(interpreter, list, idx, temp, enum_type_PMC);
 
-        index = right;
-        while (cursor != index) {
+        idx = right;
+        while (cursor != idx) {
             INTVAL cmp;
             temp = *(PMC**)list_get(interpreter, list, cursor, enum_type_PMC);
 
@@ -61,18 +61,18 @@
             }
 
             if (cmp <= 0) {
-               if (cursor > index) {
-                   INTVAL swap = index;
-                   index = cursor;
+               if (cursor > idx) {
+                   INTVAL swap = idx;
+                   idx = cursor;
                    cursor = swap;
                    list_assign(interpreter, list, cursor, temp, enum_type_PMC);
                }
                cursor++;
             }
             else {
-               if (cursor < index) {
-                   INTVAL swap = index;
-                   index = cursor;
+               if (cursor < idx) {
+                   INTVAL swap = idx;
+                   idx = cursor;
                    cursor = swap;
                    list_assign(interpreter, list, cursor, temp, enum_type_PMC);
                }
@@ -80,15 +80,15 @@
             }
         }
 
-        list_assign(interpreter, list, index, pivot, enum_type_PMC);
+        list_assign(interpreter, list, idx, pivot, enum_type_PMC);
 
-        if (index*2 < left + right) {
-            quicksort(interpreter, list, cmpsub, left, index-1);
-            left = index+1;
+        if (idx*2 < left + right) {
+            quicksort(interpreter, list, cmpsub, left, idx-1);
+            left = idx+1;
         }
         else {
-            quicksort(interpreter, list, cmpsub, index+1, right);
-            right = index-1;
+            quicksort(interpreter, list, cmpsub, idx+1, right);
+            right = idx-1;
         }
     }
 }
@@ -143,7 +143,7 @@
 
 /*
 
-=item C<PMC* "__getitem__"(PMC *self, PMC *index)>
+=item C<PMC* "__getitem__"(PMC *self, PMC *idx)>
 
 Returns the PMC value of the element at index C<key>.
 
@@ -151,22 +151,22 @@
 
 */
 
-    METHOD PMC* __getitem__(PMC *self, PMC *index) {
-        return VTABLE_get_pmc_keyed(INTERP, self, index);
+    METHOD PMC* __getitem__(PMC *self, PMC *idx) {
+        return VTABLE_get_pmc_keyed(INTERP, self, idx);
     }
 
 /*
 
-=item C<PMC* "__setitem__"(PMC *self, PMC *index, PMC *value)>
+=item C<PMC* "__setitem__"(PMC *self, PMC *idx, PMC *value)>
 
-Sets the PMC at element C<index> to C<*value>.
+Sets the PMC at element C<idx> to C<*value>.
 
 =cut
 
 */
 
-    METHOD void __setitem__(PMC *self, PMC *index, PMC *value) {
-        VTABLE_set_pmc_keyed(INTERP, self, index, value);
+    METHOD void __setitem__(PMC *self, PMC *idx, PMC *value) {
+        VTABLE_set_pmc_keyed(INTERP, self, idx, value);
     }
 
 /*
@@ -255,9 +255,9 @@
         }
         else if (key->vtable->base_type == PyBuiltin_PyInt) {
             List *list = (List *)PMC_data(SELF);
-            INTVAL index = VTABLE_get_integer(INTERP, key);
-            if (index<0) index = VTABLE_elements(INTERP, SELF) + index;
-            list_delete(INTERP, list, index, 1);
+            INTVAL idx = VTABLE_get_integer(INTERP, key);
+            if (idx<0) idx = VTABLE_elements(INTERP, SELF) + idx;
+            list_delete(INTERP, list, idx, 1);
         }
         else
             SUPER(key);
@@ -478,7 +478,7 @@
 
 /*
 
-=item C<void multiply_int(INTVAL value,  PMC *dest)>
+=item C<PMC* multiply_int(INTVAL value,  PMC *dest)>
 
 Build a list by duplicating the passed list N times.
 
@@ -486,7 +486,7 @@
 
 */
 
-    void multiply_int (INTVAL value,  PMC* dest) {
+    PMC* multiply_int (INTVAL value,  PMC* dest) {
         INTVAL k = DYNSELF.elements();
         INTVAL i;
         PMC *elem;
@@ -494,7 +494,10 @@
 
         if (k == 1) {
             elem = VTABLE_get_pmc_keyed_int(INTERP, SELF, 0);
-            VTABLE_morph(INTERP, dest, PyBuiltin_PyList);
+            if (dest)
+                VTABLE_morph(INTERP, dest, PyBuiltin_PyList);
+            else
+                dest = pmc_new(INTERP, PyBuiltin_PyList);
             list = PMC_data(dest);
             list_set_length(INTERP, list, value);
             for (i = 0; i < value; ++i)
@@ -503,6 +506,7 @@
         else {
             internal_exception(1, "multiply_int: unimplemented list size");
         }
+        return dest;
     }
 
 /*
@@ -601,7 +605,8 @@
             INTVAL start = RVal_int(range->start);
             INTVAL end   = RVal_int(range->end);
 
-            list_splice(INTERP, list, value, start, end-start);
+            list_splice(INTERP, list, (List*)PMC_data(value),
+                    start, end-start);
         }
         else {
             INTVAL ix = key_integer(INTERP, key);

Modified: trunk/dynclasses/pylong.pmc
==============================================================================
--- trunk/dynclasses/pylong.pmc (original)
+++ trunk/dynclasses/pylong.pmc Fri Apr 15 08:38:47 2005
@@ -138,23 +138,6 @@
 
 /*
 
-=item C<void multiply(PMC *value, PMC *dest)>
-
-Multiplies C<*value> with the integer and returns the result in C<*dest>.
-
-=cut
-
-*/
-
-    void multiply (PMC* value, PMC* dest) {
-MMD_PyInt: {
-            INTVAL vali = VTABLE_get_integer(INTERP, value);
-            mmd_dispatch_v_pip(INTERP, SELF, vali, dest, MMD_MULTIPLY);
-        }
-    }
-
-/*
-
 =item C<INTVAL hash()>
 
 Returns a unique hash for this value

Modified: trunk/imcc/parser_util.c
==============================================================================
--- trunk/imcc/parser_util.c    (original)
+++ trunk/imcc/parser_util.c    Fri Apr 15 08:38:47 2005
@@ -365,6 +365,8 @@
         return MMD_ADD;
     if (strcmp(name, "sub") == 0)
         return MMD_SUBTRACT;
+    if (strcmp(name, "mul") == 0)
+        return MMD_MULTIPLY;
     return -1;
 }
 
@@ -398,7 +400,7 @@
     }
 
 
-#if 1
+#if 0
     ins = multi_keyed(interpreter, unit, name, r, n, keyvec, emit);
     if (ins)
         return ins;

Modified: trunk/imcc/t/syn/keyed.t
==============================================================================
--- trunk/imcc/t/syn/keyed.t    (original)
+++ trunk/imcc/t/syn/keyed.t    Fri Apr 15 08:38:47 2005
@@ -7,7 +7,7 @@
 
 ##############################
 SKIP: {
-  skipe("experimental", 1);
+  skip("experimental", 1);
 
 pir_output_is(<<'CODE', <<'OUTPUT', "add_keyed");
 .sub test @MAIN

Modified: trunk/t/pmc/intlist.t
==============================================================================
--- trunk/t/pmc/intlist.t       (original)
+++ trunk/t/pmc/intlist.t       Fri Apr 15 08:38:47 2005
@@ -16,7 +16,7 @@
 
 =cut
 
-use Parrot::Test tests => 11;
+use Parrot::Test tests => 10;
 use Test::More;
 
 output_is(<<'CODE', <<'OUTPUT', "creation");
@@ -520,22 +520,6 @@
 ok 2
 OUTPUT
 
-output_is(<<'CODE', <<'OUTPUT', "intlist mul = repeat");
-    new P0, .IntList
-    set P0[0], 1
-    mul P0, 100
-    set I0, P0
-    print I0
-    print "\n"
-    set I0, P0[99]
-    print I0
-    print "\n"
-    end
-CODE
-100
-1
-OUTPUT
-
 pir_output_is(<< 'CODE', << 'OUTPUT', "check whether interface is done");
 
 .sub _main

Modified: trunk/vtable.tbl
==============================================================================
--- trunk/vtable.tbl    (original)
+++ trunk/vtable.tbl    Fri Apr 15 08:38:47 2005
@@ -155,9 +155,13 @@
 void i_subtract_int(INTVAL value)           MMD_I_SUBTRACT_INT
 void i_subtract_float(FLOATVAL value)       MMD_I_SUBTRACT_FLOAT
 
-void multiply(PMC* value, PMC* dest)        MMD_MULTIPLY
-void multiply_int(INTVAL value, PMC* dest)  MMD_MULTIPLY_INT
-void multiply_float(FLOATVAL value, PMC* dest)  MMD_MULTIPLY_FLOAT
+PMC* multiply(PMC* value, PMC* dest)        MMD_MULTIPLY
+PMC* multiply_int(INTVAL value, PMC* dest)  MMD_MULTIPLY_INT
+PMC* multiply_float(FLOATVAL value, PMC* dest)  MMD_MULTIPLY_FLOAT
+
+void i_multiply(PMC* value)                 MMD_I_MULTIPLY
+void i_multiply_int(INTVAL value)           MMD_I_MULTIPLY_INT
+void i_multiply_float(FLOATVAL value)       MMD_I_MULTIPLY_FLOAT
 
 void divide(PMC* value, PMC* dest)           MMD_DIVIDE
 void divide_int(INTVAL value, PMC* dest)     MMD_DIVIDE_INT

Reply via email to