Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First cut of importing from :DEFAULT one use. Wrong and incomplete, b…
…ut a start at least. Also, per S11 (or as far as I understand it), multis want to get :DEFAULT automatically, so add that.
  • Loading branch information
jnthn committed Mar 20, 2009
1 parent ec0db22 commit e38edf9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
57 changes: 56 additions & 1 deletion src/builtins/eval.pir
Expand Up @@ -141,7 +141,62 @@ itself can be found in src/builtins/control.pir.
.param pmc args :slurpy
.param pmc options :slurpy :named

$P0 = 'require'(module, 'module'=>1)
# Require module.
.local pmc retval
retval = 'require'(module, 'module'=>1)
unless null retval goto have_retval
retval = '!FAIL'()
have_retval:
if retval goto do_import
.return (retval)
do_import:

# This is a first cut of import. It's essentially wrong, since it's meant
# by default to put stuff into the lexical pad rather than the namespace.
# However, it works as a first cut, and lexical stuff isn't quite there
# enough in Rakudo yet.

# See if we've had a namespace name passed in.
.local pmc import_ns
.local pmc compiler_obj
compiler_obj = compreg 'Perl6'
$P0 = options['import_to']
if null $P0 goto use_caller_ns
$S0 = $P0
if $S0 == "" goto use_hll_root_ns
$P1 = compiler_obj.'parse_name'($S0)
$S0 = pop $P1
import_ns = get_hll_global $P1, $S0
goto got_import_ns
use_hll_root_ns:
import_ns = get_hll_namespace
goto got_import_ns
use_caller_ns:
$P0 = new 'ParrotInterpreter'
$P0 = $P0['sub'; 1]
import_ns = $P0.'get_namespace'()
got_import_ns:

# Look up symbols to import by default.
.local pmc export_ns
$P0 = compiler_obj.'parse_name'(module)
push $P0, 'EXPORT'
export_ns = get_hll_global $P0, 'DEFAULT'
if null export_ns goto done_import

# Iterate over them and import.
.local pmc it
it = iter export_ns
it_loop:
unless it goto it_loop_end
$S0 = shift it
$P0 = export_ns[$S0]
import_ns[$S0] = $P0
goto it_loop
it_loop_end:

done_import:
.return (retval)
.end


Expand Down
12 changes: 12 additions & 0 deletions src/builtins/guts.pir
Expand Up @@ -873,6 +873,18 @@ in an ambiguous multiple dispatch.
arg_done:
ns = exportns.'make_namespace'('ALL')
ns[blockname] = block

# If it's a multi-sub then we need to export it by default always.
$P0 = block.'get_namespace'()
block = $P0[blockname]
$I0 = isa block, 'MultiSub'
unless $I0 goto not_multi
ns = exportns['DEFAULT']
unless null ns goto have_default
ns = exportns.'make_namespace'('DEFAULT')
have_default:
ns[blockname] = block
not_multi:
.end


Expand Down
3 changes: 2 additions & 1 deletion src/parser/actions.pm
Expand Up @@ -386,7 +386,8 @@ method use_statement($/) {
);
## ...and load it immediately to get its BEGIN semantics
## and symbols for the current compilation.
use($name);
our @?NS;
use($name, :import_to(@?NS ?? @?NS[0] !! ''));
}
$past := PAST::Stmts.new( :node($/) );
make $past;
Expand Down

0 comments on commit e38edf9

Please sign in to comment.