Author: allison
Date: Sun Sep 30 20:33:03 2007
New Revision: 21698

Added:
   branches/pdd15oo/include/parrot/oo_private.h
Removed:
   branches/pdd15oo/src/pmc/classobject.h
Modified:
   branches/pdd15oo/include/parrot/oo.h
   branches/pdd15oo/include/parrot/pmc.h
   branches/pdd15oo/lib/Parrot/Pmc2c/PMC/Object.pm
   branches/pdd15oo/lib/Parrot/Pmc2c/PMCEmitter.pm
   branches/pdd15oo/src/gc/dod.c
   branches/pdd15oo/src/global_setup.c
   branches/pdd15oo/src/inter_misc.c
   branches/pdd15oo/src/oo.c
   branches/pdd15oo/src/ops/set.ops
   branches/pdd15oo/src/pmc.c
   branches/pdd15oo/src/pmc/class.pmc
   branches/pdd15oo/src/pmc/object.pmc
   branches/pdd15oo/src/pmc/pmcproxy.pmc

Log:
[pdd15oo] Sweeping changes to the implementation of PMCProxy, to make it work 
and to move it closer to PDD17.
- Moved the header definitions that are private to the OO subsystem into 
include/parrot/oo_private.h, following the coding standards. Deleted 
src/pmc/classobject.h.
- Eliminated the global store for PMCProxies, they only get stored in the 
namespace for the class. Deleted associated code for creating and managing the 
global store.
- Made PMCProxy and the Class PMC use the same core struct (they were nearly 
identical anyway).
- Refactored code for looking up vtable overrides to be more modular.
- Changed the default vtable functions generated for object.pmc, so they can 
actually make delegated calls.
- Changed the storage for PMCProxy's delegated instance to be an ordinary 
attribute named "proxy" that lives in the namespace of the proxied low-level 
PMC class. (This will go away when PDD17 is implemented, but works for now.)
- Added a few more useful characteristics to 'inspect'.


Modified: branches/pdd15oo/include/parrot/oo.h
==============================================================================
--- branches/pdd15oo/include/parrot/oo.h        (original)
+++ branches/pdd15oo/include/parrot/oo.h        Sun Sep 30 20:33:03 2007
@@ -19,6 +19,15 @@
 
 PARROT_CAN_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
+PMC * Parrot_oo_find_vtable_override_for_class(PARROT_INTERP,
+    NOTNULL(PMC *classobj),
+    NOTNULL(STRING *name))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3);
+
+PARROT_CAN_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
 PMC * Parrot_oo_get_class(PARROT_INTERP, NOTNULL(PMC *key))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);

