Author: leo
Date: Mon Mar 13 05:54:32 2006
New Revision: 11884

Modified:
   trunk/config/gen/core_pmcs.pm
   trunk/lib/Parrot/Pmc2c.pm
   trunk/src/hll.c
   trunk/t/pmc/namespace.t

Log:
Namespaces 21 - parrot and PMC namespace creation

* create "parrot" namespace during creation of core PMCs
* create PMC namespaces as e.g. "parrot::String" 


Modified: trunk/config/gen/core_pmcs.pm
==============================================================================
--- trunk/config/gen/core_pmcs.pm       (original)
+++ trunk/config/gen/core_pmcs.pm       Mon Mar 13 05:54:32 2006
@@ -86,7 +86,7 @@
 /*
  * DO NOT EDIT THIS FILE
  *
- * Automatically generated by config/gen/core_pmcs.pl
+ * Automatically generated by config/gen/core_pmcs.pm
  */
 
 #include "parrot/parrot.h"
@@ -115,9 +115,16 @@
         if (!pass) {
             PMC *classname_hash, *iglobals;
             int i;
-            /* Need an empty stash */
+           PMC *parrot_ns;
+            /* create the namespace root stash */
             interp->stash_hash =
                 pmc_new(interp, enum_class_NameSpace);
+            /* and parrot's default namespace */
+            parrot_ns = pmc_new(interp, enum_class_NameSpace);
+            CONTEXT(interp->ctx)->current_namespace = parrot_ns; 
+            VTABLE_set_pmc_keyed_str(interp, interp->stash_hash,       
+                   const_string(interp, "parrot"),
+                   parrot_ns);
             /* We need a class hash */
             interp->class_hash = classname_hash =
                 pmc_new(interp, enum_class_Hash);
@@ -168,7 +175,7 @@
     print OUT <<'END_PM';
 # DO NOT EDIT THIS FILE
 #
-# Automatically generated by config/gen/core_pmcs.pl
+# Automatically generated by config/gen/core_pmcs.pm
 
 package Parrot::PMC;
 

Modified: trunk/lib/Parrot/Pmc2c.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c.pm   (original)
+++ trunk/lib/Parrot/Pmc2c.pm   Mon Mar 13 05:54:32 2006
@@ -934,9 +934,17 @@
 
     # create a namespace hash
     $cout .= <<"EOC";
-        /* need a namespace Hash TODO anchor at parent, name it */
-        Parrot_base_vtables[entry]->_namespace = pmc_new(interp,
+        PMC *ns;
+        
+        /* need a namespace Hash, anchor at parent, name it */
+        ns = pmc_new(interp,
                 Parrot_get_ctx_HLL_type(interp, enum_class_NameSpace));
+        Parrot_base_vtables[entry]->_namespace = ns;
+        /* anchor at parent, aka current_namespace, that is 'parrot' */
+        VTABLE_set_pmc_keyed_str(interp, 
+                CONTEXT(interp->ctx)->current_namespace,       
+                Parrot_base_vtables[entry]->whoami, 
+                ns); 
 EOC
 
     # declare each nci method for this class

Modified: trunk/src/hll.c
==============================================================================
--- trunk/src/hll.c     (original)
+++ trunk/src/hll.c     Mon Mar 13 05:54:32 2006
@@ -110,13 +110,23 @@
      * a namespace in HLL's flavor yet - mabe promote the
      * ns_hash to another type, if mappings provide one
      *
-     * TODO need better API to append namespaces
+     * XXX always try to fetch namespace first?
      */
-    ns_hash  = pmc_new(interpreter, enum_class_NameSpace);
-    VTABLE_set_pmc_keyed_str(interpreter, interpreter->stash_hash,
-            hll_name, ns_hash);
+    if (!idx) {
+        /* "parrot" NS is already created during creation of core PMCs
+         * fetch namespace
+         */
+        ns_hash = VTABLE_get_pmc_keyed_str(interpreter, 
+                interpreter->stash_hash, hll_name);
+    }
+    else {
+        ns_hash  = pmc_new(interpreter, enum_class_NameSpace);
+        VTABLE_set_pmc_keyed_str(interpreter, interpreter->stash_hash,
+                hll_name, ns_hash);
+    }
     /* cache HLLs toplevel namespace */
-    VTABLE_set_pmc_keyed_int(interpreter, interpreter->HLL_namespace, idx, 
ns_hash);
+    VTABLE_set_pmc_keyed_int(interpreter, interpreter->HLL_namespace, 
+            idx, ns_hash);
 
     /* register HLL lib */
     name = constant_pmc_new_noinit(interpreter, enum_class_String);

Modified: trunk/t/pmc/namespace.t
==============================================================================
--- trunk/t/pmc/namespace.t     (original)
+++ trunk/t/pmc/namespace.t     Mon Mar 13 05:54:32 2006
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 22;
+use Parrot::Test tests => 23;
 
 =head1 NAME
 
@@ -484,3 +484,13 @@
 Foo
 OUTPUT
 
+pir_output_is(<<'CODE', <<'OUTPUT', "check parrot ns", todo => 'soon');
+.sub 'main' :main
+    $P0 = get_namespace ["parrot"; "String"]
+    $P1 = find_global $P0, "lower"
+    $S0 = $P1("OK\n")
+    print $S0
+.end
+CODE
+ok
+OUTPUT

Reply via email to