Author: leo
Date: Thu Mar  9 14:01:37 2006
New Revision: 11840

Modified:
   trunk/src/objects.c
   trunk/src/ops/object.ops
   trunk/src/pmc/parrotclass.pmc

Log:
OO - refactor class creation

* the newclass opcode used to call Parrot_new_class directly, which prevents
  any flexibility
* now VTABLE_init_pmc() is called (with the class_name STRING as argument),
  so that class creation can be overloaded              


Modified: trunk/src/objects.c
==============================================================================
--- trunk/src/objects.c (original)
+++ trunk/src/objects.c Thu Mar  9 14:01:37 2006
@@ -273,9 +273,8 @@
      * ParrotClass is the baseclass anyway, so build just a new class
      */
     if (base_class == Parrot_base_vtables[enum_class_ParrotClass]->class) {
-        PMC* class = pmc_new(interpreter, enum_class_ParrotClass);
-        Parrot_new_class(interpreter, class, child_class_name);
-        return class;
+        return pmc_new_init(interpreter, enum_class_ParrotClass, 
+                (PMC*)child_class_name);
     }
     parent_is_class = PObj_is_class_TEST(base_class);
 

Modified: trunk/src/ops/object.ops
==============================================================================
--- trunk/src/ops/object.ops    (original)
+++ trunk/src/ops/object.ops    Thu Mar  9 14:01:37 2006
@@ -217,8 +217,7 @@
 =cut
 
 inline op newclass(out PMC, in STR) :object_classes {
-  PMC* class = $1 = pmc_new(interpreter, enum_class_ParrotClass);
-  Parrot_new_class(interpreter, class, $2);
+  $1 = pmc_new_init(interpreter, enum_class_ParrotClass, (PMC*)$2);
   goto NEXT();
 }
 

Modified: trunk/src/pmc/parrotclass.pmc
==============================================================================
--- trunk/src/pmc/parrotclass.pmc       (original)
+++ trunk/src/pmc/parrotclass.pmc       Thu Mar  9 14:01:37 2006
@@ -62,7 +62,12 @@
 
 =item C<void init()>
 
-Initializes the class.
+Initializes the class flags.
+
+=item C<void init_pms(PMC *init)>
+
+The actual class creation code, called from C<newclass> opcode. The C<init>
+argument is not a PMC* but the C<classname> STRING.
 
 =cut
 
@@ -73,8 +78,15 @@
         PMC_int_val(SELF) = ATTRIB_COUNT(SELF) = 0;
         /* But we are a class, really */
         PObj_is_class_SET(SELF);
+        /* turn on marking of the class_data array */
         PObj_data_is_PMC_array_SET(SELF);
-        /* s. Parrot_new_class() for more initialization */
+    }
+
+    void init_pmc (PMC* name) {
+        STRING *class_name = (STRING*) name;
+
+        SELF.init();
+        Parrot_new_class(INTERP, SELF, class_name);
     }
 
 /*
@@ -225,8 +237,7 @@
             }
             else {
                 real_class = SELF;
-                SELF.init();
-                Parrot_new_class(INTERP, SELF, class_name);
+                SELF.init_pmc((PMC*)class_name);
             }
             /* make room for thawed arrays */
             if (PMC_int_val(real_class) == PCD_MAX) {

Reply via email to