Skip to content

Commit

Permalink
[pmc]: Exporter beginning 'import' method
Browse files Browse the repository at this point in the history
~ new add_global test
~ new import test -- FAILING! will fix asap

git-svn-id: https://svn.parrot.org/parrot/trunk@17819 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
particle committed Mar 28, 2007
1 parent 67de806 commit 2f8fa82
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
40 changes: 30 additions & 10 deletions src/pmc/exporter.pmc
Expand Up @@ -176,25 +176,45 @@ Import C<globals> from the C<src> namespace to the C<dest> namespace.

*/

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 */
}

/*
Expand Down
28 changes: 23 additions & 5 deletions t/pmc/exporter.t
Expand Up @@ -6,7 +6,7 @@ use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
use Parrot::Test tests => 5;
use Parrot::Test tests => 6;

=head1 NAME
Expand Down Expand Up @@ -92,7 +92,6 @@ 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' );
Expand Down Expand Up @@ -146,7 +145,6 @@ 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


pir_output_is( <<'CODE', <<'OUT', 'globals' );
Expand Down Expand Up @@ -221,8 +219,7 @@ ok 5 - globals() with too many args fails
OUT


## TODO add_global
pir_output_is( <<'CODE', <<'OUT', 'globals' );
pir_output_is( <<'CODE', <<'OUT', 'add_global' );
.sub 'test' :main
$P0 = new .Exporter
Expand Down Expand Up @@ -263,16 +260,37 @@ pir_output_is( <<'CODE', <<'OUT', 'globals' );
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:
Expand Down

0 comments on commit 2f8fa82

Please sign in to comment.