Author: leo
Date: Tue Mar 7 11:39:25 2006
New Revision: 11815
Modified:
trunk/src/hll.c
trunk/src/pmc/namespace.pmc
trunk/t/pmc/namespace.t
Log:
Namespaces 6 - remember namespace parent and name
* NameSpace.set_pmc_keyed_str stores now parent and name of the
child namespace
* test with parrot namespace
Modified: trunk/src/hll.c
==============================================================================
--- trunk/src/hll.c (original)
+++ trunk/src/hll.c Tue Mar 7 11:39:25 2006
@@ -110,7 +110,7 @@
* a namespace in HLL's flavor yet - mabe promote the
* ns_hash to another type, if mappings provide one
*
- * TODO need better APIT to append namespaces
+ * TODO need better API to append namespaces
*/
ns_hash = pmc_new(interpreter, enum_class_NameSpace);
VTABLE_set_pmc_keyed_str(interpreter, interpreter->stash_hash,
Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc (original)
+++ trunk/src/pmc/namespace.pmc Tue Mar 7 11:39:25 2006
@@ -13,9 +13,9 @@
=head2 Data
PMC_struct_val ... the hash, bucket->value is an array
- of 3 PMCs (namespace, sub, var) slot
+ of 3 PMCs (namespace, sub, var) slot ???
PMC_pmc_val ... parent namespace
- PMC_data ... name string of this namespace part
+ PMC_data ... name STRING of this namespace part
=head2 Functions
@@ -30,14 +30,56 @@
pmclass NameSpace extends Hash need_ext {
- voit init {
+/*
+
+=item C<voit init()>
+
+Initialze a C<NameSpace> PMC by calling C<Hash.init> and clearing
+other fields.
+
+=cut
+
+*/
+
+ void init() {
SUPER(); /* _struct_val := Hash */
PMC_pmc_val(SELF) = NULL; /* parent */
PMC_data(SELF) = NULL; /* namespace name */
}
- PMC* namespace() {
- return SELF;
+/*
+
+=item C<void set_pmc_keyed_str(STRING *key, PMC *value)>
+
+Sets C<*value> as the namespace item for C<*key>. This is part of the
+raw interface. If the PMC C<value> is exactly a NameSpace, C<SELF>
+will be set as the parent of that namespace and the name C<key> of
+C<value> is stored too.
+
+=cut
+
+*/
+
+ void set_pmc_keyed_str(STRING *key, PMC *value) {
+ SUPER(key, value);
+ if (value->vtable->base_type == enum_class_NameSpace) {
+ PMC_pmc_val(value) = SELF; /* set parent */
+ PMC_data(value) = key; /* and name */
+ }
+ }
+
+/*
+
+=item C<STRING* get_string()>
+
+Return the name of this namespace part.
+
+=cut
+
+*/
+
+ STRING* get_string() {
+ return PMC_data(SELF);
}
}
Modified: trunk/t/pmc/namespace.t
==============================================================================
--- trunk/t/pmc/namespace.t (original)
+++ trunk/t/pmc/namespace.t Tue Mar 7 11:39:25 2006
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 18;
+use Parrot::Test tests => 19;
=head1 NAME
@@ -52,6 +52,7 @@
CODE
NameSpace
OUTPUT
+
pir_output_is(<<'CODE', <<'OUTPUT', "find_global Foo::bar");
.sub 'main' :main
$P0 = find_global "Foo", "bar"
@@ -387,3 +388,24 @@
unicode namespaces are fun
OUT
+pir_output_is(<<'CODE', <<'OUTPUT', "verify root and parrot namespaces");
+# name may change though
+.sub main :main
+ .include "interpinfo.pasm"
+ $P0 = interpinfo .INTERPINFO_NAMESPACE_ROOT
+ typeof $S0, $P0
+ print $S0
+ print "\n"
+ $P1 = $P0["parrot"]
+ print $P1
+ print "\n"
+ typeof $S0, $P1
+ print $S0
+ print "\n"
+.end
+CODE
+NameSpace
+parrot
+NameSpace
+OUTPUT
+