# New Ticket Created by  Jerry Gay 
# Please include the string:  [perl #41235]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41235 >


i'm sending this to rt so it doesn't get lost. i want it in before
0.4.8 next week.
~jerry

---------- Forwarded message ----------
From: chromatic <[EMAIL PROTECTED]>
Date: Dec 25, 2006 1:44 PM
Subject: [PATCH] Add get_name() Method to Namespaces
To: [EMAIL PROTECTED]


Here's a patch to implement get_name(), as specified in PDD 21.  I haven't
checked it in because it includes an API change.  There was already a name()
method in namespaces; I renamed it per the PDD.

-- c
=== src/interpreter.c
==================================================================
--- src/interpreter.c	(revision 852)
+++ src/interpreter.c	(local)
@@ -673,7 +673,7 @@
 
 Run parrot operations of loaded code segment until an end opcode is
 reached run core is selected depending on the C<Interp_flags> when a
-C<restart> opcode is encountered a different core my be selected and
+C<restart> opcode is encountered, a different core may be selected and
 evaluation of opcode continues.
 
 =cut
=== src/ops/experimental.ops
==================================================================
--- src/ops/experimental.ops	(revision 852)
+++ src/ops/experimental.ops	(local)
@@ -2,7 +2,7 @@
 ** experimental.ops
 */
 
-extern PMC* Parrot_NameSpace_name(Interp* interp, PMC* pmc);
+extern PMC* Parrot_NameSpace_get_name(Interp* interp, PMC* pmc);
 
 VERSION = PARROT_VERSION;
 