Added: branches/pdd15oo/include/parrot/oo_private.h
==============================================================================
--- (empty file)
+++ branches/pdd15oo/include/parrot/oo_private.h        Sun Sep 30 20:33:03 2007
@@ -0,0 +1,65 @@
+/* oo_private.h
+ *  Copyright (C) 2007, The Perl Foundation.
+ *  SVN Info
+ *     $Id: oo.h 20040 2007-07-20 18:56:25Z petdance $
+ *  Overview:
+ *     Structs, typedefs and macros for the Class, Object, and PMCProxy PMCs.
+ *     This header file is only included by files within the OO subsystem.
+ *  Data Structure and Algorithms:
+ *  History:
+ *  Notes:
+ *  References:
+ */
+
+#ifndef PARROT_OO_PRIVATE_H_GUARD
+#define PARROT_OO_PRIVATE_H_GUARD
+
+#include "parrot/parrot.h"
+
+/* Class PMC's underlying struct. */
+typedef struct Parrot_Class {
+    int id;                /* The type number of the PMC. [To be deprecated] */
+    STRING *name;          /* The name of the class. */
+    PMC *_namespace;       /* The namespace it's linked to, if any. */
+    int instantiated;      /* Any instantiations since last modification? */
+    PMC *parents;          /* Immediate parent classes. */
+    PMC *all_parents;      /* Cached list of ourself and all parents, in MRO 
order. */
+    PMC *roles;            /* An array of roles. */
+    PMC *methods;          /* Hash of method names to methods in this class. */
+    PMC *vtable_overrides; /* Hash of Parrot v-table methods we override. */
+    PMC *attrib_metadata;  /* Hash of attributes in this class to hashes of 
metadata. */
+    PMC *attrib_index;     /* Lookup table for attributes in this and parents. 
*/
+    PMC *attrib_cache;     /* Cache of visible attrib names to indexes. */
+    PMC *resolve_method;   /* List of method names the class provides to 
resolve
+                            * conflicts with methods from roles. */
+} Parrot_Class;
+
+/* Macro to access underlying structure of a Class PMC. */
+#define PARROT_CLASS(o) ((Parrot_Class *) PMC_data(o))
+
+/* Object PMC's underlying struct. */
+typedef struct Parrot_Object {
+    PMC *_class;          /* The class this is an instance of. */
+    PMC *attrib_store;   /* The attributes store - a resizable PMC array. */
+} Parrot_Object;
+
+/* Macro to access underlying structure of an Object PMC. */
+#define PARROT_OBJECT(o) ((Parrot_Object *) PMC_data(o))
+
+/* Fully qualified class name generation; defined in Class, used by Object. */
+STRING* Parrot_Class_get_fq_classname(Parrot_Interp interp, Parrot_Class 
*class_info);
+
+/* We have a flag to mark if the class inherits from anything from a different
+ * class universe (for example, a PMC). */
+#define PObj_HasAlienParents_FLAG PObj_private0_FLAG
+#define PObj_HasAlienParents_TEST(o) PObj_flag_TEST(HasAlienParents, o)
+#define PObj_HasAlienParents_SET(o) PObj_flag_SET(HasAlienParents, o)
+
+#endif /* PARROT_OO_PRIVATE_H_GUARD */
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Modified: branches/pdd15oo/include/parrot/pmc.h
==============================================================================
--- branches/pdd15oo/include/parrot/pmc.h       (original)
+++ branches/pdd15oo/include/parrot/pmc.h       Sun Sep 30 20:33:03 2007
@@ -106,20 +106,6 @@
 
 /* &end_gen */
 
-/* This is the underlying structure for a PMC Proxy object; we need to set it
- * up from outside of the PMC. */
-typedef struct Parrot_PMCProxy {
-    int id;               /* The type number of the PMC. */
-    STRING *name;         /* The name of the PMC. */
-    PMC *_namespace;      /* The namespace it's linked to, if any. */
-    PMC *parents;         /* Proxy PMCs of any immediate parent classes. */
-    PMC *all_parents;     /* Cached list of ourself and all parents, in MRO 
order. */
-    PMC *methods;         /* PMC's non-vtable methods. Hash of method names to 
invokables. */
-} Parrot_PMCProxy;
-
-/* Macro to access underlying structure of a PMCProxy PMC. */
-#define PARROT_PMCPROXY(o) ((Parrot_PMCProxy *) PMC_data(o))
-
 #endif /* PARROT_PMC_H_GUARD */
 
 /*

Modified: branches/pdd15oo/lib/Parrot/Pmc2c/PMC/Object.pm
==============================================================================
--- branches/pdd15oo/lib/Parrot/Pmc2c/PMC/Object.pm     (original)
+++ branches/pdd15oo/lib/Parrot/Pmc2c/PMC/Object.pm     Sun Sep 30 20:33:03 2007
@@ -36,38 +36,41 @@
             $new_default_method->signature;
         my $void_return = $return_type_char eq 'v' ? 'return;' : '';
         my $return      = $return_type_char eq 'v' ? ''        : 
$return_prefix;
+        my $superargs   = $args;
+        $superargs      =~ s/^,//;
 
         $new_default_method->body( Parrot::Pmc2c::Emitter->text(<<"EOC") );
     Parrot_Object * const obj = PARROT_OBJECT(pmc);
     Parrot_Class * const _class = PARROT_CLASS(obj->_class);
+    STRING *meth_name = string_from_literal(interp, "$vt_method_name");
 
     /* Walk and search for the vtable method. */
     const int num_classes = VTABLE_elements(interp, _class->all_parents);
