Author: tene
Date: Mon Dec 29 19:29:09 2008
New Revision: 34604
Modified:
trunk/src/pmc/namespace.pmc
trunk/t/pmc/namespace.t
Log:
[core]: Add 'make_namespace' method to NameSpace PMC (RT #56616)
Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc (original)
+++ trunk/src/pmc/namespace.pmc Mon Dec 29 19:29:09 2008
@@ -535,6 +535,25 @@
/*
+=item C<METHOD make_namespace(PMC* key)>
+
+Create and retrieve the namespace given by C<key>. If the namespace
+already exists, only retrieve it.
+
+=cut
+
+*/
+
+ METHOD make_namespace(PMC *key) {
+ PMC *ns = Parrot_get_namespace_keyed(INTERP, SELF, key);
+ if (PMC_IS_NULL(ns)) {
+ ns = Parrot_make_namespace_keyed(INTERP, SELF, key);
+ }
+ RETURN(PMC *ns);
+ }
+
+/*
+
=item C<METHOD add_namespace(STRING *name, PMC *namespace)>
Stores the given namespace under this namespace, with the given name. Throws
Modified: trunk/t/pmc/namespace.t
==============================================================================
--- trunk/t/pmc/namespace.t (original)
+++ trunk/t/pmc/namespace.t Mon Dec 29 19:29:09 2008
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 65;
+use Parrot::Test tests => 66;
use Parrot::Config;
=head1 NAME
@@ -1769,6 +1769,24 @@
OK
OUT
+pir_output_is( <<'CODE', <<'OUT', "make_namespace method");
+.sub 'main' :main
+ $P0 = split ';', 'perl6;Foo;Bar'
+ $P1 = get_root_namespace
+ $P2 = $P1.'make_namespace'($P0)
+ $I0 = isa $P2, 'NameSpace'
+ say $I0
+ $P3 = get_root_namespace ['perl6';'Foo';'Bar']
+ $I0 = isnull $P3
+ say $I0
+ $I0 = issame $P2, $P3
+ say $I0
+.end
+CODE
+1
+0
+1
+OUT
# Local Variables:
# mode: cperl