Author: leo
Date: Wed Mar 15 08:14:19 2006
New Revision: 11906

Modified:
   trunk/compilers/pge/PGE/Exp.pir
   trunk/config/gen/core_pmcs.pm
   trunk/lib/Parrot/Pmc2c.pm
   trunk/runtime/parrot/library/PGE/Hs.pir
   trunk/src/global.c
   trunk/src/global_setup.c
   trunk/src/hll.c
   trunk/src/inter_misc.c
   trunk/src/mmd.c
   trunk/src/objects.c
   trunk/src/ops/experimental.ops
   trunk/src/packfile.c
   trunk/src/pmc.c
   trunk/src/pmc/coroutine.pmc
   trunk/src/pmc/parrotinterpreter.pmc
   trunk/src/pmc/sub.pmc
   trunk/t/compilers/pge/pge-hs.t
   trunk/t/pmc/globals.t
   trunk/t/pmc/mmd.t
   trunk/t/pmc/namespace.t
   trunk/t/src/extend.t

Log:
Namespaces 23 - switch to relative namespaces

- initial/default HLL namespace is "parrot"
- store_global, find_global w/o namespace are now relative to
  current namespace
- prepend "::parrot" in namespace tests
- store_global, find_global with namespace are now relative to HLL namespace
- getnamespace is absolute to namespace root
- add 'get_namespace Px, Sx' opcode (needed for 'ns = get_namespace ["Foo"]')
- simplify MMD namespace lookup
- intermediate workaround for 'newclass / .namespace': try current and HLL
  namespace to find class namespace
- adjust globals.t, fix extend.t
- use find_name instead of find_global in PGE compiled subrules code
- store_global into "PGE::Rule" in PGE::Hs


Modified: trunk/compilers/pge/PGE/Exp.pir
==============================================================================
--- trunk/compilers/pge/PGE/Exp.pir     (original)
+++ trunk/compilers/pge/PGE/Exp.pir     Wed Mar 15 08:14:19 2006
@@ -1085,7 +1085,9 @@
     emit(code, "    $P0 = find_method mob, \"%s\"", subname)
     emit(code, "    goto %s_s2", label)
     emit(code, "  %s_s1:", label)
-    emit(code, "    $P0 = find_global \"%s\"", subname)
+    ## leo: this was find_global - find_name looks into current namespace too
+    ##      I don't know, in which ns the subrule gets emitted
+    emit(code, "    $P0 = find_name \"%s\"", subname)
     emit(code, "  %s_s2:", label)
     emit(code, "    $P1 = captscope", subargs)
   subrule_3:

Modified: trunk/config/gen/core_pmcs.pm
==============================================================================
--- trunk/config/gen/core_pmcs.pm       (original)
+++ trunk/config/gen/core_pmcs.pm       Wed Mar 15 08:14:19 2006
@@ -120,7 +120,20 @@
             interp->stash_hash =
                 pmc_new(interp, enum_class_NameSpace);
             /* and parrot's default namespace */
-            parrot_ns = pmc_new(interp, enum_class_NameSpace);
+           if (interp->parent_interpreter) {
+               interp->HLL_info = interp->parent_interpreter->HLL_info;
+               interp->HLL_namespace = 
interp->parent_interpreter->HLL_namespace;
+           }
+           else {
+               STRING *parrot = const_string(interp, "parrot");
+               interp->HLL_info = constant_pmc_new(interp,
+                       enum_class_ResizablePMCArray);
+               interp->HLL_namespace = constant_pmc_new(interp,
+                       enum_class_ResizablePMCArray);
+               Parrot_register_HLL(interp, parrot, NULL);
+           }
+           parrot_ns = 
+               VTABLE_get_pmc_keyed_int(interp, interp->HLL_namespace, 0);     
             CONTEXT(interp->ctx)->current_namespace = parrot_ns; 
             VTABLE_set_pmc_keyed_str(interp, interp->stash_hash,       
                    const_string(interp, "parrot"),
@@ -129,7 +142,7 @@
             interp->class_hash = classname_hash =
                 pmc_new(interp, enum_class_Hash);
             Parrot_register_core_pmcs(interp, classname_hash);
-            /* init the interpreter globals array */
+            /* init the interp globals array */
             iglobals = pmc_new(interp, enum_class_SArray);
             interp->iglobals = iglobals;
             VTABLE_set_integer_native(interp, iglobals, (INTVAL)IGLOBALS_SIZE);

Modified: trunk/lib/Parrot/Pmc2c.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c.pm   (original)
+++ trunk/lib/Parrot/Pmc2c.pm   Wed Mar 15 08:14:19 2006
@@ -932,21 +932,10 @@
 EOC
     }
 
-    # create a namespace hash
     $cout .= <<"EOC";
-        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); 
+        /* setup MRO and _namespace */
+        Parrot_create_mro(interp, entry);
 EOC