-    const int all_in_universe = !PObj_HasAlienParents_TEST(obj->_class);
-    const int alien_parents_pos = VTABLE_elements(interp, 
_class->attrib_metadata);
     int i;
     for (i = 0; i < num_classes; i++) {
         /* Get the class. */
         PMC * const cur_class = VTABLE_get_pmc_keyed_int(interp, 
_class->all_parents, i);
 
-        /* If it's from this universe or the class doesn't inherit from
-         * anything outside of it... */
-        if (all_in_universe || VTABLE_isa(interp, cur_class, 
string_from_literal(interp, "Class"))) {
-            const Parrot_Class * const class_info = PARROT_CLASS(cur_class);
-            if (VTABLE_exists_keyed_str(interp, class_info->vtable_overrides, 
string_from_literal(interp, "$vt_method_name"))) {
-                /* Found it; call. */
-                PMC * const meth = VTABLE_get_pmc_keyed_str(interp,
-                    class_info->vtable_overrides, string_from_literal(interp, 
"$vt_method_name"));
-                ${return}Parrot_run_meth_fromc_args$ret_suffix(interp, meth, 
pmc, string_from_literal(interp, "$vt_method_name"), "$sig"$args);
-                $void_return
-            }
+        PMC * const meth = Parrot_oo_find_vtable_override_for_class(interp, 
cur_class, meth_name);
+        if (!PMC_IS_NULL(meth)) {
+            ${return}Parrot_run_meth_fromc_args$ret_suffix(interp, meth, pmc, 
meth_name, "$sig"$args);
+            $void_return
         }
-        else {
+
+        if (VTABLE_type(interp, cur_class) == enum_class_PMCProxy) {
+            
             /* Get the PMC instance and call the vtable method on that. */
-            PMC * const del_class = VTABLE_get_pmc_keyed_int(interp, 
obj->attrib_store, alien_parents_pos);
-            ${return}VTABLE_$vt_method_name(interp, del_class$args);
+            PMC * const del_object = VTABLE_get_attr_keyed(interp, SELF,
+                cur_class, CONST_STRING(interp, "proxy"));
+
+            if (!PMC_IS_NULL(del_object)) {
+                ${return}VTABLE_$vt_method_name(interp, del_object$args); 
+                $void_return
+            }
+
         }
     }
+    SUPER($superargs);
     $null_return
 EOC
         $self->add_method($new_default_method);

Modified: branches/pdd15oo/lib/Parrot/Pmc2c/PMCEmitter.pm
==============================================================================
--- branches/pdd15oo/lib/Parrot/Pmc2c/PMCEmitter.pm     (original)
+++ branches/pdd15oo/lib/Parrot/Pmc2c/PMCEmitter.pm     Sun Sep 30 20:33:03 2007
@@ -585,8 +585,6 @@
     $cout .= <<"EOC";
         /* setup MRO and _namespace */
         Parrot_create_mro(interp, entry);
-        /* create PMC Proxy object */
-        Parrot_create_pmc_proxy(interp, entry);
 EOC
 
     # declare each nci method for this class

Modified: branches/pdd15oo/src/gc/dod.c
==============================================================================
--- branches/pdd15oo/src/gc/dod.c       (original)
+++ branches/pdd15oo/src/gc/dod.c       Sun Sep 30 20:33:03 2007
@@ -313,9 +313,6 @@
     /* Now mark the class hash */
     pobject_lives(interp, (PObj *)interp->class_hash);
 
-    /* Mark the PMC Proxy PMC array. */
-    pobject_lives(interp, (PObj *)interp->pmc_proxies);
-
     /* Mark the registry if any */
     if (interp->DOD_registry)
         pobject_lives(interp, (PObj *)interp->DOD_registry);

Modified: branches/pdd15oo/src/global_setup.c
==============================================================================
--- branches/pdd15oo/src/global_setup.c (original)
+++ branches/pdd15oo/src/global_setup.c Sun Sep 30 20:33:03 2007
@@ -156,14 +156,6 @@
     /* Call base vtable class constructor methods */
     Parrot_initialize_core_pmcs(interp);
 
-    /* We have a Proxy PMC for each of the PMCs; now need to attach that to
-     * the class slot for the namespace each of the PMCs reference. */
-    for (i = 0; i <= interp->n_vtable_max; i++)
-        if (interp->vtables[i])
-            Parrot_PCCINVOKE(interp, interp->vtables[i]->_namespace,
-                string_from_literal(interp, "set_class"), "P->",
-                VTABLE_get_pmc_keyed_int(interp, interp->pmc_proxies, i));
-
     iglobals = interp->iglobals;
     VTABLE_set_pmc_keyed_int(interp, iglobals,
             (INTVAL)IGLOBALS_CLASSNAME_HASH, interp->class_hash);
@@ -211,9 +203,6 @@
     interp->class_hash = classname_hash = pmc_new(interp, 
enum_class_NameSpace);
     Parrot_register_core_pmcs(interp, classname_hash);
 
-    /* Also a PMC array to store PMC Proxy objects. */
-    interp->pmc_proxies = pmc_new(interp, enum_class_ResizablePMCArray);
-
     /* init the interpreter globals array */
     iglobals         = pmc_new(interp, enum_class_SArray);
     interp->iglobals = iglobals;

Modified: branches/pdd15oo/src/inter_misc.c
==============================================================================
--- branches/pdd15oo/src/inter_misc.c   (original)
+++ branches/pdd15oo/src/inter_misc.c   Sun Sep 30 20:33:03 2007
@@ -58,12 +58,6 @@
     /* insert it into namespace */
     VTABLE_set_pmc_keyed_str(interp, interp->vtables[type]->_namespace,
             method_name, method);
-
-    /* Also need to list the method in the PMCProxy PMC's method list, so it
-     * can be introspected. */
-    proxy = VTABLE_get_pmc_keyed_int(interp, interp->pmc_proxies, type);
-    VTABLE_set_pmc_keyed_str(interp, PARROT_PMCPROXY(proxy)->methods,
-            method_name, method);
 }
 
 PARROT_API
@@ -82,12 +76,6 @@
     /* insert it into namespace */
     VTABLE_set_pmc_keyed_str(interp, interp->vtables[type]->_namespace,
             method_name, method);
-
-    /* Also need to list the method in the PMCProxy PMC's method list, so it
-     * can be introspected. */
-    proxy = VTABLE_get_pmc_keyed_int(interp, interp->pmc_proxies, type);
-    VTABLE_set_pmc_keyed_str(interp, PARROT_PMCPROXY(proxy)->methods,
-            method_name, method);
 }
 
 /*

Modified: branches/pdd15oo/src/oo.c
==============================================================================
--- branches/pdd15oo/src/oo.c   (original)
+++ branches/pdd15oo/src/oo.c   Sun Sep 30 20:33:03 2007
@@ -20,7 +20,7 @@
 
 #define PARROT_IN_OO_C
 #include "parrot/parrot.h"
-#include "parrot/oo.h"
+#include "parrot/oo_private.h"
 
 #include "oo.str"
 
@@ -117,13 +117,33 @@
     return classobj;
 }
 
+PARROT_CAN_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+PMC *
+Parrot_oo_find_vtable_override_for_class(PARROT_INTERP, NOTNULL(PMC 
*classobj), NOTNULL(STRING *name))
+{
+    if (VTABLE_isa(interp, classobj, string_from_literal(interp, "Class"))) {
+        Parrot_Class * const class_info = PARROT_CLASS(classobj);
+        if (VTABLE_exists_keyed_str(interp, class_info->vtable_overrides,
+                name)) {
+            /* Found it. */
+            PMC * const meth = VTABLE_get_pmc_keyed_str(interp,
+                class_info->vtable_overrides, name);
+            return meth;
+        }
+    }
+
+    return PMCNULL;
+}
+
 /*
 
 =back
 
 =head1 SEE ALSO
 
-F<include/parrot/objects.h>, F<docs/pdds/pdd15_objects.pod>.
+F<include/parrot/oo.h>, F<include/parrot/oo_private.h>,
+F<docs/pdds/pdd15_objects.pod>.
 
 =cut
 

Modified: branches/pdd15oo/src/ops/set.ops
==============================================================================
--- branches/pdd15oo/src/ops/set.ops    (original)
+++ branches/pdd15oo/src/ops/set.ops    Sun Sep 30 20:33:03 2007
@@ -157,7 +157,7 @@
 }
 
 inline op set(out STR, invar PMC) :base_core {
-  $1 = $2->vtable->get_string(interp, $2);
+  $1 = VTABLE_get_string(interp, $2);
   goto NEXT();
 }
 

Modified: branches/pdd15oo/src/pmc.c
==============================================================================
--- branches/pdd15oo/src/pmc.c  (original)
+++ branches/pdd15oo/src/pmc.c  Sun Sep 30 20:33:03 2007
@@ -595,50 +595,6 @@
 }
 
 
-/*
-
-=back
-
-=head2 PMC Proxy related things
-
-=over 4
-
-=item C<Parrot_create_pmc_proxy>
-
-Creates a PMC Proxy for the supplied class number and puts it into the array
-of proxies.
-
-=cut
-
-*/
-
-PARROT_API
-void
-Parrot_create_pmc_proxy(PARROT_INTERP, int type_num)
-{
-    PMC *proxy;
-    Parrot_PMCProxy *proxy_info;
-
-    /* Ensure that it's a valid type number. */
-    if (type_num > interp->n_vtable_max || type_num < 0) {
-        real_exception(interp, NULL, 1,
-            "Attempt to create PMC Proxy for invalid type number!");
-    }
-
-    /* Create PMC proxy object and set up number, name and namespcae. */
-    proxy = pmc_new(interp, enum_class_PMCProxy);
-    proxy_info = PARROT_PMCPROXY(proxy);
-    proxy_info->id = type_num;
-    proxy_info->name = interp->vtables[type_num]->whoami;
-    proxy_info->_namespace = interp->vtables[type_num]->_namespace;
-
-    /* XXX Parents and MRO still todo. */
-
-    /* Enter it in the list of proxy objects. */
-    VTABLE_set_pmc_keyed_int(interp, interp->pmc_proxies, type_num, proxy);
-}
-
-
 
 /*
 

Modified: branches/pdd15oo/src/pmc/class.pmc
==============================================================================
--- branches/pdd15oo/src/pmc/class.pmc  (original)
+++ branches/pdd15oo/src/pmc/class.pmc  Sun Sep 30 20:33:03 2007
@@ -86,8 +86,8 @@
 
 #define PARROT_IN_OBJECTS_C /* To get the vtable.h imports we want. */
 #include "parrot/parrot.h"