@@ -255,7 +255,7 @@
 =cut
 
 op classname(out PMC, invar PMC) :object_base {
-    PMC *ns = Parrot_NameSpace_name(interp,
+    PMC *ns = Parrot_NameSpace_get_name(interp,
                                     VTABLE_namespace(interp, $2));
     if (PMC_IS_NULL(ns) || VTABLE_elements(interp, ns) < 2)
     {
=== src/pmc/namespace.pmc
==================================================================
--- src/pmc/namespace.pmc	(revision 852)
+++ src/pmc/namespace.pmc	(local)
@@ -305,18 +305,18 @@
 
 /*
 
-=item C<METHOD PMC* name()>
+=item C<METHOD PMC* get_name()>
 
 Returns the name of the namespace as an array of strings.
 
-  $P2 = $P3.'name'()
+  $P2 = $P3.'get_name'()
   $S0 = join '::', $P2            # '::Foo::Bar'
 
 =cut
 
 */
 
-    METHOD PMC* name() {
+    METHOD PMC* get_name() {
         PMC *ar, *ns;
 
         ar = pmc_new(INTERP, enum_class_ResizableStringArray);
@@ -376,7 +376,7 @@
         if (VTABLE_isa(INTERP, sub, s_sub))
             return sub;
 
-                return PMCNULL;
+        return PMCNULL;
     }
 
 /*
=== src/sub.c
==================================================================
--- src/sub.c	(revision 852)
+++ src/sub.c	(local)
@@ -273,7 +273,7 @@
 /* XXX use method lookup - create interface
  *                         see also pbc.c
  */
-extern PMC* Parrot_NameSpace_name(Interp *interp, PMC* pmc);
+extern PMC* Parrot_NameSpace_get_name(Interp *interp, PMC* pmc);
 
 STRING*
 Parrot_full_sub_name(Interp *interp, PMC* sub)
@@ -293,7 +293,7 @@
         STRING *j;
 
         Parrot_block_DOD(interp);
-        ns_array = Parrot_NameSpace_name(interp, s->namespace_stash);
+        ns_array = Parrot_NameSpace_get_name(interp, s->namespace_stash);
         if (s->name) {
             VTABLE_push_string(interp, ns_array, s->name);
         }
=== t/pmc/namespace.t
==================================================================
--- t/pmc/namespace.t	(revision 852)
+++ t/pmc/namespace.t	(local)
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 39;
+use Parrot::Test tests => 40;
 use Parrot::Config;
 
 =head1 NAME
@@ -266,7 +266,7 @@
 .namespace ['lib']
 .sub main :main :anon
     $P0 = get_namespace
-    $P0 = $P0.'name'()
+    $P0 = $P0.'get_name'()
     $S0 = join "::", $P0
     say $S0
     end
@@ -313,7 +313,7 @@
     .include "pmctypes.pasm"
     $P0 = interpinfo .INTERPINFO_CURRENT_SUB
     $P1 = $P0."get_namespace"()
-    $P2 = $P1.'name'()
+    $P2 = $P1.'get_name'()
     $S0 = join '::', $P2
     print $S0
     print "\n"
@@ -403,7 +403,7 @@
     $P1 = $P0["parrot"]
     $P3 = new .NameSpace
     $P1["Foo"] = $P3
-    $P2 = $P3.'name'()
+    $P2 = $P3.'get_name'()
     $I2 = elements $P2
     print $I2
     print "\n"
@@ -426,7 +426,7 @@
     $P4 = 1
     $P4[0] = 'Foo'
     $P0 = get_hll_namespace $P4
-    $P2 = $P0.'name'()
+    $P2 = $P0.'get_name'()
     $I2 = elements $P2
     print $I2
     print "\n"
@@ -435,7 +435,7 @@
     print "\n"
     # fetch w key
     $P2 = get_hll_namespace ["Foo"]
-    $P2 = $P2.'name'()
+    $P2 = $P2.'get_name'()
     $I2 = elements $P2
     print $I2
     print "\n"
@@ -455,7 +455,7 @@
     $P0 = find_global "Foo", "bar"
     print "ok\n"
     $P1 = $P0."get_namespace"()
-    $P2 = $P1.name()
+    $P2 = $P1.'get_name'()
     $S0 = join '::', $P2
     print $S0
     print "\n"
@@ -909,6 +909,96 @@
 Didn't find root namespace 'Foo'.
 OUTPUT
 
+pir_output_is( <<'CODE', <<'OUTPUT', 'get_name()' );
+
+.sub create_nested_key
+    .param string name
+    .param pmc other_names :slurpy
+
+    .local pmc key
+    key = new .Key
+    key = name
+
+    .local int elem
+    elem = other_names
+
+    if elem goto nested
+    .return( key )
+
+  nested:
+    .local pmc tail
+    tail = create_nested_key(other_names :flat)
+    push key, tail
+
+    .return( key )
+.end
+
+.sub main :main
+    .local pmc key
+    key = create_nested_key( 'SingleName' )
+    print_namespace( key )
+
+    key = create_nested_key( 'Nested', 'Name', 'Space' )
+    print_namespace( key )
+
+    key = get_namespace
+
+    .local pmc ns
+    ns = key.'get_name'()
+
+    .local string ns_name
+    ns_name = join ';', ns
+    print ns_name
+    print "\n"
+.end
+
+.sub 'print_namespace'
+    .param pmc key
+
+    .local pmc get_ns
+    get_ns = find_global key, 'get_namespace'
+
+    .local pmc ns
+    ns = get_ns()
+
+    .local pmc name_array
+    name_array = ns.'get_name'()
+
+    .local string name
+    name = join ';', name_array
+
+    print name
+    print "\n"
+.end
+
+.sub get_namespace
+    .local pmc ns
+    ns = get_namespace
+    .return( ns )
+.end
+
+.namespace [ 'SingleName' ]
+
+.sub get_namespace
+    .local pmc ns
+    ns = get_namespace
+    .return( ns )
+.end
+
+.namespace [ 'Nested'; 'Name'; 'Space' ]
+
+.sub get_namespace
+    .local pmc ns
+    ns = get_namespace
+    .return( ns )
+.end
+
+CODE
+parrot;SingleName
+parrot;Nested;Name;Space
+parrot
+OUTPUT
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4

Reply via email to