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

[email protected]
Newsgroups perl.cvs.parrot
Message-ID <[email protected]>
Author: Whiteknight
Date: Sat Jan 17 09:22:58 2009
New Revision: 35697

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

Log:
[get_class] some updates to get_class to try and standardize the way objects are looked up. This fixes some of the hacky stuff I did yesterday to implement some of this behavior (but doesn't fix everything). Jonathan++ for the help

Modified: trunk/src/oo.c
==============================================================================
--- trunk/src/oo.c	(original)
+++ trunk/src/oo.c	Sat Jan 17 09:22:58 2009
@@ -228,7 +228,8 @@
            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_String
+         || base_type == enum_class_NameSpace)
             type = pmc_type_p(interp, key);
         else
             type = pmc_type(interp, VTABLE_get_string(interp, key));

Modified: trunk/src/pmc.c
==============================================================================
--- trunk/src/pmc.c	(original)
+++ trunk/src/pmc.c	Sat Jan 17 09:22:58 2009
@@ -617,8 +617,21 @@
 {
     ASSERT_ARGS(pmc_type_p)
     PMC * const classname_hash = interp->class_hash;
-    PMC * const item           =
-        (PMC *)VTABLE_get_pointer_keyed(interp, classname_hash, name);
+    PMC * item;
+
+    if (name->vtable->base_type == enum_class_NameSpace) {
+        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 */
+        if (VTABLE_get_integer(interp, name) > 0)
+            VTABLE_shift_pmc(interp, name);
+        else
+            return 0;
+    }
+    item = (PMC *)VTABLE_get_pointer_keyed(interp, classname_hash, name);
 
     if (!PMC_IS_NULL(item))
         return VTABLE_get_integer(interp, item);

Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc	(original)
+++ trunk/src/pmc/namespace.pmc	Sat Jan 17 09:22:58 2009
@@ -500,9 +500,6 @@
                 }
                 return ns;
             }
-            case enum_class_NameSpace:
-                /* XXX TT#182: Implement this! */
-                return PMCNULL;
             default:
                 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_GLOBAL_NOT_FOUND,
                     "Invalid namespace key in get_pointer_keyed");
@@ -633,16 +630,19 @@
 
     METHOD get_name() {
         PMC * const ar = pmc_new(INTERP, enum_class_ResizableStringArray);
+        INTVAL elements = 0;
         PMC *ns        = SELF;
 
         while (ns) {
             Parrot_NameSpace_attributes *nsinfo = PARROT_NAMESPACE(ns);
             VTABLE_unshift_string(INTERP, ar, nsinfo->name);
             ns = PMC_pmc_val(ns);
+            elements++;
         }
 
         /* remove the NULL string of the namespace root */
-        VTABLE_shift_string(INTERP, ar);
+        if (elements > 0)
+            VTABLE_shift_string(INTERP, ar);
 
         RETURN(PMC *ar);
     }
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.