Browse files

[pmc] finish Exporter's 'source' and 'destination' methods

git-svn-id: https://svn.parrot.org/parrot/trunk@17801 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 8a487f9 commit ac3ceb699ee00e4e9daca0cbfd1a52564b63040b @particle particle committed Mar 28, 2007
Showing with 48 additions and 13 deletions.
  1. +24 −11 src/pmc/exporter.pmc
  2. +24 −2 t/pmc/exporter.t
View
35 src/pmc/exporter.pmc
@@ -71,15 +71,21 @@ otherwise returns the value.
PCCMETHOD void source(PMC *src :optional, int got_src :opt_flag) {
Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
- PMC *ret_ns_src;
/* TODO deal with non-namespace pmcs */
if (got_src) {
- exp->ns_src = VTABLE_clone(interp, src);
+ if (src->vtable->base_type != enum_class_NameSpace) {
+ real_exception(interp, NULL, 0,
+ "source must be a NameSpace PMC");
+ return;
+ }
+
+ exp->ns_src = src;
}
else {
- ret_ns_src = VTABLE_clone(interp, exp->ns_src);
- PCCRETURN(PMC *ret_ns_src);
+ PMC *tmp_ns_src;
+ tmp_ns_src = exp->ns_src;
+ PCCRETURN(PMC *tmp_ns_src);
}
}
@@ -97,15 +103,20 @@ otherwise returns the value.
PCCMETHOD void destination(PMC *dest :optional, int got_dest :opt_flag) {
Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
- PMC *ret_ns_dest;
/* TODO deal with non-namespace pmcs */
if (got_dest) {
- exp->ns_dest = VTABLE_clone(interp, dest);
+ if (dest->vtable->base_type != enum_class_NameSpace) {
+ real_exception(interp, NULL, 0,
+ "destination must be a NameSpace PMC");
+ return;
+ }
+ exp->ns_dest = dest;
}
else {
- ret_ns_dest = VTABLE_clone(interp, exp->ns_dest);
- PCCRETURN(PMC *ret_ns_dest);
+ PMC *tmp_ns_dest;
+ tmp_ns_dest = exp->ns_dest;
+ PCCRETURN(PMC *tmp_ns_dest);
}
}
@@ -146,10 +157,12 @@ Add C<global> to the array of globals.
*/
- PCCMETHOD void add_global(PMC *global) {
+ PCCMETHOD void add_global(PMC *global :optional, int has_global :opt_flag) {
Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
- VTABLE_push_string(interp, exp->globals,
- VTABLE_get_string(interp, global));
+ if (has_global) {
+ VTABLE_push_string(interp, exp->globals,
+ VTABLE_get_string(interp, global));
+ }
}
View
26 t/pmc/exporter.t
@@ -41,7 +41,7 @@ ok 2 - isa $P0, 'Exporter'
OUT
-pir_output_is( <<'CODE', <<'OUT', 'source', todo => 'broken' );
+pir_output_is( <<'CODE', <<'OUT', 'source' );
.sub 'test' :main
new $P0, .Exporter
$P1 = $P0.'source'()
@@ -72,16 +72,30 @@ pir_output_is( <<'CODE', <<'OUT', 'source', todo => 'broken' );
ok_3:
say 'ok 3 - source() with too many args fails'
+ push_eh ok_4
+ $P0.'source'('foo')
+ clear_eh
+ print 'not '
+
+ ok_4:
+ say 'ok 4 - source() with non-namespace arg throws exception'
+.end
+
+
+# TODO replace with make_namespace, when implemented
+.namespace ['Eponymous']
+.sub 'Eponymous' :anon
.end
CODE
ok 1 - source() with no args returns source namespace, which is empty at first
ok 2 - source() with args sets source namespace
ok 3 - source() with too many args fails
+ok 4 - source() with non-namespace arg throws exception
OUT
# TODO test passing non-namespace pmc
-pir_output_is( <<'CODE', <<'OUT', 'destination', todo => 'broken' );
+pir_output_is( <<'CODE', <<'OUT', 'destination' );
.sub 'test' :main
new $P0, .Exporter
$P1 = $P0.'destination'()
@@ -112,6 +126,13 @@ pir_output_is( <<'CODE', <<'OUT', 'destination', todo => 'broken' );
ok_3:
say 'ok 3 - destination() with too many args fails'
+ push_eh ok_4
+ $P0.'destination'('foo')
+ clear_eh
+ print 'not '
+
+ ok_4:
+ say 'ok 4 - destination() with non-namespace arg throws exception'
.end
@@ -123,6 +144,7 @@ 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
OUT
# TODO test passing non-namespace pmc

0 comments on commit ac3ceb6

Please sign in to comment.