Author: leo
Date: Sun Mar 12 06:20:45 2006
New Revision: 11874

Modified:
   trunk/src/global.c
   trunk/src/ops/experimental.ops
   trunk/src/pmc/sub.pmc
   trunk/t/pmc/namespace.t

Log:
Namespaces 18 - get_namespace opcode and method

* Sub.get_namespace now returns the NameSpace hash, not the String/Key
* get_namespace opcode returns the current NameSpace
* adjust tests


Modified: trunk/src/global.c
==============================================================================
--- trunk/src/global.c  (original)
+++ trunk/src/global.c  Sun Mar 12 06:20:45 2006
@@ -247,7 +247,7 @@
     /* MultiSub isa R*PMCArray and doesn't have a PMC_sub structure 
      * MultiSub could also contain subs from various namespaces,
      * that it doesn't make much sense, to associate a namespace
-     * a multi.
+     * with a multi.
      *
      */
     if (pmc->vtable->base_type != enum_class_MultiSub)

Modified: trunk/src/ops/experimental.ops
==============================================================================
--- trunk/src/ops/experimental.ops      (original)
+++ trunk/src/ops/experimental.ops      Sun Mar 12 06:20:45 2006
@@ -250,19 +250,21 @@
 op get_namespace(out PMC) {
     PMC *current_sub;
     current_sub = CONTEXT(interpreter->ctx)->current_sub;
-    $1 = PMC_sub(current_sub)->namespace;
+    $1 = PMC_sub(current_sub)->namespace_stash;
     goto NEXT();
 }
 
 op get_namespace(out PMC, in PMC) {
-    PMC *ns_root = interpreter->stash_hash;
-    $1 = VTABLE_get_pmc_keyed(interpreter, ns_root, $2);
+    PMC *ns_root = interpreter->stash_hash, *ns;
+    ns = VTABLE_get_pmc_keyed(interpreter, ns_root, $2);
+    $1 = ns ? ns : PMCNULL;
     goto NEXT();
 }
 
 op get_namespace(out PMC, in KEY) {
-    PMC *ns_root = interpreter->stash_hash;
-    $1 = VTABLE_get_pmc_keyed(interpreter, ns_root, $2);
+    PMC *ns_root = interpreter->stash_hash, *ns;
+    ns = VTABLE_get_pmc_keyed(interpreter, ns_root, $2);
+    $1 = ns ? ns : PMCNULL;
     goto NEXT();
 }
 

Modified: trunk/src/pmc/sub.pmc
==============================================================================
--- trunk/src/pmc/sub.pmc       (original)
+++ trunk/src/pmc/sub.pmc       Sun Mar 12 06:20:45 2006
@@ -541,8 +541,7 @@
 
 =item C<METHOD PMC* get_namespace()>
 
-Return the namespace PMC or Undef. The namespace PMC is either a
-String PMC or a Key PMC for a nested namespace.
+Return the namespace PMC, where the Sub is defined. 
 
 TODO return C<namespace_stash> instead.
 
@@ -562,8 +561,7 @@
     METHOD PMC* get_namespace() {
         struct Parrot_sub * sub = PMC_sub(SELF);
 
-        return PMC_IS_NULL(sub->namespace) ?
-            pmc_new(INTERP, enum_class_Undef) : sub->namespace;
+        return sub->namespace_stash;
     }
 
     METHOD INTVAL __get_regs_used(char *kind) {

Modified: trunk/t/pmc/namespace.t
==============================================================================
--- trunk/t/pmc/namespace.t     (original)
+++ trunk/t/pmc/namespace.t     Sun Mar 12 06:20:45 2006
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 21;
+use Parrot::Test tests => 22;
 
 =head1 NAME
 
@@ -315,25 +315,15 @@
     .include "pmctypes.pasm"
     $P0 = interpinfo .INTERPINFO_CURRENT_SUB
     $P1 = $P0."get_namespace"()
-    typeof $I0, $P1
-    if $I0 == .Key goto is_key
-    print $P1
-    print "\n"
-    .return()
-is_key:
-    print $P1
-    $P1 = shift $P1
-    $I1 = defined $P1
-    unless $I1 goto ex
-    print "::"
-    goto is_key
-ex:
+    $P2 = $P1.'name'()
+    $S0 = join '::', $P2
+    print $S0
     print "\n"
 .end
 CODE
 ok
 baz
-Foo::Bar
+::Foo::Bar
 OUTPUT
 
 SKIP: {
@@ -469,3 +459,28 @@
 3
 ::parrot::Foo
 OUTPUT
+
+pir_output_is(<<'CODE', <<'OUTPUT', "Sub.get_namespace, get_namespace");
+.sub 'main' :main
+    $P0 = find_global "Foo", "bar"
+    print "ok\n"
+    $P1 = $P0."get_namespace"()
+    $P2 = $P1.name()
+    $S0 = join '::', $P2
+    print $S0
+    print "\n"
+    $P0()
+.end
+
+.namespace ["Foo"]
+.sub 'bar'
+    $P1 = get_namespace
+    print $P1
+    print "\n"
+.end
+CODE
+ok
+::Foo
+Foo
+OUTPUT
+

Reply via email to