+#include "parrot/oo_private.h"
 #include "pmc_namespace.h"
-#include "classobject.h"
 
 /* This function builds the attribute index (table to map class name and
  * attribute name to an index) for the current class. */
@@ -97,21 +97,20 @@
     Parrot_Class * const _class      = PARROT_CLASS(self);
     int                  cur_index   = 0;
     PMC * const          table       = pmc_new(interp, enum_class_Hash);
-    STRING       * const class_str   = string_from_cstring(interp, "Class", 5);
     const int            num_classes =
         VTABLE_elements(interp, _class->all_parents);
     int                  i;
 
     /* We will go over the list of all parents to construct the table. */
     for (i = 0; i < num_classes; i++) {
-       /* Get the class and check it's from this class universe (if not we
-        * don't know how it stores its attributes, so we'll have to delegate
-        * the lookup). */
+       /* Get the class and check that it respects the standard class interface
+        * (if not we don't know how it stores its attributes, so we'll have to
+        * delegate the lookup). */
         PMC *cur_class = VTABLE_get_pmc_keyed_int(interp, _class->all_parents,
             i);
 
-        if (VTABLE_isa(interp, cur_class, class_str)) {
-            /* The the attribute metadata hash. */
+        if (PObj_is_class_TEST(cur_class)) {
+            /* The attribute metadata hash. */
             Parrot_Class *class_info = PARROT_CLASS(cur_class);
             PMC          *attribs    = class_info->attrib_metadata;
             PMC          *iter       = VTABLE_get_iter(interp, attribs);
@@ -404,39 +403,12 @@
 }
 
 static PMC *
-get_vtable_override_for_class(PARROT_INTERP, PMC *classobj, STRING *name)
-{
-    if (VTABLE_isa(interp, classobj,
-            string_from_literal(interp, "Class"))) {
-        const Parrot_Class * const class_info = PARROT_CLASS(classobj);
-        if (VTABLE_exists_keyed_str(interp, class_info->vtable_overrides,
-                name)) {
-            /* Found it. */
-            PMC * const meth = VTABLE_get_pmc_keyed_str(interp,
-                class_info->vtable_overrides, name);
-            return meth;
-        }
-    }
-    /* This is the case where a class is of a type other than Class,
-     * but PMCProxy doesn't handle vtable overrides correctly yet. Will
-     * have to come back and add it later. */
-
-    return PMCNULL;
-}
-
-static PMC *
 find_vtable_override(PARROT_INTERP, PMC *parrot_class, STRING *name)
 {
     Parrot_Class * const _class = PARROT_CLASS(parrot_class);
 
     /* Walk and search for the vtable method. */
     const int num_classes       = VTABLE_elements(interp, _class->all_parents);
-    const int all_in_universe   = !PObj_HasAlienParents_TEST(parrot_class);
-    /* xxx this isn't used yet
-    const int alien_parents_pos = VTABLE_elements(interp,
-        _class->attrib_metadata);
-    */
-
     int i;
 
     for (i = 0; i < num_classes; i++) {
@@ -444,7 +416,7 @@
         PMC * const cur_class =
             VTABLE_get_pmc_keyed_int(interp, _class->all_parents, i);
 
-        PMC * const meth = get_vtable_override_for_class(interp, cur_class, 
name);
+        PMC * const meth = Parrot_oo_find_vtable_override_for_class(interp, 
cur_class, name);
         if (!PMC_IS_NULL(meth))
             return meth;
     }
@@ -452,17 +424,25 @@
 }
 
 static void
-initialize_parents(PARROT_INTERP, PMC *all_parents, PMC *object)
+initialize_parents(PARROT_INTERP, PMC *object, PMC *all_parents)
 {
-    INTVAL parent_index  = VTABLE_elements(interp, all_parents) - 1;
+    INTVAL  parent_index = VTABLE_elements(interp, all_parents) - 1;
     STRING *name         = string_from_literal(interp, "init");
 
     /* Loop through the parents in reverse MRO order. */
     for (; parent_index >= 0; parent_index--) {
+        PMC *meth;
         PMC * const parent = VTABLE_get_pmc_keyed_int(interp,
             all_parents, parent_index);
 
-        PMC *meth = get_vtable_override_for_class(interp, parent, name);
+        /* PMCProxy parents store an instance to delegate to */
+        if (VTABLE_type(interp, parent) == enum_class_PMCProxy) {
+            PMC * proxy = VTABLE_instantiate(interp, parent, PMCNULL);
+            VTABLE_set_attr_keyed(interp, object, parent,
+                    string_from_literal(interp, "proxy"), proxy);
+        }
+
+        meth = Parrot_oo_find_vtable_override_for_class(interp, parent, name);
         if (!PMC_IS_NULL(meth)) {
             Parrot_run_meth_fromc_args(interp, meth,
                     object, name, "v");
@@ -471,17 +451,25 @@
 }
 
 static void
-initialize_parents_pmc(PARROT_INTERP, PMC *all_parents, PMC *object, PMC *init)
+initialize_parents_pmc(PARROT_INTERP, PMC *object, PMC *all_parents, PMC *init)
 {
-    INTVAL parent_index = VTABLE_elements(interp, all_parents) - 1;
-    STRING *name        = string_from_literal(interp, "init_pmc");
+    INTVAL  parent_index = VTABLE_elements(interp, all_parents) - 1;
+    STRING *name         = string_from_literal(interp, "init_pmc");
 
     /* Loop through the parents in reverse MRO order. */
     for (; parent_index >= 0; parent_index--) {
+        PMC *meth;
         PMC * const parent = VTABLE_get_pmc_keyed_int(interp,
             all_parents, parent_index);
 
-        PMC *meth = get_vtable_override_for_class(interp, parent, name);
+        /* PMCProxy parents store an instance to delegate to */
+        if (VTABLE_type(interp, parent) == enum_class_PMCProxy) {
+            PMC * proxy = VTABLE_instantiate(interp, parent, init);
+            VTABLE_set_attr_keyed(interp, object, parent,
+                    string_from_literal(interp, "proxy"), proxy);
+        }
+
+        meth = Parrot_oo_find_vtable_override_for_class(interp, parent, name);
         if (!PMC_IS_NULL(meth)) {
             Parrot_run_meth_fromc_args(interp, meth,
                     object, name, "vP", init);
@@ -920,6 +908,9 @@
         else if (string_equal(interp, what, CONST_STRING(interp, 
"attributes")) == 0) {
             found = _class->attrib_metadata;
         }
+        else if (string_equal(interp, what, CONST_STRING(interp, 
"attrib_index")) == 0) {
+            found = _class->attrib_index;
+        }
         else if (string_equal(interp, what, CONST_STRING(interp, "methods")) 
== 0) {
             found = _class->methods;
         }
@@ -1170,9 +1161,9 @@
         /* Check for overrides on the init or init_pmc vtable function and call
          * them if they exist */
         if (PMC_IS_NULL(init)) 
-            initialize_parents(interp, _class->all_parents, object);
+            initialize_parents(interp, object, _class->all_parents);
         else 
-            initialize_parents_pmc(interp, _class->all_parents, object, init);
+            initialize_parents_pmc(interp, object, _class->all_parents, init);
 
         return object;
     }

Modified: branches/pdd15oo/src/pmc/object.pmc
==============================================================================
--- branches/pdd15oo/src/pmc/object.pmc (original)
+++ branches/pdd15oo/src/pmc/object.pmc Sun Sep 30 20:33:03 2007
@@ -19,7 +19,7 @@
 */
 
 #include "parrot/parrot.h"
-#include "classobject.h"
+#include "parrot/oo_private.h"
 
 /* This finds the index of an attribute in an object's attribute store and
  * returns it. Returns -1 if the attribute does not exist. */

Modified: branches/pdd15oo/src/pmc/pmcproxy.pmc
==============================================================================
--- branches/pdd15oo/src/pmc/pmcproxy.pmc       (original)
+++ branches/pdd15oo/src/pmc/pmcproxy.pmc       Sun Sep 30 20:33:03 2007
@@ -15,7 +15,7 @@
 
 =head2 Structure
 
-This class stores its state in the Parrot_PMCProxy structure, which has the
+This class stores its state in the Parrot_Class structure, using the
 following fields.
 
 =over 4
@@ -50,6 +50,7 @@
 */
 
 #include "parrot/parrot.h"
+#include "parrot/oo_private.h"
 
 /*
 
@@ -75,7 +76,9 @@
 */
 
     void init() {
-        Parrot_PMCProxy *_pmc = mem_allocate_zeroed_typed(Parrot_PMCProxy);
+        Parrot_Class *_pmc = mem_allocate_zeroed_typed(Parrot_Class);
+        PMC * const new_attribute = pmc_new(interp, enum_class_Hash);
+        STRING *name = CONST_STRING(interp, "proxy");
         PMC_data(SELF)        = _pmc;
 
         /* Set flags for custom DOD mark and destroy. */
@@ -89,6 +92,15 @@
         _pmc->parents         = pmc_new(interp, enum_class_ResizablePMCArray);
         _pmc->all_parents     = pmc_new(interp, enum_class_ResizablePMCArray);
         _pmc->methods         = pmc_new(interp, enum_class_Hash);
+        _pmc->attrib_metadata = pmc_new(interp, enum_class_Hash);
+        _pmc->attrib_index    = PMCNULL;
+        _pmc->attrib_cache    = PMCNULL;
+
+        /* Set up the attribute storage for the proxy instance */
+        VTABLE_set_string_keyed_str(interp, new_attribute,
+                CONST_STRING(interp, "name"), name);
+        VTABLE_set_pmc_keyed_str(interp, _pmc->attrib_metadata,
+                name, new_attribute);
 
         /* We put ourself on the all parents list. */
         VTABLE_push_pmc(interp, _pmc->all_parents, SELF);
@@ -99,7 +111,7 @@
 
     void init_pmc(PMC *init_data) {
         INTVAL type_num = VTABLE_get_integer(interp, init_data);
-        Parrot_PMCProxy *proxy_info;
+        Parrot_Class *proxy_info;
 
         /* Ensure that it's a valid type number. */
         if (type_num > interp->n_vtable_max || type_num < 0) {
@@ -111,17 +123,15 @@
         SELF.init();
 
         /* Set up number, name and namespace. */
-        proxy_info = PARROT_PMCPROXY(SELF);
+        proxy_info = PARROT_CLASS(SELF);
         proxy_info->id = type_num;
         proxy_info->name = interp->vtables[type_num]->whoami;
         proxy_info->_namespace = interp->vtables[type_num]->_namespace;
 
         /* XXX Parents and MRO still todo. */
 
-        /* Enter it in the list of proxy objects. */
-        VTABLE_set_pmc_keyed_int(interp, interp->pmc_proxies, type_num, SELF);
-
-        /* Link namespace to this class, if there is one. */
+        /* Link the proxy and the namespace, caching the proxy object for later
+         * retrieval on class lookup. */
         if (!PMC_IS_NULL(proxy_info->_namespace))
             Parrot_PCCINVOKE(interp, proxy_info->_namespace,
                 string_from_literal(interp, "set_class"), "P->", SELF);
@@ -137,7 +147,7 @@
 
 */
     PMC *instantiate(PMC *init) {
-        Parrot_PMCProxy *_pmc = PARROT_PMCPROXY(SELF);
+        Parrot_Class *_pmc = PARROT_CLASS(SELF);
 
         if (!PMC_IS_NULL(init))
             return pmc_new_init(interp, _pmc->id, init);
@@ -170,7 +180,7 @@
 */
 
     void mark() {
-        Parrot_PMCProxy * const _pmc = PARROT_PMCPROXY(SELF);
+        Parrot_Class * const _pmc = PARROT_CLASS(SELF);
 
         if (_pmc->name)
             pobject_lives(interp, (PObj*)_pmc->name);
@@ -180,8 +190,20 @@
             pobject_lives(interp, (PObj*)_pmc->parents);
         if (_pmc->all_parents)
             pobject_lives(interp, (PObj*)_pmc->all_parents);
+        if (_pmc->roles)
+            pobject_lives(interp, (PObj*)_pmc->roles);
         if (_pmc->methods)
             pobject_lives(interp, (PObj*)_pmc->methods);
+        if (_pmc->vtable_overrides)
+            pobject_lives(interp, (PObj*)_pmc->vtable_overrides);
+        if (_pmc->attrib_metadata)
+            pobject_lives(interp, (PObj*)_pmc->attrib_metadata);
+        if (_pmc->attrib_index)
+            pobject_lives(interp, (PObj*)_pmc->attrib_index);
+        if (_pmc->attrib_cache)
+            pobject_lives(interp, (PObj*)_pmc->attrib_cache);
+        if (_pmc->resolve_method)
+            pobject_lives(interp, (PObj*)_pmc->resolve_method);
     }
 
 /*
@@ -195,7 +217,7 @@
 */
 
     INTVAL isa_pmc(PMC *lookup) {
-        Parrot_PMCProxy * const _proxy = PARROT_PMCPROXY(SELF);
+        Parrot_Class * const _proxy = PARROT_CLASS(SELF);
         INTVAL        i, num_classes;
         STRING       *classname;
         PMC          *classobj = PMCNULL;
@@ -270,7 +292,7 @@
 */
     PMC *inspect_str(STRING *what)
     {
-        Parrot_PMCProxy *_pmc = PARROT_PMCPROXY(SELF);
+        Parrot_Class *_pmc = PARROT_CLASS(SELF);
 
         /* What should we return? */
         PMC          *found   = PMCNULL;
@@ -283,6 +305,9 @@
             /* Should not clone this. */
             return _pmc->_namespace;
         }
+        else if (string_equal(interp, what, CONST_STRING(interp, 
"attributes")) == 0) {
+            found = _pmc->attrib_metadata;
+        }
         else if (string_equal(interp, what, CONST_STRING(interp, "methods")) 
== 0) {
             found = _pmc->methods;
         }
@@ -334,7 +359,7 @@
 
 */
     PCCMETHOD name() {
-        Parrot_PMCProxy *_pmc     = PARROT_PMCPROXY(SELF);
+        Parrot_Class *_pmc     = PARROT_CLASS(SELF);
         STRING          *ret_name = _pmc->name;
         PCCRETURN(STRING *ret_name);
     }
@@ -349,7 +374,7 @@
 
 */
     PCCMETHOD pmc_namespace() {
-        Parrot_PMCProxy *_pmc          = PARROT_PMCPROXY(SELF);
+        Parrot_Class *_pmc          = PARROT_CLASS(SELF);
         PMC             *ret_namespace = _pmc->_namespace;
         PCCRETURN(PMC *ret_namespace);
     }
@@ -430,7 +455,7 @@
 */
 
     STRING *get_string() {
-        Parrot_PMCProxy * const proxy_info = PARROT_PMCPROXY(SELF);
+        Parrot_Class * const proxy_info = PARROT_CLASS(SELF);
 
         /* Copy the stored string name of the proxy. */
         return string_copy(interp, proxy_info->name);

Reply via email to