Author: leo
Date: Fri Mar 10 07:56:06 2006
New Revision: 11854
Modified:
trunk/src/global.c
trunk/src/pmc/coroutine.pmc
trunk/src/pmc/namespace.pmc
trunk/t/pmc/globals.t
trunk/t/pmc/namespace.t
Log:
Namespaces 14 - use NameSpace PMC for global ops
* switch existing code in src/global.c to use NameSpace vtable functions
* needs a lot more cleanup
* adjust tests, which used "\0Namespace" syntax, this hack isn't needed
anymore and is abandoned now
---
* fix Coroutine.clone - a DOD run did mark garbage, because the ptr
of the copied Parrot_coro structure was set too late
Modified: trunk/src/global.c
==============================================================================
--- trunk/src/global.c (original)
+++ trunk/src/global.c Fri Mar 10 07:56:06 2006
@@ -48,75 +48,29 @@
Parrot_find_global(Parrot_Interp interpreter, STRING *class, STRING
*globalname)
{
PMC *stash;
- STRING *ns_name;
-#if 1
- /*
- * we are cheating a bit and use Hash internals to avoid
- * hash lookup duplication
- */
- HashBucket *b;
+
#if DEBUG_GLOBAL
PIO_printf(interpreter, "find_global class '%Ss' meth '%Ss'\n",
class, globalname);
#endif
- stash = interpreter->stash_hash;
if (class) {
- ns_name = string_concat(interpreter,
- string_from_cstring(interpreter, "\0", 1),
- class, 0);
- b = hash_get_bucket(interpreter,
- (Hash*) PMC_struct_val(stash), ns_name);
- if (!b)
- return NULL;
- stash = b->value;
- if (!globalname)
- return stash;
- b = hash_get_bucket(interpreter,
- (Hash*) PMC_struct_val(stash), globalname);
- if (!b)
- return NULL;
- return (PMC*) b->value;
- }
- if (!globalname)
- return stash;
- b = hash_get_bucket(interpreter,
- (Hash*) PMC_struct_val(stash), globalname);
- if (!b)
- return NULL;
- return b->value;
-
-#else
- if (class) {
- ns_name = string_concat(interpreter,
- string_from_cstring(interpreter, "\0", 1),
- class, 0);
- if (!VTABLE_exists_keyed_str(interpreter,
- interpreter->stash_hash,
- ns_name)) {
- return NULL;
- }
stash = VTABLE_get_pmc_keyed_str(interpreter,
interpreter->stash_hash,
- ns_name);
+ class);
+ if (!stash)
+ return NULL;
}
else {
stash = interpreter->stash_hash;
+ /* TODO return relative to current namespace */
}
- if (!globalname)
- return stash;
- if (!VTABLE_exists_keyed_str(interpreter, stash, globalname)) {
- return NULL;
- }
- return VTABLE_get_pmc_keyed_str(interpreter,
+ return VTABLE_get_pointer_keyed_str(interpreter,
stash, globalname);
-#endif
}
PMC *
Parrot_find_global_p(Parrot_Interp interpreter, PMC *ns, STRING *name)
{
- PMC *stash, *ns_next;
- STRING *class, *ns_name;
if (PMC_IS_NULL(ns))
return Parrot_find_global(interpreter, NULL, name);
@@ -124,28 +78,14 @@
case enum_class_String:
return Parrot_find_global(interpreter, PMC_str_val(ns), name);
case enum_class_Key:
- stash = interpreter->stash_hash;
- while (1) {
- class = key_string(interpreter, ns);
- ns_name = string_concat(interpreter,
- string_from_cstring(interpreter, "\0", 1),
- class, 0);
- if (!VTABLE_exists_keyed_str(interpreter, stash, ns_name)) {
- return NULL;
- }
- stash = VTABLE_get_pmc_keyed_str(interpreter, stash, ns_name);
- ns_next = key_next(interpreter, ns);
- if (!ns_next)
- break;
- ns = ns_next;
- }
- return Parrot_find_global_p(interpreter, stash, name);
+ /* TODO query the class namespace directly */
+ ns = VTABLE_get_pmc_keyed(interpreter,
+ interpreter->stash_hash, ns);
+ if (!(ns))
+ return NULL;
/* fall through */
case enum_class_NameSpace:
- if (!VTABLE_exists_keyed_str(interpreter, ns, name)) {
- return NULL;
- }
- return VTABLE_get_pmc_keyed_str(interpreter, ns, name);
+ return VTABLE_get_pointer_keyed_str(interpreter, ns, name);
}
return NULL;
}
@@ -155,7 +95,7 @@
STRING *name, void *next)
{
PMC *g = Parrot_find_global(interpreter, class, name);
- if (g)
+ if (!PMC_IS_NULL(g))
return g;
if (PARROT_ERRORS_test(interpreter, PARROT_ERRORS_GLOBALS_FLAG)) {
real_exception(interpreter, next, E_NameError,
@@ -169,7 +109,7 @@
Parrot_get_global_p(Parrot_Interp interpreter, PMC *ns, STRING *name)
{
PMC *g = Parrot_find_global_p(interpreter, ns, name);
- if (g)
+ if (!PMC_IS_NULL(g))
return g;
if (PARROT_ERRORS_test(interpreter, PARROT_ERRORS_GLOBALS_FLAG)) {
real_exception(interpreter, NULL, E_NameError,
@@ -250,7 +190,6 @@
Parrot_global_namespace(Interp *interpreter, PMC *globals, STRING *class)
{
PMC *stash;
- STRING *ns_name;
/*
* this routine is called by PackFile_ConstTable_unpack too, which
@@ -259,15 +198,10 @@
* lookup dies then during mark_1_seg.
*/
Parrot_block_DOD(interpreter);
- ns_name = string_concat(interpreter,
- string_from_cstring(interpreter, "\0", 1),
- class, 0);
- if (!VTABLE_exists_keyed_str(interpreter, globals, ns_name)) {
+ stash = VTABLE_get_pmc_keyed_str(interpreter, globals, class);
+ if (!stash || stash->vtable->base_type != enum_class_NameSpace) {
stash = pmc_new(interpreter, enum_class_NameSpace);
- VTABLE_set_pmc_keyed_str(interpreter, globals, ns_name, stash);
- }
- else {
- stash = VTABLE_get_pmc_keyed_str(interpreter, globals, ns_name);
+ VTABLE_set_pmc_keyed_str(interpreter, globals, class, stash);
}
Parrot_unblock_DOD(interpreter);
return stash;
Modified: trunk/src/pmc/coroutine.pmc
==============================================================================
--- trunk/src/pmc/coroutine.pmc (original)
+++ trunk/src/pmc/coroutine.pmc Fri Mar 10 07:56:06 2006
@@ -111,10 +111,10 @@
PMC* ret = pmc_new_noinit(INTERP, SELF->vtable->base_type);
PObj_custom_mark_destroy_SETALL(ret);
sub = mem_sys_allocate(sizeof(struct Parrot_coro));
- memcpy(sub, PMC_sub(SELF), sizeof(struct Parrot_coro));
- sub->name = string_copy(INTERP, sub->name);
PMC_struct_val(ret) = sub;
PMC_pmc_val(ret) = NULL;
+ memcpy(sub, PMC_sub(SELF), sizeof(struct Parrot_coro));
+ sub->name = string_copy(INTERP, sub->name);
return ret;
}
Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc (original)
+++ trunk/src/pmc/namespace.pmc Fri Mar 10 07:56:06 2006
@@ -100,12 +100,12 @@
=item C<PMC* get_pmc_keyed(PMC *key)>
-Return the given namespace or PMCNULL. C<key> is either an array of
+Return the given namespace or NULL. C<key> is either an array of
strings, or a possibly nested key.
=item C<PMC* get_pmc_keyed_str(PMC *key)>
-Return the given namespace item or PMCNULL. If the named item is either
+Return the given namespace item or NULL. If the named item is either
a NameSpace or a var, the NameSpace is returned.
=cut
@@ -182,11 +182,11 @@
PMC *ns = hash_get(INTERP,
(Hash*) PMC_struct_val(SELF), key);
if (!ns)
- return PMCNULL;
+ return NULL;
if ((PObj_get_FLAGS(ns) & FPA_is_ns_ext) &&
ns->vtable->base_type == enum_class_FixedPMCArray)
ns = VTABLE_get_pmc_keyed_int(INTERP, ns, NS_slot_ns);
- return ns ? ns : PMCNULL;
+ return ns;
}
PMC* get_pmc_keyed(PMC *key) {
@@ -198,26 +198,48 @@
while (key) {
part = key_string(INTERP, key);
ns = VTABLE_get_pmc_keyed_str(INTERP, ns, part);
- if (ns == PMCNULL)
- return PMCNULL;
+ if (!ns)
+ return NULL;
key = key_next(INTERP, key);
}
return ns;
}
n = VTABLE_elements(INTERP, key);
if (!n)
- return PMCNULL;
+ return NULL;
for (i = 0; i < n; ++i) {
part = VTABLE_get_string_keyed_int(INTERP, key, i);
ns = VTABLE_get_pmc_keyed_str(INTERP, ns, part);
- if (ns == PMCNULL)
- return PMCNULL;
+ if (!ns)
+ return NULL;
}
return ns;
}
/*
+=item C<void* get_pointer_keyed_str(PMC *key)>
+
+Return the given namespace item or NULL. If the named item is either
+a NameSpace or a var, the var is returned.
+
+=cut
+
+*/
+
+ void* get_pointer_keyed_str (STRING* key) {
+ PMC *ns = hash_get(INTERP,
+ (Hash*) PMC_struct_val(SELF), key);
+ if (!ns)
+ return NULL;
+ if ((PObj_get_FLAGS(ns) & FPA_is_ns_ext) &&
+ ns->vtable->base_type == enum_class_FixedPMCArray)
+ ns = VTABLE_get_pmc_keyed_int(INTERP, ns, NS_slot_var_sub);
+ return ns;
+ }
+
+/*
+
=item C<STRING* get_string()>
Return the name of this namespace part.
Modified: trunk/t/pmc/globals.t
==============================================================================
--- trunk/t/pmc/globals.t (original)
+++ trunk/t/pmc/globals.t Fri Mar 10 07:56:06 2006
@@ -25,9 +25,7 @@
pir_output_is(<<'CODE', <<'OUTPUT', "get namespace");
.sub main
.local pmc ns, o
- .local string nul
- null nul
- ns = find_global "Foo", nul
+ ns = find_global "Foo"
o = find_global ns, "f"
o()
.end
@@ -58,12 +56,9 @@
pir_output_is(<<'CODE', <<'OUTPUT', "get namespace - nested");
.sub main
- .local pmc ns, ns2, o
- .local string nul
- null nul
- ns = find_global "Foo", nul
- ns2 = find_global ns, "\0Bar"
- o = find_global ns2, "f"
+ .local pmc ns, o
+ ns = get_namespace ["Foo"; "Bar"]
+ o = find_global ns, "f"
o()
.end
Modified: trunk/t/pmc/namespace.t
==============================================================================
--- trunk/t/pmc/namespace.t (original)
+++ trunk/t/pmc/namespace.t Fri Mar 10 07:56:06 2006
@@ -39,7 +39,7 @@
pir_output_is(<<'CODE', <<'OUTPUT', "verify NameSpace type");
.sub 'main' :main
- $P0 = find_global "\0Foo"
+ $P0 = find_global "Foo"
typeof $S0, $P0
print $S0
print "\n"
@@ -104,7 +104,7 @@
pir_output_is(<<'CODE', <<'OUTPUT', "find_global Foo::bar hash");
.sub 'main' :main
- $P0 = find_global "\0Foo"
+ $P0 = find_global "Foo"
$P1 = $P0["bar"]
print "ok\n"
$P1()
@@ -123,7 +123,7 @@
.sub 'main' :main
.include "interpinfo.pasm"
$P0 = interpinfo .INTERPINFO_NAMESPACE_ROOT
- $P1 = $P0["\0Foo"]
+ $P1 = $P0["Foo"]
$P2 = $P1["bar"]
print "ok\n"
$P2()
@@ -156,8 +156,8 @@
pir_output_is(<<'CODE', <<'OUTPUT', "find_global Foo::Bar::baz hash");
.sub 'main' :main
- $P0 = find_global "\0Foo"
- $P1 = $P0["\0Bar"]
+ $P0 = find_global "Foo"
+ $P1 = $P0["Bar"]
$P2 = $P1["baz"]
print "ok\n"
$P2()
@@ -174,8 +174,8 @@
pir_output_is(<<'CODE', <<'OUTPUT', "find_global Foo::Bar::baz hash 2");
.sub 'main' :main
- $P0 = find_global "\0Foo"
- $P1 = $P0["\0Bar" ; "baz"]
+ $P0 = find_global "Foo"
+ $P1 = $P0["Bar" ; "baz"]
print "ok\n"
$P1()
.end
@@ -193,7 +193,7 @@
.sub 'main' :main
.include "interpinfo.pasm"
$P0 = interpinfo .INTERPINFO_NAMESPACE_ROOT
- $P1 = $P0["\0Foo";"\0Bar" ; "baz"]
+ $P1 = $P0["Foo";"Bar" ; "baz"]
print "ok\n"
$P1()
.end
@@ -209,9 +209,9 @@
pir_output_is(<<'CODE', <<'OUTPUT', "find_global Foo::Bar::baz alias");
.sub 'main' :main
- $P0 = find_global "\0Foo"
- $P1 = $P0["\0Bar"]
- store_global "\0TopBar", $P1
+ $P0 = find_global "Foo"
+ $P1 = $P0["Bar"]
+ store_global "TopBar", $P1
$P2 = find_global "TopBar", "baz"
print "ok\n"
$P2()
@@ -301,8 +301,8 @@
pir_output_is(<<'CODE', <<'OUTPUT', "get namespace in Foo::Bar::baz");
.sub 'main' :main
- $P0 = find_global "\0Foo"
- $P1 = find_global $P0, "\0Bar"
+ $P0 = find_global "Foo"
+ $P1 = find_global $P0, "Bar"
$P2 = find_global $P1, "baz"
print "ok\n"
$P2()