Permalink
Browse files

[pmc]: Exporter

~ 'destination' is now set to current namespace upon initialization
  (this is what you usually want)
~ 'globals' now supports either a space-separated string or a string array as input

git-svn-id: https://svn.parrot.org/parrot/trunk@18003 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent c89b859 commit 4b47d4cf3c8cb50dca2c2fd22e257e07e2b5e297 @particle particle committed Apr 5, 2007
Showing with 33 additions and 33 deletions.
  1. +11 −18 src/pmc/exporter.pmc
  2. +22 −15 t/pmc/exporter.t
View
@@ -29,7 +29,7 @@ An empty PMC of this type is allocated upon initialization.
=item C<ns_dest>
The destination namespace -- a NameSpace PMC.
-An empty PMC of this type is allocated upon initialization.
+A PMC representing the current namespace is allocated upon initialization.
=item C<globals>
@@ -86,7 +86,7 @@ Instantiates an Exporter.
/* Set up the object. */
exp = mem_sys_allocate_zeroed(sizeof (Parrot_Exporter));
exp->ns_src = pmc_new(interp, enum_class_NameSpace);
- exp->ns_dest = pmc_new(interp, enum_class_NameSpace);
+ exp->ns_dest = CONTEXT(interp->ctx)->current_namespace;
exp->globals = PMCNULL;
PMC_data(SELF) = exp;
}
@@ -211,33 +211,26 @@ Sets the array if C<glb> is passed, otherwise returns the value.
If C<glb> is a String, it is split on ascii whitespace.
If C<glb> is a FixedStringArray, it is cloned and set.
-TODO: get MMD working
-
=cut
*/
PCCMETHOD void globals(PMC *glb :optional, int got_glb :opt_flag) {
Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
PMC *ret_globals;
+ STRING *s_str = CONST_STRING(interp, "String");
+ STRING *s_fsa = CONST_STRING(interp, "FixedStringArray");
if (got_glb) {
- if (PMC_IS_NULL(glb)) {
+ if (PMC_IS_NULL(glb))
exp->globals = PMCNULL;
- }
- else {
-/* xxx_MMD_FixedStringArray: { */
- exp->globals = VTABLE_clone(interp, glb);
-/* }
-xxx_MMD_String: {
+ else if (VTABLE_isa(interp, glb, s_str))
exp->globals = string_split(interp, ' ', glb);
- }
-xxx_MMD_DEFAULT: {
+ else if (VTABLE_isa(interp, glb, s_fsa))
+ exp->globals = VTABLE_clone(interp, glb);
+ else
real_exception(interp, NULL, 0,
- "unrecognized type in MMD dispatch");
- }
-*/
- }
+ "Invalid type %d in globals()", glb->vtable->base_type);
}
else {
if (PMC_IS_NULL(exp->globals)) {
@@ -257,7 +250,7 @@ xxx_MMD_DEFAULT: {
add_global(PMC *global :optional, int has_global :opt_flag)>
Add C<global> to the array of globals (C<globals>.)
-Sets the array if C<glb_array> is passed, otherwise does nothing.
+Sets the array if C<global> is passed, otherwise does nothing.
=cut
View
@@ -98,10 +98,16 @@ pir_output_is( <<'CODE', <<'OUT', 'destination' );
.sub 'test' :main
new $P0, .Exporter
$P1 = $P0.'destination'()
- if $P1 == '' goto ok_1
+ unless null $P1 goto ok_1
print 'not '
ok_1:
- say 'ok 1 - destination() with no args returns destination namespace, which is empty at first'
+ say 'ok 1 - destination() with no args returns destination namespace'
+
+ $P99 = get_namespace
+ if $P1 == $P99 goto ok_2
+ print 'not '
+ ok_2:
+ say 'ok 2 - ...which is current namespace at first'
# get a NameSpace PMC for testing
# TODO replace with make_namespace, when implemented
@@ -110,28 +116,28 @@ pir_output_is( <<'CODE', <<'OUT', 'destination' );
$P0.'destination'(ns)
$P1 = $P0.'destination'()
- if $P1 == 'Eponymous' goto ok_2
+ if $P1 == 'Eponymous' goto ok_3
print 'not '
- ok_2:
- say 'ok 2 - destination() with args sets destination namespace'
+ ok_3:
+ say 'ok 3 - destination() with args sets destination namespace'
$P1 = clone ns
- push_eh ok_3
+ push_eh ok_4
$P0.'destination'(ns, $P1)
clear_eh
print 'not '
- ok_3:
- say 'ok 3 - destination() with too many args fails'
+ ok_4:
+ say 'ok 4 - destination() with too many args fails'
- push_eh ok_4
+ push_eh ok_5
$P0.'destination'('foo')
clear_eh
print 'not '
- ok_4:
- say 'ok 4 - destination() with non-namespace arg throws exception'
+ ok_5:
+ say 'ok 5 - destination() with non-namespace arg throws exception'
.end
@@ -140,10 +146,11 @@ pir_output_is( <<'CODE', <<'OUT', 'destination' );
.sub 'Eponymous' :anon
.end
CODE
-ok 1 - destination() with no args returns destination namespace, which is empty at first
-ok 2 - destination() with args sets destination namespace
-ok 3 - destination() with too many args fails
-ok 4 - destination() with non-namespace arg throws exception
+ok 1 - destination() with no args returns destination namespace
+ok 2 - ...which is current namespace at first
+ok 3 - destination() with args sets destination namespace
+ok 4 - destination() with too many args fails
+ok 5 - destination() with non-namespace arg throws exception
OUT

0 comments on commit 4b47d4c

Please sign in to comment.