-
     # declare each nci method for this class
     foreach my $method (@{ $self->{methods} }) {
       next unless $method->{loc} eq 'nci';
@@ -971,9 +960,6 @@
         int my_enum_class_$dynpmc = pmc_type(interp, 
string_from_const_cstring(interp, "$dynpmc", 0));
 EOC
     }
-        $cout .= <<"EOC";
-        Parrot_create_mro(interp, entry);
-EOC
     # init MMD "right" slots with the dynpmc types
     foreach my $entry (@init_mmds) {
         if ($entry->[1] eq $classname) {

Modified: trunk/runtime/parrot/library/PGE/Hs.pir
==============================================================================
--- trunk/runtime/parrot/library/PGE/Hs.pir     (original)
+++ trunk/runtime/parrot/library/PGE/Hs.pir     Wed Mar 15 08:14:19 2006
@@ -67,7 +67,8 @@
     find_global p6rule_compile, "PGE", "p6rule"
     null rulesub
     rulesub = p6rule_compile(pattern)
-    store_global name, rulesub
+    ## leo XXX need namespace
+    store_global "PGE::Rule", name, rulesub
 
     .return (name)
 .end

Modified: trunk/src/global.c
==============================================================================
--- trunk/src/global.c  (original)
+++ trunk/src/global.c  Wed Mar 15 08:14:19 2006
@@ -43,25 +43,33 @@
 
 */
 
+static PMC*
+parrot_HLL_namespace(Interp *interpreter)
+{
+    parrot_context_t *ctx = CONTEXT(interpreter->ctx);
+    INTVAL hll_id = ctx->current_HLL;
+
+    return VTABLE_get_pmc_keyed_int(interpreter, 
+            interpreter->HLL_namespace, hll_id);
+}
+
 PMC *
 Parrot_find_global(Parrot_Interp interpreter, STRING *class, STRING 
*globalname)
 {
     PMC *stash;
-
+    PMC *globals; 
 #if DEBUG_GLOBAL
     PIO_printf(interpreter, "find_global class '%Ss' meth '%Ss'\n",
             class, globalname);
 #endif
     if (class) {
-        stash = VTABLE_get_pmc_keyed_str(interpreter,
-                                         interpreter->stash_hash,
-                                         class);
+        globals = parrot_HLL_namespace(interpreter);
+        stash = VTABLE_get_pmc_keyed_str(interpreter, globals, class);
         if (!stash)
             return NULL;
     }
     else {
-        stash = interpreter->stash_hash;
-        /* TODO return relative to current namespace */
+        stash = CONTEXT(interpreter->ctx)->current_namespace;
     }
     return VTABLE_get_pointer_keyed_str(interpreter,
             stash, globalname);
@@ -71,13 +79,16 @@
 Parrot_find_global_p(Parrot_Interp interpreter, PMC *ns, STRING *name)
 {
 
+    PMC *globals;
+
     if (PMC_IS_NULL(ns))
         return Parrot_find_global(interpreter, NULL, name);
     switch (ns->vtable->base_type) {
         case enum_class_String:
             return Parrot_find_global(interpreter, PMC_str_val(ns), name);
         case enum_class_Key:
-            ns = VTABLE_get_pmc_keyed(interpreter, interpreter->stash_hash, 
ns);
+            globals = parrot_HLL_namespace(interpreter);
+            ns = VTABLE_get_pmc_keyed(interpreter, globals, ns);
             if (!ns)
                 return NULL;
             /* fall through */
@@ -120,9 +131,9 @@
 
 =item C<PMC* Parrot_get_name(Interp* interpreter, STRING *name)>
 
-Find the name in lexicals, globals, and builtins. If the name
-isn't found throw and exception or return the Null PMC, depending on
-the interpreter's errors setting.
+Find the name in lexicals, current namespace,  globals, and builtins. If the
+name isn't found throw and exception or return the Null PMC, depending on the
+interpreter's errors setting.
 
 =cut
 
@@ -141,14 +152,13 @@
        g = VTABLE_get_pmc_keyed_str(interpreter, lex_pad, name);
     }
     if (!g) {
-        current_sub = CONTEXT(interpreter->ctx)->current_sub;
-        if (current_sub &&
-                (namespace = PMC_sub(current_sub)->namespace))
-
-            g = Parrot_find_global_p(interpreter, namespace, name);
+        namespace = CONTEXT(interpreter->ctx)->current_namespace;
+        g = Parrot_find_global_p(interpreter, namespace, name);
+    }
+    if (!g) {
+        namespace = parrot_HLL_namespace(interpreter);
+        g = Parrot_find_global_p(interpreter, namespace, name);
     }
-    if (!g)
-        g = Parrot_find_global(interpreter, NULL, name);
     if (!g)
         g = Parrot_find_builtin(interpreter, name);
     if (g) {
@@ -188,19 +198,11 @@
 {
     PMC *stash;
 
-    /*
-     * this routine is called by PackFile_ConstTable_unpack too, which
-     * creates const table entries for global subs. During that the
-     * constant isn't yet created. Triggering a DOD run in the hash
-     * lookup dies then during mark_1_seg.
-     */
-    Parrot_block_DOD(interpreter);
     stash = VTABLE_get_pmc_keyed_str(interpreter, globals, class);
     if (!stash || stash->vtable->base_type != enum_class_NameSpace) {
         stash = pmc_new(interpreter, enum_class_NameSpace);
         VTABLE_set_pmc_keyed_str(interpreter, globals, class, stash);
     }
-    Parrot_unblock_DOD(interpreter);
     return stash;
 }
 
@@ -220,13 +222,15 @@
 Parrot_store_global(Interp *interpreter, STRING *class,
         STRING *globalname, PMC *pmc)
 {
-    PMC *globals = interpreter->stash_hash;
+    PMC *globals;
     PMC *stash;
+
     if (class) {
+        globals = parrot_HLL_namespace(interpreter);
         stash = Parrot_global_namespace(interpreter, globals, class);
     }
     else
-        stash = globals;
+        stash = CONTEXT(interpreter->ctx)->current_namespace;
     VTABLE_set_pmc_keyed_str(interpreter, stash, globalname, pmc);
     Parrot_invalidate_method_cache(interpreter, class, globalname);
 }
@@ -235,13 +239,15 @@
 store_sub(Interp *interpreter, STRING *class,
         STRING *globalname, PMC *pmc)
 {
-    PMC *globals = interpreter->stash_hash;
+    PMC *globals;
     PMC *stash;
+
     if (class) {
+        globals = parrot_HLL_namespace(interpreter);
         stash = Parrot_global_namespace(interpreter, globals, class);
     }
     else
-        stash = globals;  /*  TODO current */
+        stash = CONTEXT(interpreter->ctx)->current_namespace;
     VTABLE_set_pmc_keyed_str(interpreter, stash, globalname, pmc);
     Parrot_invalidate_method_cache(interpreter, class, globalname);
     /* MultiSub isa R*PMCArray and doesn't have a PMC_sub structure 
@@ -258,8 +264,10 @@
 store_sub_p(Interp *interpreter, PMC *namespace,
         STRING *globalname, PMC *pmc)
 {
-    PMC *globals = interpreter->stash_hash;
+    PMC *globals;
     PMC *stash;
+
+    globals = parrot_HLL_namespace(interpreter);
     stash = VTABLE_get_pmc_keyed(interpreter, globals, namespace);
     if (!stash || stash->vtable->base_type != enum_class_NameSpace) {
         stash = pmc_new(interpreter, enum_class_NameSpace);

Modified: trunk/src/global_setup.c
==============================================================================
--- trunk/src/global_setup.c    (original)
+++ trunk/src/global_setup.c    Wed Mar 15 08:14:19 2006
@@ -143,21 +143,6 @@
     parrot_set_config_hash_interpreter(interpreter);
 
     /*
-     * HLL support
-     */
-    if (interpreter->parent_interpreter) {
-        interpreter->HLL_info = interpreter->parent_interpreter->HLL_info;
-        interpreter->HLL_namespace = 
interpreter->parent_interpreter->HLL_namespace;
-    }
-    else {
-        STRING *parrot = CONST_STRING(interpreter, "parrot");
-        interpreter->HLL_info = constant_pmc_new(interpreter,
-                enum_class_ResizablePMCArray);
-        interpreter->HLL_namespace = constant_pmc_new(interpreter,
-                enum_class_ResizablePMCArray);
-        Parrot_register_HLL(interpreter, parrot, NULL);
-    }
-    /*
      * lib search paths
      */
     parrot_init_library_paths(interpreter);

Modified: trunk/src/hll.c
==============================================================================
--- trunk/src/hll.c     (original)
+++ trunk/src/hll.c     Wed Mar 15 08:14:19 2006
@@ -112,18 +112,9 @@
      *
      * XXX always try to fetch namespace first?
      */
-    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);
-    }
+    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);

Modified: trunk/src/inter_misc.c
==============================================================================
--- trunk/src/inter_misc.c      (original)
+++ trunk/src/inter_misc.c      Wed Mar 15 08:14:19 2006
@@ -42,12 +42,14 @@
 {
     PMC *method;
     method = pmc_new(interpreter, enum_class_NCI);
+    /* create call func */
     VTABLE_set_pointer_keyed_str(interpreter, method,
             string_make(interpreter, proto, strlen(proto),
                 NULL, PObj_constant_FLAG|PObj_external_FLAG),
             func);
-    Parrot_store_global(interpreter,
-        Parrot_base_vtables[type]->whoami,
+    /* insert it into namespace */
+    VTABLE_set_pmc_keyed_str(interpreter, 
+        Parrot_base_vtables[type]->_namespace,
             string_make(interpreter, name,
                 strlen(name), NULL,
                 PObj_constant_FLAG|PObj_external_FLAG),

Modified: trunk/src/mmd.c
==============================================================================
--- trunk/src/mmd.c     (original)
+++ trunk/src/mmd.c     Wed Mar 15 08:14:19 2006
@@ -47,7 +47,7 @@
 
 #define MMD_DEBUG 0
 
-static void mmd_create_builtin_multi_meth_2(Interp *,
+static void mmd_create_builtin_multi_meth_2(Interp *, PMC *ns,
         INTVAL func_nr, INTVAL type, INTVAL right, funcptr_t func_ptr);
 
 #ifndef NDEBUG
@@ -308,11 +308,6 @@
             mmd_register(interpreter, func_nr, left->vtable->base_type,
                     right->vtable->base_type,
                     D2FPTR((UINTVAL) sub | 3));
-#if 0
-            mmd_create_builtin_multi_meth_2(interpreter,
-                func_nr, left->vtable->base_type,
-                right->vtable->base_type, (funcptr_t)mmd_wrap_p_ppp);
-#endif
             is_pmc = 3;
         }
         if (is_pmc == 3) {
@@ -1952,18 +1947,9 @@
 static int
 mmd_search_package(Interp *interpreter, STRING *meth, PMC *arg_tuple, PMC *cl)
 {
-    /* STRING *namespace = CONTEXT(interpreter->ctx)->current_package; */
     PMC *pmc;
-    PMC *current_sub;
-    PMC *namespace;
 
-    current_sub = CONTEXT(interpreter->ctx)->current_sub;
-    if (!current_sub || !VTABLE_defined(interpreter, current_sub))
-        return 0;
-    namespace = PMC_sub(current_sub)->namespace;
-    if (!namespace)
-        return 0;
-    pmc = Parrot_find_global_p(interpreter, namespace, meth);
+    pmc = Parrot_find_global(interpreter, NULL, meth);
     if (pmc) {
         if (mmd_maybe_candidate(interpreter, pmc, arg_tuple, cl))
             return 1;
@@ -1987,7 +1973,7 @@
 {
     PMC *pmc;
 
-    pmc = Parrot_find_global(interpreter, NULL, meth);
+    pmc = Parrot_find_global_p(interpreter, interpreter->stash_hash, meth);
     if (pmc) {
         if (mmd_maybe_candidate(interpreter, pmc, arg_tuple, cl))
             return 1;
@@ -2006,40 +1992,68 @@
 
 */
 
+static PMC*
+mmd_get_ns(Interp *interpreter) 
+{
+    STRING *ns_name;
+    PMC *ns;
+
+    ns_name = CONST_STRING(interpreter, "__parrot_core");
+    ns = VTABLE_get_pmc_keyed_str(interpreter, 
+            interpreter->stash_hash, ns_name);
+    return ns;
+}
+
+static PMC*
+mmd_create_ns(Interp *interpreter) 
+{
+    STRING *ns_name;
+    PMC *ns;
+
+    ns_name = CONST_STRING(interpreter, "__parrot_core");
+    ns = VTABLE_get_pmc_keyed_str(interpreter, 
+            interpreter->stash_hash, ns_name);
+    if (!ns) {
+        ns = pmc_new(interpreter, enum_class_NameSpace);
+        VTABLE_set_pmc_keyed_str(interpreter, 
+                interpreter->stash_hash, ns_name, ns);
+    }
+    return ns;
+}
+
 static void
 mmd_search_builtin(Interp *interpreter, STRING *meth, PMC *arg_tuple, PMC *cl)
 {
-    PMC *pmc;
-    STRING *ns;
-
-    ns = CONST_STRING(interpreter, "__parrot_core");
-    pmc = Parrot_find_global(interpreter, ns, meth);
+    PMC *pmc, *ns;
+    ns = mmd_get_ns(interpreter);
+    pmc = Parrot_find_global_p(interpreter, ns, meth);
     if (pmc)
         mmd_maybe_candidate(interpreter, pmc, arg_tuple, cl);
 }
 
-static void
-mmd_create_builtin_multi_stub(Interp *interpreter, INTVAL func_nr)
+
+static PMC *
+mmd_create_builtin_multi_stub(Interp *interpreter, PMC* ns, INTVAL func_nr)
 {
     const char *name;
-    STRING *s, *ns;
+    STRING *s;
     PMC *multi;
 
     name = Parrot_MMD_method_name(interpreter, func_nr);
-    ns = CONST_STRING(interpreter, "__parrot_core");
-    s =  const_string(interpreter, name);
     /* create in constant pool */
+    s = const_string(interpreter, name);
     multi = constant_pmc_new(interpreter, enum_class_MultiSub);
-    Parrot_store_global(interpreter, ns, s, multi);
+    VTABLE_set_pmc_keyed_str(interpreter, ns, s, multi);
+    return ns;
 }
 
 static void
-mmd_create_builtin_multi_meth_2(Interp *interpreter,
+mmd_create_builtin_multi_meth_2(Interp *interpreter, PMC *ns,
         INTVAL func_nr, INTVAL type, INTVAL right, funcptr_t func_ptr)
 {
     const char *short_name;
     char signature[6], val_sig;
-    STRING *meth_name, *ns, *_sub;
+    STRING *meth_name, *_sub;
     PMC *method, *multi, *class, *multi_sig;
 
     assert (type != enum_class_Null && type != enum_class_delegate &&
@@ -2116,8 +2130,7 @@
      * push method onto core multi_sub
      * TODO cache the namespace
      */
-    ns = CONST_STRING(interpreter, "__parrot_core");
-    multi = Parrot_find_global(interpreter, ns,
+    multi = Parrot_find_global_p(interpreter, ns,
             const_string(interpreter, short_name));
     assert(multi);
     VTABLE_push_pmc(interpreter, multi, method);
@@ -2125,10 +2138,10 @@
 }
 
 static void
-mmd_create_builtin_multi_meth(Interp *interpreter, INTVAL type,
+mmd_create_builtin_multi_meth(Interp *interpreter, PMC *ns, INTVAL type,
         const MMD_init *entry)
 {
-    mmd_create_builtin_multi_meth_2(interpreter,
+    mmd_create_builtin_multi_meth_2(interpreter, ns, 
             entry->func_nr, type, entry->right, entry->func_ptr);
 }
 
@@ -2150,8 +2163,10 @@
 {
     INTVAL i;
     MMD_table *table;
+    PMC *ns;
 
     table = interpreter->binop_mmd_funcs;
+    ns = mmd_create_ns(interpreter);
     if ((INTVAL)table->x < type && type < enum_class_core_max) {
         /*
          * pre-allocate the function table
@@ -2162,7 +2177,7 @@
             /*
              * create a MultiSub stub
              */
-            mmd_create_builtin_multi_stub(interpreter, i);
+            mmd_create_builtin_multi_stub(interpreter, ns, i);
         }
     }
     /*
@@ -2173,7 +2188,7 @@
         mmd_register(interpreter,
                 mmd_table[i].func_nr, type,
                 mmd_table[i].right, mmd_table[i].func_ptr);
-        mmd_create_builtin_multi_meth(interpreter, type, mmd_table + i);
+        mmd_create_builtin_multi_meth(interpreter, ns, type, mmd_table + i);
     }
 }
 

Modified: trunk/src/objects.c
==============================================================================
--- trunk/src/objects.c (original)
+++ trunk/src/objects.c Wed Mar 15 08:14:19 2006
@@ -447,7 +447,7 @@
     INTVAL new_type;
     VTABLE *new_vtable, *parent_vtable;
     PMC *vtable_pmc;
-    PMC *ns; 
+    PMC *ns, *top; 
 
     /*
      * register the class in the PMCs name class_hash
@@ -485,13 +485,21 @@
     Parrot_base_vtables[new_type] = new_vtable;
 
     /* check if we already have a NameSpace */
-    ns = VTABLE_get_pmc_keyed_str(interpreter, interpreter->stash_hash, 
-            class_name);
+    top = CONTEXT(interpreter->ctx)->current_namespace;
+    ns = VTABLE_get_pmc_keyed_str(interpreter, top, class_name);
     /* XXX nested, use current as base ? */
     if (!ns) {
+        /* XXX try HLL namespace too XXX */
+        parrot_context_t *ctx = CONTEXT(interpreter->ctx);
+        INTVAL hll_id = ctx->current_HLL;
+
+        top =  VTABLE_get_pmc_keyed_int(interpreter, 
+                interpreter->HLL_namespace, hll_id);
+        ns = VTABLE_get_pmc_keyed_str(interpreter, top, class_name);
+    }
+    if (!ns) {
         ns = pmc_new(interpreter, enum_class_NameSpace);
-        VTABLE_set_pmc_keyed_str(interpreter, interpreter->stash_hash, 
-                class_name, ns);
+        VTABLE_set_pmc_keyed_str(interpreter, top, class_name, ns);
     }
     /* attach namspace to vtable */
     new_vtable->_namespace = ns;
@@ -1141,16 +1149,15 @@
 find_method_direct_1(Interp* interpreter, PMC *class,
                               STRING *method_name)
 {
-    PMC* method, *mro;
-    STRING *name;
+    PMC* method, *mro, *ns;
     INTVAL i, n;
 
     mro = class->vtable->mro;
     n = VTABLE_elements(interpreter, mro);
     for (i = 0; i < n; ++i) {
         class = VTABLE_get_pmc_keyed_int(interpreter, mro, i);
-        name = VTABLE_name(interpreter, class);
-        method = Parrot_find_global(interpreter, name, method_name);
+        ns = VTABLE_namespace(interpreter, class);
+        method = VTABLE_get_pmc_keyed_str(interpreter, ns, method_name);
         TRACE_FM(interpreter, class, method_name, method);
         if (method) {
             return method;

Modified: trunk/src/ops/experimental.ops
==============================================================================
--- trunk/src/ops/experimental.ops      (original)
+++ trunk/src/ops/experimental.ops      Wed Mar 15 08:14:19 2006
@@ -238,6 +238,8 @@
 
 =item B<get_namespace>(out PMC, in KEY)
 
+=item B<get_namespace>(out PMC, in STR)
+
 Get the specified namespace. $2 is either an array of names or a key.
 If the namespace doesn't exist, $1 is set to PMCNULL.
 
@@ -267,6 +269,13 @@
     goto NEXT();
 }
 
+op get_namespace(out PMC, in STR) {
+    PMC *ns_root = interpreter->stash_hash, *ns;
+    ns = VTABLE_get_pmc_keyed_str(interpreter, ns_root, $2);
+    $1 = ns ? ns : PMCNULL;
+    goto NEXT();
+}
+
 op find_global(out PMC, in KEY, in STR) {
     $1 = Parrot_find_global_p(interpreter, $2, $3);
     goto NEXT();

Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c        (original)
+++ trunk/src/packfile.c        Wed Mar 15 08:14:19 2006
@@ -3200,7 +3200,10 @@
          * XXX place this code in Sub.thaw ?
          */
         if (!(PObj_get_FLAGS(pmc) & SUB_FLAG_PF_ANON)) {
+            /* PF structures aren't fully constructed yet */
+            Parrot_block_DOD(interpreter);
             Parrot_store_sub_in_namespace(interpreter, pmc);
+            Parrot_unblock_DOD(interpreter);
         }
     }
     /*

Modified: trunk/src/pmc.c
==============================================================================
--- trunk/src/pmc.c     (original)
+++ trunk/src/pmc.c     Wed Mar 15 08:14:19 2006
@@ -478,9 +478,10 @@
 Parrot_create_mro(Interp *interpreter, INTVAL type)
 {
     VTABLE *vtable;
-    STRING *class_name;
+    STRING *class_name, *isa;
     INTVAL pos, len, parent_type, total;
     PMC *class, *mro;
+    PMC *ns;
 
     vtable = Parrot_base_vtables[type];
     /* multithreaded: has already mro */
@@ -489,25 +490,37 @@
     mro = pmc_new(interpreter, enum_class_ResizablePMCArray);
     vtable->mro = mro;
     class_name = vtable->whoami;
-    total = (INTVAL)string_length(interpreter, vtable->isa_str);
+    isa = vtable->isa_str;
+    total = (INTVAL)string_length(interpreter, isa);
     for (pos = 0; ;) {
         len = string_length(interpreter, class_name);
         pos += len + 1;
         parent_type = pmc_type(interpreter, class_name);
         if (!parent_type)   /* abstract classes don't have a vtable */
             break;
-        class = Parrot_base_vtables[parent_type]->class;
+        vtable = Parrot_base_vtables[parent_type];
+        if (!vtable->_namespace) {
+            /* need a namespace Hash, anchor at parent, name it */
+            ns = pmc_new(interpreter,
+                    Parrot_get_ctx_HLL_type(interpreter, 
enum_class_NameSpace));
+            vtable->_namespace = ns;
+            /* anchor at parent, aka current_namespace, that is 'parrot' */
+            VTABLE_set_pmc_keyed_str(interpreter, 
+                    CONTEXT(interpreter->ctx)->current_namespace,      
+                    class_name, ns);
+        }
+        class = vtable->class;
         if (!class) {
             class = create_class_pmc(interpreter, parent_type);
         }
         VTABLE_push_pmc(interpreter, mro, class);
         if (pos >= total)
             break;
-        len = string_str_index(interpreter, vtable->isa_str,
+        len = string_str_index(interpreter, isa,
                 CONST_STRING(interpreter, " "), pos);
         if (len == -1)
             len = total;
-        class_name = string_substr(interpreter, vtable->isa_str, pos,
+        class_name = string_substr(interpreter, isa, pos,
                 len - pos, NULL, 0);
     }
 }

Modified: trunk/src/pmc/coroutine.pmc
==============================================================================
--- trunk/src/pmc/coroutine.pmc (original)
+++ trunk/src/pmc/coroutine.pmc Wed Mar 15 08:14:19 2006
@@ -161,7 +161,10 @@
             PMC_cont(ccont)->from_ctx = ctx;
             ctx->current_sub = SELF;
             ctx->current_HLL = co->HLL_id;
-            ctx->current_namespace = co->namespace_stash;
+            if (co->namespace_stash) {
+                /* :anon sub don't have it */
+                ctx->current_namespace = co->namespace_stash;
+            }
             ctx->current_cont = ccont;
             ctx->current_object = NULL;
             INTERP->current_object = NULL;

Modified: trunk/src/pmc/parrotinterpreter.pmc
==============================================================================
--- trunk/src/pmc/parrotinterpreter.pmc (original)
+++ trunk/src/pmc/parrotinterpreter.pmc Wed Mar 15 08:14:19 2006
@@ -555,8 +555,8 @@
 
     void thawfinish(visit_info *info) {
         INTVAL i, n, m;
-        PMC *hll_info, *entry, *lib_pmc, *new_info;
-        STRING *lib_name;
+        PMC *hll_info, *entry, *lib_pmc, *new_info, *ns_hash;
+        STRING *lib_name, *hll_name;
 
         hll_info = INTERP->HLL_info;
         n = VTABLE_elements(INTERP, hll_info);
@@ -573,6 +573,27 @@
             lib_name = VTABLE_get_string(INTERP, lib_pmc);
             if (lib_name->strlen)
                 Parrot_load_lib(INTERP, lib_name, NULL);
+            hll_name = VTABLE_get_string_keyed_int(INTERP, entry, 0);
+            /* create HLL namespace */
+            hll_name = string_downcase(INTERP, hll_name);
+
+            /* HLL type mappings aren't yet created, we can't create
+             * a namespace in HLL's flavor yet - mabe promote the
+             * ns_hash to another type, if mappings provide one
+             *
+             * XXX always try to fetch namespace first?
+             */
+
+            ns_hash = VTABLE_get_pmc_keyed_str(INTERP, INTERP->stash_hash,
+                    hll_name);
+            if (!ns_hash) {
+                ns_hash  = pmc_new(INTERP, enum_class_NameSpace);
+                VTABLE_set_pmc_keyed_str(INTERP, INTERP->stash_hash,
+                        hll_name, ns_hash);
+            }
+            /* cache HLLs toplevel namespace */
+            VTABLE_set_pmc_keyed_int(INTERP, INTERP->HLL_namespace, 
+                    i, ns_hash);
         }
         if (m > n) {
             /* TODO destruct old HLL_info are constants */

Modified: trunk/src/pmc/sub.pmc
==============================================================================
--- trunk/src/pmc/sub.pmc       (original)
+++ trunk/src/pmc/sub.pmc       Wed Mar 15 08:14:19 2006
@@ -294,7 +294,10 @@
             INTERP->current_method = NULL;
         }
         context->current_HLL = sub->HLL_id;
-        context->current_namespace = sub->namespace_stash;
+        if (sub->namespace_stash) {
+            /* :anon sub don't have it */
+            context->current_namespace = sub->namespace_stash;
+        }
         /* create pad if needed
          * TODO move this up in front of argument passing
          *      and factor out common code with coroutine pmc

Modified: trunk/t/compilers/pge/pge-hs.t
==============================================================================
--- trunk/t/compilers/pge/pge-hs.t      (original)
+++ trunk/t/compilers/pge/pge-hs.t      Wed Mar 15 08:14:19 2006
@@ -33,7 +33,6 @@
     add_rule = find_global "PGE::Hs", "add_rule"
     add_rule("foo", "s")
     result = match("test", "t(.<foo>)t")
-
     eq result, "PGE_Match 0 4 [PGE_Match 1 3 [] [(\"foo\", PGE_Match 2 3 [] 
[])]] []\n", OK
     print "not "
 

Modified: trunk/t/pmc/globals.t
==============================================================================
--- trunk/t/pmc/globals.t       (original)
+++ trunk/t/pmc/globals.t       Wed Mar 15 08:14:19 2006
@@ -57,7 +57,7 @@
 pir_output_is(<<'CODE', <<'OUTPUT', "get namespace - nested");
 .sub main
    .local pmc ns, o
-   ns = get_namespace ["Foo"; "Bar"]
+   ns = get_namespace ["parrot"; "Foo"; "Bar"]
    o =  find_global ns, "f"
    o()
 .end

Modified: trunk/t/pmc/mmd.t
==============================================================================
--- trunk/t/pmc/mmd.t   (original)
+++ trunk/t/pmc/mmd.t   Wed Mar 15 08:14:19 2006
@@ -406,14 +406,11 @@
 OUT
 
 pir_output_is(<<'CODE', <<'OUT', "MMD on argument count");
-.namespace ["main"]
 .sub main :main
     p("ok 1\n")
     p("-twice", "ok 2\n")
 .end
 
-.namespace [""]
-
 .sub p :multi(string)
     .param string s
     print s
@@ -436,14 +433,11 @@
 OUT
 
 pir_output_is(<<'CODE', <<'OUT', "MMD on mative types");
-.namespace ["main"]
 .sub main :main
     p("ok 1\n")
     p(42)
 .end
 
-.namespace [""]
-
 .sub p :multi(string)
     .param string s
     print s
@@ -460,7 +454,6 @@
 OUT
 
 pir_output_is(<<'CODE', <<'OUT', "MMD on PMC types");
-.namespace ["main"]
 .sub main :main
     $P0 = new String
     $P0 = "ok 1\n"
@@ -478,8 +471,6 @@
     p($P1)
 .end
 
-.namespace [""]
-
 .sub p :multi(String)
     .param pmc p
     print "String "
@@ -499,7 +490,6 @@
 OUT
 
 pir_output_is(<<'CODE', <<'OUT', "MMD on PMC types quoted");
-.namespace ["main"]
 .sub main :main
     $P0 = new String
     $P0 = "ok 1\n"
@@ -517,8 +507,6 @@
     p($P1)
 .end
 
-.namespace [""]
-
 .sub p :multi("String")
     .param pmc p
     print "String "
@@ -538,7 +526,6 @@
 OUT
 
 pir_output_like(<<'CODE', <<'OUT', "MMD on PMC types, invalid");
-.namespace ["main"]
 .sub main :main
     $P0 = new String
     $P0 = "ok 1\n"
@@ -558,8 +545,6 @@
     p($P0)
 .end
 
-.namespace [""]
-
 .sub p :multi(String)
     .param pmc p
     print "String "
@@ -580,7 +565,6 @@
 OUT
 
 pir_output_is(<<'CODE', <<'OUT', "MMD on PMC types 3");
-.namespace ["main"]
 .sub main :main
     $P0 = new String
     $P0 = "ok 1\n"
@@ -601,8 +585,6 @@
     p($P0)
 .end
 
-.namespace [""]
-
 .sub p :multi(String)
     .param pmc p
     print "String "
@@ -759,13 +741,15 @@
 
 pir_output_is(<<'CODE', <<'OUTPUT', "__add as function - Int, Float");
 .sub main :main
-    .local pmc d, l, r
+    .local pmc d, l, r, ns, a
     d = new Integer
     l = new Integer
     r = new Float
     l = 3
     r = 39.42
-    "__add"(l, r, d)
+    ns = get_namespace ["__parrot_core"]
+    a = ns["__add"]
+    a(l, r, d)
     print d
     print "\n"
     end

Modified: trunk/t/pmc/namespace.t
==============================================================================
--- trunk/t/pmc/namespace.t     (original)
+++ trunk/t/pmc/namespace.t     Wed Mar 15 08:14:19 2006
@@ -123,7 +123,7 @@
 .sub 'main' :main
     .include "interpinfo.pasm"
     $P0 = interpinfo .INTERPINFO_NAMESPACE_ROOT
-    $P1 = $P0["Foo"]
+    $P1 = $P0["parrot";"Foo"]
     $P2 = $P1["bar"]
     print "ok\n"
     $P2()
@@ -193,7 +193,7 @@
 .sub 'main' :main
     .include "interpinfo.pasm"
     $P0 = interpinfo .INTERPINFO_NAMESPACE_ROOT
-    $P1 = $P0["Foo";"Bar" ; "baz"]
+    $P1 = $P0["parrot";"Foo";"Bar" ; "baz"]
     print "ok\n"
     $P1()
 .end
@@ -323,7 +323,7 @@
 CODE
 ok
 baz
-::Foo::Bar
+::parrot::Foo::Bar
 OUTPUT
 
 SKIP: {
@@ -480,7 +480,7 @@
 .end
 CODE
 ok
-::Foo
+::parrot::Foo
 Foo
 OUTPUT
 

Modified: trunk/t/src/extend.t
==============================================================================
--- trunk/t/src/extend.t        (original)
+++ trunk/t/src/extend.t        Wed Mar 15 08:14:19 2006
@@ -441,22 +441,21 @@
 the_test(Parrot_Interp interpreter, opcode_t *cur_op, opcode_t *start)
 {
     struct PackFile *pf;
-    PMC *key, *sub, *arg;
+    PMC *sub, *arg;
+    STRING *name;
 
     pf = Parrot_readbc(interpreter, "temp.pbc");
     Parrot_loadbc(interpreter, pf);
-    key = key_new_cstring(interpreter, "_sub1");
-    sub = VTABLE_get_pmc_keyed(interpreter,
-                              interpreter->stash_hash, key);
+    name = const_string(interpreter, "_sub1");
+    sub = Parrot_find_global(interpreter, NULL, name);
     Parrot_call_sub(interpreter, sub, "v");
     PIO_eprintf(interpreter, "back\n");
 
     /* win32 seems to buffer stderr ? */
     PIO_flush(interpreter, PIO_STDERR(interpreter));
 
-    key = key_new_cstring(interpreter, "_sub2");
-    sub = VTABLE_get_pmc_keyed(interpreter,
-                              interpreter->stash_hash, key);
+    name = const_string(interpreter, "_sub2");
+    sub = Parrot_find_global(interpreter, NULL, name);
     arg = pmc_new(interpreter, enum_class_String);
     VTABLE_set_string_native(interpreter, arg,
                             string_from_cstring(interpreter, "hello ", 0));
@@ -514,14 +513,14 @@
 the_test(Parrot_Interp interpreter, opcode_t *cur_op, opcode_t *start)
 {
     struct PackFile *pf;
-    PMC *key, *sub;
+    PMC *sub;
+    STRING *name;
     Parrot_exception jb;
 
     pf = Parrot_readbc(interpreter, "temp.pbc");
     Parrot_loadbc(interpreter, pf);
-    key = key_new_cstring(interpreter, "_sub1");
-    sub = VTABLE_get_pmc_keyed(interpreter,
-                              interpreter->stash_hash, key);
+    name = const_string(interpreter, "_sub1");
+    sub = Parrot_find_global(interpreter, NULL, name);
 
     if (setjmp(jb.destination)) {
        PIO_eprintf(interpreter, "caught\n");

Reply via email to