Skip to content
Browse files

First horrible implementation of use lib

It doesn't scope right and it also doesn't work with the precompiler so it
cannot be used in modules.  Also it propagates into modules, which may or may
not be a feature.
  • Loading branch information...
1 parent 94c69fe commit 6b0956d6a6a311da3dcbc1ed4f9e342293306f20 @sorear sorear committed Aug 23, 2012
Showing with 25 additions and 4 deletions.
  1. +18 −2 src/NieczaActions.pm6
  2. +1 −0 src/NieczaCompiler.pm6
  3. +6 −2 src/STD.pm6
View
20 src/NieczaActions.pm6
@@ -3583,6 +3583,12 @@ method statement_control:use ($/) {
my $name = $<module_name>.ast<name>;
my $args = $<arglist> ?? $<arglist>.ast !! [];
+ # arguments are always evaluated immediately
+ $/.CURSOR.trymop({
+ for @$args {
+ $_ = self.eval_ast($/, $_)
+ }
+ }) or return;
# support loading modules from perl5
if $<module_name><longname><colonpair> -> $pairs {
@@ -3600,17 +3606,27 @@ method statement_control:use ($/) {
return;
}
+ if $name eq 'lib' {
+ $/.CURSOR.trymop({ for @$args { .=to_string }; }) or return;
+ unless $*run_mode {
+ $/.CURSOR.sorry("use lib not permitted in precompiled files yet");
+ return;
+ }
+ $*compiler.module_finder.path.push: @$args;
+ return;
+ }
+
if $args {
$/.CURSOR.sorry("'use' with arguments NYI");
return;
}
- if ($name eq 'strict') {
+ if $name eq 'strict' {
$*CURLEX<!sub>.set_extend('strict', True);
return;
}
- if ($name eq 'MONKEY_TYPING' || $name eq 'fatal' || $name eq 'lib') {
+ if $name eq 'MONKEY_TYPING' || $name eq 'fatal' || $name eq 'lib' {
return;
}
View
1 src/NieczaCompiler.pm6
@@ -22,6 +22,7 @@ method !compile(:$unitname, :$filename, :$source, :$main, :$run, :$evalmode, :$o
my $*compiler = self;
my $*verbose = $.verbose;
my $*backend = $.backend;
+ my $*run_mode = $run;
# tells parser not to exit when parse fails
my $*in_repl = $repl;
View
8 src/STD.pm6
@@ -5449,9 +5449,13 @@ method trymop($f) {
state $fast = %*ENV<NIECZA_FAIL_FAST>;
if $fast {
$f();
+ True;
} else {
- unless try { $f(); True } {
- self.sorry($!)
+ if try { $f(); True } {
+ True;
+ } else {
+ self.sorry($!);
+ False;
}
}
}

0 comments on commit 6b0956d

Please sign in to comment.
Something went wrong with that request. Please try again.