Skip to content

Commit

Permalink
Hack BEGIN { @*INC.push: ... } to DTRT
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jul 18, 2011
1 parent f5e9082 commit fe88724
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/CORE.setting
Expand Up @@ -1880,6 +1880,7 @@ INIT {
$PROCESS::EXECUTABLE_NAME ::= Q:CgOp { (sysquery (i 2)) };
$PROCESS::PROGRAM_NAME ::= Q:CgOp { (sysquery (i 1)) };
$PROCESS::BASE_DIRECTORY ::= Q:CgOp { (sysquery (i 3)) };
@GLOBAL::INC = ();
}
# }}}
Expand Down
1 change: 1 addition & 0 deletions src/NieczaCompiler.pm6
Expand Up @@ -22,6 +22,7 @@ method !compile($unitname, $filename, $modtime, $source, $main, $run, $end, $eva
my $*compiler = self;
my $*verbose = $.verbose;
my $*in_repl = $repl;
my @*INC;

my $ast;
my @steps = (
Expand Down
8 changes: 5 additions & 3 deletions src/NieczaPathSearch.pm6
@@ -1,12 +1,14 @@
class NieczaPathSearch;

has $.path;
has @.path;

# Given Foo::Bar, find ($?FILE, $modtime, $text)
method load_module($name) {
my $sub = "".IO.combine($name.split('::'));

for @$.path -> $pe {
my @path = @*INC, @!path;

for @path -> $pe {
for <pm6 pm setting> -> $ext {
my $fn = $pe.IO.append($sub).but-extension($ext);
if $fn.f {
Expand All @@ -18,7 +20,7 @@ method load_module($name) {
}
}

die "Unable to locate module $name in @$.path";
die "Unable to locate module $name in @path";
}

method load_file($name) {
Expand Down
23 changes: 23 additions & 0 deletions src/niecza
Expand Up @@ -24,6 +24,28 @@ use Sig;
use STD;

augment class NieczaActions {
method statement_prefix:BEGIN ($/) {
$<blast>.ast.is_phaser = 2;
$*CURLEX<!sub>.create_static_pad;
make ::Op::StatementList.new;

# MAJOR HACK - allows test code like BEGIN { @*INC.push: ... } to work
repeat while False {
my $c = $<blast>.ast.code;

last unless $c ~~ Op::StatementList;
last unless $c.children == 1;
my $d = $c.children.[0];
last unless $d ~~ Op::CallMethod;
last unless $d.receiver ~~ Op::ContextVar;
last unless $d.receiver.name eq '@*INC';
last if $d.private || $d.ismeta;
last unless $d.name eq any <push unshift>;
last unless +$d.getargs == 1;
last unless defined my $str = self.trivial_eval($/, $d.getargs.[0]);
@*INC."$d.name()"($str);
}
}
}

CgOp._register_ops: <
Expand Down Expand Up @@ -84,6 +106,7 @@ GetOptions(:!permute,
"help|h" => sub { say $usage; exit 0 },
);

my @*INC;
my $backend;
if $bcnd eq 'nam' {
$backend = NieczaBackendNAM.new(obj_dir => $odir);
Expand Down

0 comments on commit fe88724

Please sign in to comment.