Author: particle
Date: Wed Mar 28 16:53:04 2007
New Revision: 17819
Modified:
trunk/src/pmc/exporter.pmc
trunk/t/pmc/exporter.t
Log:
[pmc]: Exporter beginning 'import' method
~ new add_global test
~ new import test -- FAILING! will fix asap
Modified: trunk/src/pmc/exporter.pmc
==============================================================================
--- trunk/src/pmc/exporter.pmc (original)
+++ trunk/src/pmc/exporter.pmc Wed Mar 28 16:53:04 2007
@@ -176,25 +176,45 @@
*/
- PCCMETHOD void import(PMC *dest, PMC *src, PMC *globals) {
+ PCCMETHOD void import(PMC *dest :optional :named["destination"], int
got_dest :opt_flag,
+ PMC *src :optional :named["source"], int got_src :opt_flag,
+ PMC *globals :optional :named["globals"], int got_globals
:opt_flag) {
+/*
+ * notes:
+ * passed params override current values, so set them before using them
+ * check if any values are null before using them, and throw if so
+ * for each global,
+ * find global in source namespace, throw exception if not found
+ * find global in destination namespace, throw warning if found
+ * store global in destination namespace
+ */
+
Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
- int size_globals;
+ int copy_of_globals;
+
+ if (got_src)
+ PCCINVOKE(interp, SELF, "source", PMC *src);
+ if (got_dest)
+ PCCINVOKE(interp, SELF, "destination", PMC *dest);
+ if (got_globals)
+ PCCINVOKE(interp, SELF, "globals", PMC *globals);
if (exp->globals == PMCNULL) {
real_exception(interp, NULL, 0, "no globals to import");
+ return;
}
- else if (exp->ns_src == PMCNULL) {
+ if (exp->ns_src == PMCNULL) {
real_exception(interp, NULL, 0, "source namespace not set");
+ return;
}
- else if (exp->ns_dest == PMCNULL) {
+ if (exp->ns_dest == PMCNULL) {
real_exception(interp, NULL, 0, "destination namespace not set");
+ return;
}
- else {
- size_globals = VTABLE_get_integer(interp, exp->globals);
- if (!size_globals)
- return;
- /* TODO for each global, look up in source and alias to dest */
- }
+
+ copy_of_globals = VTABLE_get_integer(interp, exp->globals);
+ return;
+ /* TODO for each global, look up in source and alias to dest */
}
/*
Modified: trunk/t/pmc/exporter.t
==============================================================================
--- trunk/t/pmc/exporter.t (original)
+++ trunk/t/pmc/exporter.t Wed Mar 28 16:53:04 2007
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 5;
+use Parrot::Test tests => 6;
=head1 NAME
@@ -92,7 +92,6 @@
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' );
@@ -146,7 +145,6 @@
ok 3 - destination() with too many args fails
ok 4 - destination() with non-namespace arg throws exception
OUT
-# TODO test passing non-namespace pmc
pir_output_is( <<'CODE', <<'OUT', 'globals' );
@@ -221,8 +219,7 @@
OUT
-## TODO add_global
-pir_output_is( <<'CODE', <<'OUT', 'globals' );
+pir_output_is( <<'CODE', <<'OUT', 'add_global' );
.sub 'test' :main
$P0 = new .Exporter
@@ -263,16 +260,37 @@
print 'not '
ok_3:
say 'ok 3 - add_global() with args adds string to globals array (again)'
+
+ push_eh ok_4
+ $P0.'globals'($P99, $P98)
+ clear_eh
+
+ print 'not '
+ ok_4:
+ say 'ok 4 - add_global() with too many args fails'
+
.end
CODE
ok 1 - add_global() with no args does nothing
ok 2 - add_global() with args adds string to globals array
ok 3 - add_global() with args adds string to globals array (again)
+ok 4 - add_global() with too many args fails
OUT
## TODO import
+pir_output_is( <<'CODE', <<'OUT', 'import' );
+.sub 'test' :main
+ $P0 = new .Exporter
+
+ $P0.'import'()
+ say 'ok 1 - import() with no args does nothing'
+.end
+CODE
+ok 1 - import() with no args does nothing
+OUT
+# Parrot_free_context
# Local Variables: