Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
If there's no PIR pre-compiled file to hand, use the .pm instead. Sti…
…ll need to do checks for which is newer, and generating the PIR file if we can haz write access. Also, awesomize module not found error to show any version and authority if they are passed.
  • Loading branch information
jnthn committed Mar 11, 2010
1 parent 5faf418 commit 69ce6d7
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/Perl6/Module/Loader.pm
Expand Up @@ -11,19 +11,40 @@ method need($name, %name_adverbs?) {
Perl6::Module::Locator.find_module($name, @inc, %name_adverbs<ver>, %name_adverbs<auth>) !!
Perl6::Module::Locator.find_module_no_conditions($name, @inc);
if $pm_file eq '' {
# XXX Awesomeize - include version and auth if specified.
pir::die("Unable to find module '$name'.");
pir::die("Unable to find module '$name'" ~
(%name_adverbs<ver> ?? " with version '" ~ %name_adverbs<ver> ~ "'" !! "") ~
(%name_adverbs<ver> && %name_adverbs<auth> ?? ' and' !! '') ~
(%name_adverbs<auth> ?? " with authority '" ~ %name_adverbs<auth> ~ "'" !! "") ~
".");
}

# XXX For now, we just use the pre-compiled PIR file. (Yes, epic hack.)
my $pir_file := pir::substr__SSII($pm_file, 0, pir::length__IS($pm_file) - 2) ~ 'pir';
unless pir::stat__ISI($pir_file, 0) {
pir::die("Sorry, for now you must manually compile .pm modules to .pir (missing for $name).");
}
unless %LOADED{$pir_file} {
pir::load_bytecode__vS($pir_file);
%LOADED{$pir_file} := 1;
# Need not load file if we already did so.
unless %LOADED{$pm_file} {
# Is there a pre-compiled PIR version?
my $pir_file := pir::substr__SSII($pm_file, 0, pir::length__IS($pm_file) - 2) ~ 'pir';
my $loaded_pir := 0;
if pir::stat__ISI($pir_file, 0) {
# XXX We really should check if it's newer than the .pm file
# to avoid loading out of date versions.
pir::load_bytecode__vS($pir_file);
$loaded_pir := 1;
}

# If we couldn't load a cached PIR version, read in and compile.
# XXX We can try to write the compiled PIR to disk so the next
# time around it's fast.
unless $loaded_pir {
my $fh := pir::open__PSS($pm_file, 'r');
my $source := $fh.readall();
$fh.close();
my $eval := Perl6::Compiler.compile($source);
$eval();
}

# Mark loaded.
%LOADED{$pm_file} := 1;
}

1;
}

Expand Down

0 comments on commit 69ce6d7

Please sign in to comment.