Author: allison
Date: Wed Oct  3 15:04:33 2007
New Revision: 21800

Modified:
   branches/pdd15oo/src/ops/pmc.ops
   branches/pdd15oo/src/pmc.c
   branches/pdd15oo/src/pmc/default.pmc

Log:
[pdd15oo] Allow high-level objects to be instantiated by type ID.


Modified: branches/pdd15oo/src/ops/pmc.ops
==============================================================================
--- branches/pdd15oo/src/ops/pmc.ops    (original)
+++ branches/pdd15oo/src/ops/pmc.ops    Wed Oct  3 15:04:33 2007
@@ -64,11 +64,12 @@
                    "Illegal PMC enum (%d) in new", (int)$2);
   }
 
-  /* Why?? If we're creating a continuation, the continuation PMC
-   * needs to be in the destination register before its init method
-   * copies the registers. */
+  /* Why separate init from pmc_new_noinit, instead of calling pmc_new? If
+   * we're creating a continuation, the continuation PMC needs to be in the
+   * destination register before its init method copies the registers. */
   $1 = pmc_new_noinit(interp, $2);
-  $1->vtable->init(interp, $1);
+  if ($2 <  enum_class_core_max)
+      $1->vtable->init(interp, $1);
   goto NEXT();
 }
 

Modified: branches/pdd15oo/src/pmc.c
==============================================================================
--- branches/pdd15oo/src/pmc.c  (original)
+++ branches/pdd15oo/src/pmc.c  Wed Oct  3 15:04:33 2007
@@ -62,8 +62,16 @@
 PMC *
 pmc_new(PARROT_INTERP, INTVAL base_type)
 {
-    PMC * const pmc = pmc_new_noinit(interp, base_type);
-    VTABLE_init(interp, pmc);
+    PMC *pmc;
+    if (base_type < enum_class_core_max) {
+        pmc = get_new_pmc_header(interp, base_type, 0);
+        VTABLE_init(interp, pmc);
+    }
+    else
+    {
+        PMC *classobj = interp->vtables[base_type]->pmc_class;
+        pmc = VTABLE_instantiate(interp, classobj, PMCNULL);
+    }
     return pmc;
 }
 
@@ -268,8 +276,14 @@
 PMC *
 pmc_new_noinit(PARROT_INTERP, INTVAL base_type)
 {
-    PMC * const pmc = get_new_pmc_header(interp, base_type, 0);
-
+    PMC *pmc;
+    if (base_type < enum_class_core_max)
+        pmc = get_new_pmc_header(interp, base_type, 0);
+    else
+    {
+        PMC *classobj = interp->vtables[base_type]->pmc_class;
+        pmc = VTABLE_instantiate(interp, classobj, PMCNULL);
+    }
     return pmc;
 }
 
@@ -329,10 +343,16 @@
 PMC *
 pmc_new_init(PARROT_INTERP, INTVAL base_type, NULLOK(PMC *init))
 {
-    PMC * const pmc = pmc_new_noinit(interp, base_type);
-
-    VTABLE_init_pmc(interp, pmc, init);
-
+    PMC *pmc;
+    if (base_type < enum_class_core_max) {
+        pmc = get_new_pmc_header(interp, base_type, 0);
+        VTABLE_init_pmc(interp, pmc, init);
+    }
+    else
+    {
+        PMC *classobj = interp->vtables[base_type]->pmc_class;
+        pmc = VTABLE_instantiate(interp, classobj, init);
+    }
     return pmc;
 }
 

Modified: branches/pdd15oo/src/pmc/default.pmc
==============================================================================
--- branches/pdd15oo/src/pmc/default.pmc        (original)
+++ branches/pdd15oo/src/pmc/default.pmc        Wed Oct  3 15:04:33 2007
@@ -314,6 +314,13 @@
 
     PMC *instantiate(PMC *init) {
         const INTVAL type = SELF->vtable->base_type;
+
+        /* Ensure no looping, as pmc_new calls the instantiate vtable entry for
+         * non-core types. */
+        if (type >= enum_class_core_max)
+            real_exception(interp, NULL, 1,
+                    "All high-level classes should override instantiate");
+
         if (!PMC_IS_NULL(init))
             return pmc_new_init(INTERP, type, init);
 

Reply via email to