[svn:parrot] r35704 - in trunk/src: . pmc

[email protected]
Newsgroups perl.cvs.parrot
Message-ID <[email protected]>
Author: Whiteknight
Date: Sat Jan 17 10:31:00 2009
New Revision: 35704

Modified:
   trunk/src/oo.c
   trunk/src/pmc.c
   trunk/src/pmc/namespace.pmc

Log:
[get_class] a few cleanups with the get_class stuff

Modified: trunk/src/oo.c
==============================================================================
--- trunk/src/oo.c	(original)
+++ trunk/src/oo.c	Sat Jan 17 10:31:00 2009
@@ -200,7 +200,6 @@
             case enum_class_NameSpace:
                 classobj = VTABLE_get_class(interp, key);
                 break;
-
             case enum_class_String:
             case enum_class_Key:
             case enum_class_ResizableStringArray:
@@ -219,28 +218,19 @@
         }
     }
 
+    /* If the PMCProxy doesn't exist yet for the given key, we look up the
+       type ID here and create a new one */
     if (PMC_IS_NULL(classobj)) {
         /* Look up a low-level class and create a proxy */
-        INTVAL type;
-        const INTVAL base_type = key->vtable->base_type;
-
-        /* XXX TT#182: This is a hack! We should be able to treat all
-           PMC types the same through pmc_type_p or some interface to it */
-        if (base_type == enum_class_Key
-         || base_type == enum_class_ResizableStringArray
-         || base_type == enum_class_String
-         || base_type == enum_class_NameSpace)
-            type = pmc_type_p(interp, key);
-        else
-            type = pmc_type(interp, VTABLE_get_string(interp, key));
+        const INTVAL type = pmc_type_p(interp, key);
 
         /* Reject invalid type numbers */
         if (type > interp->n_vtable_max || type <= 0)
-            return PMCNULL;
+            classobj = PMCNULL;
         else {
-             PMC * const type_num = pmc_new(interp, enum_class_Integer);
-             VTABLE_set_integer_native(interp, type_num, type);
-             classobj = pmc_new_init(interp, enum_class_PMCProxy, type_num);
+            PMC * const type_num = pmc_new(interp, enum_class_Integer);
+            VTABLE_set_integer_native(interp, type_num, type);
+            classobj = pmc_new_init(interp, enum_class_PMCProxy, type_num);
         }
     }
 

Modified: trunk/src/pmc.c
==============================================================================
--- trunk/src/pmc.c	(original)
+++ trunk/src/pmc.c	Sat Jan 17 10:31:00 2009
@@ -620,17 +620,25 @@
     PMC * item;
 
     if (name->vtable->base_type == enum_class_NameSpace) {
+        /* We need to convert the NameSpace to a ResizableStringArray. The
+           get_name method does this for now, but eventually we should be
+           able to do a morph VTABLE call instead */
         Parrot_PCCINVOKE(interp, name, CONST_STRING(interp, "get_name"), "->P",  &name);
-        /* lop off the HLL namespace */
-        PARROT_ASSERT(name->vtable->base_type == enum_class_ResizableStringArray);
 
-        /* if it's the root namespace, the array will be empty so don't
-           try to do a shift here */
+        /* We need to chop off the HLL namespace. If it is the root
+           namespace, the array will be empty so don't try to do a shift
+           here */
         if (VTABLE_get_integer(interp, name) > 0)
             VTABLE_shift_pmc(interp, name);
         else
             return 0;
     }
+    else if (name->vtable->base_type == enum_class_Role)
+        /* This is a bit of a hack for now. Stringification is imprecise, and
+           we sholdn't be relying on that to find unique class IDs in all
+           cases. */
+        return pmc_type(interp, VTABLE_get_string(interp, name));
+
     item = (PMC *)VTABLE_get_pointer_keyed(interp, classname_hash, name);
 
     if (!PMC_IS_NULL(item))

Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc	(original)
+++ trunk/src/pmc/namespace.pmc	Sat Jan 17 10:31:00 2009
@@ -502,7 +502,8 @@
             }
             default:
                 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_GLOBAL_NOT_FOUND,
-                    "Invalid namespace key in get_pointer_keyed");
+                    "Invalid namespace key of type '%S' in get_pointer_keyed",
+                    key->vtable->whoami);
         }
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.