perl.cvs.parrot
[Top] [All Lists]

[svn:parrot] r35929 - trunk/src/pmc

Subject: [svn:parrot] r35929 - trunk/src/pmc
From:
Date: Fri, 23 Jan 2009 14:23:17 -0800 PST
Newsgroups: perl.cvs.parrot

Author: julianalbo
Date: Fri Jan 23 14:23:17 2009
New Revision: 35929

Modified:
   trunk/src/pmc/complex.pmc

Log:
implement Complex init_pmc

Modified: trunk/src/pmc/complex.pmc
==============================================================================
--- trunk/src/pmc/complex.pmc   (original)
+++ trunk/src/pmc/complex.pmc   Fri Jan 23 14:23:17 2009
@@ -326,8 +326,8 @@
 
 =item C<void init_pmc(PMC *initializer)>
 
-Initializes the complex number with the specified values.
-(not implemented)
+Initializes the complex number with the specified initializer.
+The initializer can be a string PMC or a numeric array with (real, imag)
 
 =item C<void destroy()>
 
@@ -351,8 +351,29 @@
     }
 
     VTABLE void init_pmc(PMC *initializer) {
-        /* XXX not implemented */
+        const INTVAL arg_type = VTABLE_type(interp, initializer);
         SELF.init();
+        switch (arg_type) {
+            case enum_class_String:
+                SELF.set_string_native(VTABLE_get_string(interp, initializer));
+                break;
+            case enum_class_FixedFloatArray:
+            case enum_class_ResizableFloatArray:
+            case enum_class_FixedIntegerArray:
+            case enum_class_ResizableIntegerArray:
+                if (VTABLE_get_integer(interp, initializer) == 2) {
+                    FLOATVAL re = VTABLE_get_number_keyed_int(interp, 
initializer, 0);
+                    FLOATVAL im = VTABLE_get_number_keyed_int(interp, 
initializer, 1);
+                    SET_ATTR_re(INTERP, SELF, re);
+                    SET_ATTR_im(INTERP, SELF, im);
+                   break;
+                }
+                /* else let it fall to default */
+            default:
+                Parrot_ex_throw_from_c_args(interp, NULL,
+                    EXCEPTION_INVALID_OPERATION,
+                    "Invalid Complex initializer");
+        }
     }
 
     VTABLE void destroy() {

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:parrot] r35929 - trunk/src/pmc, julianalbo <=