Author: leo
Date: Wed Mar 8 04:25:16 2006
New Revision: 11822
Modified:
trunk/src/pmc/namespace.pmc
trunk/t/pmc/namespace.t
Log:
Namespaces 9 - implement NameSpace.name()
* see also the comments in src/pmc/namespace.pmc
* test
Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc (original)
+++ trunk/src/pmc/namespace.pmc Wed Mar 8 04:25:16 2006
@@ -56,6 +56,11 @@
will be set as the parent of that namespace and the name C<key> of
C<value> is stored too.
+=item C<void set_pmc_keyed(PMC *key, PMC *value)>
+
+If C<key> is a simple key, it works like above. If C<key> is an array
+of strings or a chained key, add all components to the namespace.
+
=cut
*/
@@ -68,6 +73,17 @@
}
}
+ void set_pmc_keyed(PMC *key, PMC *value) {
+ switch (PObj_get_FLAGS(key) & KEY_type_FLAGS) {
+ case KEY_string_FLAG:
+ SELF.set_pmc_keyed_str(key_string(INTERP, key), value);
+ if (!key_next(INTERP, key))
+ break;
+ default:
+ assert("not yet" != NULL);
+ }
+ }
+
/*
=item C<STRING* get_string()>
@@ -82,6 +98,45 @@
return PMC_data(SELF);
}
+/*
+
+=back
+
+=head2 Methods
+
+=over 4
+
+=cut
+
+*/
+
+/*
+
+=item C<METHOD PMC* name()>
+
+Returns the name of the namespace as an array of strings.
+
+XXX Should the NULL String of namespace root be included?
+ See also t/pmc/namespace_20.pir.
+
+ $P2 = $P3.'name'()
+ $S0 = join '::', $P2 # '::Foo::Bar'
+
+=cut
+
+*/
+
+ METHOD PMC* name() {
+ PMC *ar, *ns;
+
+ ar = pmc_new(INTERP, enum_class_ResizableStringArray);
+ ns = SELF;
+ while (ns) {
+ VTABLE_unshift_string(INTERP, ar, PMC_data(ns));
+ ns = PMC_pmc_val(ns);
+ }
+ return ar;
+ }
}
/*
Modified: trunk/t/pmc/namespace.t
==============================================================================
--- trunk/t/pmc/namespace.t (original)
+++ trunk/t/pmc/namespace.t Wed Mar 8 04:25:16 2006
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 19;
+use Parrot::Test tests => 20;
=head1 NAME
@@ -409,3 +409,24 @@
NameSpace
OUTPUT
+pir_output_is(<<'CODE', <<'OUTPUT', "ns.name()");
+.sub main :main
+ .include "interpinfo.pasm"
+ $P0 = interpinfo .INTERPINFO_NAMESPACE_ROOT
+ $P1 = $P0["parrot"]
+ $P3 = new .NameSpace
+ $P1["Foo"] = $P3
+ $P2 = $P3.'name'()
+ $I2 = elements $P2
+ print $I2
+ print "\n"
+ $S0 = join '::', $P2
+ print $S0
+ print "\n"
+.end
+# namespace root doesnt have a name
+# XXX should the root namespace be included?
+CODE
+3
+::parrot::Foo
+OUTPUT