I've done some work in this problem. The attached patch is a way to make
the examples work but I think this is not the way to go, or a lot of
functions in a lot of pmc will need changes.

Index: src/pmc/complex.pmc
===================================================================
--- src/pmc/complex.pmc	(revision 31697)
+++ src/pmc/complex.pmc	(working copy)
@@ -758,14 +758,21 @@
 */
 
     MULTI PMC *subtract(Complex value, PMC *dest) {
-        if (dest)
-            VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
+        if (dest) {
+	    if(! VTABLE_isa(INTERP, dest, CONST_STRING(INTERP, 'Complex')))
+                VTABLE_morph(INTERP, dest, SELF->vtable->base_type);
+        }
         else
-            dest = pmc_new(INTERP, SELF->vtable->base_type);
+            dest = VTABLE_clone(INTERP, SELF);
 
-        RE(dest) = RE(SELF) - RE(value);
-        IM(dest) = IM(SELF) - IM(value);
-
+        {
+            FLOATVAL re1 = VTABLE_get_number_keyed_int(INTERP, SELF, 0);
+            FLOATVAL im1 = VTABLE_get_number_keyed_int(INTERP, SELF, 1);
+            FLOATVAL re2 = VTABLE_get_number_keyed_int(INTERP, value, 0);
+            FLOATVAL im2 = VTABLE_get_number_keyed_int(INTERP, value, 1);
+            VTABLE_set_number_keyed_int(INTERP, dest, 0, re1 - re2);
+            VTABLE_set_number_keyed_int(INTERP, dest, 1, im1 - im2);
+        }
         return dest;
     }
 

Reply via email to