-
-
Save FROGGS/59b7f7a890381005eda7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Perl6/Grammar.nqp b/src/Perl6/Grammar.nqp | |
index 42dde04..5aeed52 100644 | |
--- a/src/Perl6/Grammar.nqp | |
+++ b/src/Perl6/Grammar.nqp | |
@@ -1156,10 +1156,14 @@ grammar Perl6::Grammar is HLL::Grammar does STD { | |
$<doc>=[ 'DOC' \h+ ]? | |
<sym> <.ws> | |
[ | |
- | <version> | |
+ | <version> [ <?{ ~$<version><vnum>[0] eq '5' }> { | |
+ my $module := $*W.load_module($/, 'Perl5', $*GLOBALish); | |
+ do_import($/, $module, 'Perl5'); | |
+ $/.CURSOR.import_EXPORTHOW($module); | |
+ } ]? | |
| <module_name> | |
{ | |
- $longname := $<module_name><longname>; | |
+ $longname := $<module_name><longname><name>; | |
# Some modules are handled in the actions are just turn on a | |
# setting of some kind. | |
@@ -1195,9 +1199,22 @@ grammar Perl6::Grammar is HLL::Grammar does STD { | |
|| { | |
unless ~$<doc> && !%*COMPILING<%?OPTIONS><doc> { | |
if $longname { | |
+ my %options; | |
+ for $<module_name><longname><colonpair> -> $colonpair { | |
+ my $pair := $*W.compile_time_evaluate($/, | |
+ $colonpair.ast); | |
+ my $key := nqp::unbox_s($pair.key); | |
+ my $value := nqp::unbox_s($pair.value); | |
+ %options{ $key } := $value; | |
+ } | |
my $module := $*W.load_module($/, | |
~$longname, | |
- $*GLOBALish); | |
+ $*GLOBALish, | |
+ :name(%options<name>), | |
+ :file(%options<file>), | |
+ :from(%options<from>), | |
+ :auth(%options<auth>), | |
+ :ver(%options<ver>)); | |
do_import($/, $module, ~$longname); | |
$/.CURSOR.import_EXPORTHOW($module); | |
} | |
@@ -1239,13 +1256,11 @@ grammar Perl6::Grammar is HLL::Grammar does STD { | |
$*W.import($/, $EXPORT{$tag}, $package_source_name); | |
} | |
} | |
- if +@positional_imports { | |
- if nqp::existskey($module, '&EXPORT') { | |
- $module<&EXPORT>(|@positional_imports); | |
- } | |
- else { | |
- nqp::die("Error while importing from '$package_source_name': no EXPORT sub, but you provided positional argument in the 'use' statement"); | |
- } | |
+ if nqp::existskey($module, '&EXPORT') { | |
+ $module<&EXPORT>(|@positional_imports); | |
+ } | |
+ elsif +@positional_imports { | |
+ nqp::die("Error while importing from '$package_source_name': no EXPORT sub, but you provided positional argument in the 'use' statement"); | |
} | |
} | |
} | |
diff --git a/src/Perl6/ModuleLoader.nqp b/src/Perl6/ModuleLoader.nqp | |
index 9cf8cc4..fe07280 100644 | |
--- a/src/Perl6/ModuleLoader.nqp | |
+++ b/src/Perl6/ModuleLoader.nqp | |
@@ -114,7 +114,7 @@ class Perl6::ModuleLoader { | |
@candidates | |
} | |
- method load_module($module_name, *@GLOBALish, :$line, :$file?) { | |
+ method load_module($module_name, *@GLOBALish, :$line, :$name?, :$file?, :$from?, :$auth?, :$ver?) { | |
# Locate all the things that we potentially could load. Choose | |
# the first one for now (XXX need to filter by version and auth). | |
my @prefixes := self.search_path(); | |
@@ -191,13 +191,12 @@ class Perl6::ModuleLoader { | |
# Get the compiler and compile the code, then run it | |
# (which runs the mainline and captures UNIT). | |
my $?FILES := %chosen<pm>; | |
- my $eval := nqp::getcomp('perl6').compile($source); | |
+ my $eval := nqp::getcomp('perl6').compile($source, :M($from)); | |
my $*CTXSAVE := self; | |
my $*MAIN_CTX; | |
$eval(); | |
%modules_loaded{%chosen<key>} := $module_ctx := $*MAIN_CTX; | |
DEBUG("done loading ", %chosen<pm>) if $DEBUG; | |
- | |
} | |
nqp::bindhllsym('perl6', 'GLOBAL', $preserve_global); | |
CATCH { | |
diff --git a/src/Perl6/World.nqp b/src/Perl6/World.nqp | |
index 6e81501..d728659 100644 | |
--- a/src/Perl6/World.nqp | |
+++ b/src/Perl6/World.nqp | |
@@ -355,22 +355,28 @@ class Perl6::World is HLL::World { | |
# Loads a module immediately, and also makes sure we load it | |
# during the deserialization. | |
- method load_module($/, $module_name, $cur_GLOBALish) { | |
+ method load_module($/, $module_name, $cur_GLOBALish, :$name?, :$file?, :$from?, :$auth?, :$ver?) { | |
# Immediate loading. | |
my $line := HLL::Compiler.lineof($/.orig, $/.from, :cache(1)); | |
- my $module := Perl6::ModuleLoader.load_module($module_name, $cur_GLOBALish, :$line); | |
+ my $module := Perl6::ModuleLoader.load_module($module_name, $cur_GLOBALish, :$line, | |
+ :$name, :$file, :$from, :$auth, :$ver); | |
# During deserialization, ensure that we get this module loaded. | |
if self.is_precompilation_mode() { | |
- self.add_load_dependency_task(:deserialize_past(QAST::Stmts.new( | |
- self.perl6_module_loader_code(), | |
- QAST::Op.new( | |
+ my $op := QAST::Op.new( | |
:op('callmethod'), :name('load_module'), | |
QAST::Op.new( :op('getcurhllsym'), | |
QAST::SVal.new( :value('ModuleLoader') ) ), | |
QAST::SVal.new( :value($module_name) ), | |
- QAST::IVal.new(:value($line), :named('line')) | |
- )))); | |
+ QAST::IVal.new(:value($line), :named('line'))); | |
+ nqp::push($op, QAST::SVal.new(:value($name), :named('name'))) if nqp::defined($name); | |
+ nqp::push($op, QAST::SVal.new(:value($file), :named('file'))) if nqp::defined($file); | |
+ nqp::push($op, QAST::SVal.new(:value($from), :named('from'))) if nqp::defined($from); | |
+ nqp::push($op, QAST::SVal.new(:value($auth), :named('auth'))) if nqp::defined($auth); | |
+ nqp::push($op, QAST::SVal.new(:value($ver), :named('ver'))) if nqp::defined($ver); | |
+ self.add_load_dependency_task(:deserialize_past(QAST::Stmts.new( | |
+ self.perl6_module_loader_code(), $op | |
+ ))); | |
} | |
return nqp::ctxlexpad($module); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment