Skip to content

Commit

Permalink
Merge branch 'module-trace' into nom
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Jun 12, 2012
2 parents b12854a + d53986b commit 030721d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
25 changes: 24 additions & 1 deletion src/Perl6/ModuleLoader.pm
Expand Up @@ -99,7 +99,7 @@ class Perl6::ModuleLoader {
@candidates
}

method load_module($module_name, *@GLOBALish) {
method load_module($module_name, *@GLOBALish, :$line) {
# 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();
Expand All @@ -118,14 +118,29 @@ class Perl6::ModuleLoader {
$module_ctx := %modules_loaded{%chosen<key>};
}
else {
if +@*MODULES == 0 {
my %prev := nqp::hash();
%prev<line> := $line;
%prev<filename> := pir::find_caller_lex__ps('$?FILES');
@*MODULES[0] := %prev;
}
else {
@*MODULES[-1]<line> := $line;
}
my %trace := nqp::hash();
%trace<module> := $module_name;
%trace<filename> := %chosen<pm>;
my $preserve_global := pir::get_hll_global__Ps('GLOBAL');
nqp::push(@*MODULES, %trace);
if %chosen<load> {
%trace<precompiled> := %chosen<load>;
DEBUG("loading ", %chosen<load>) if $DEBUG;
my %*COMPILING := {};
my $*CTXSAVE := self;
my $*MAIN_CTX;
pir::load_bytecode(%chosen<load>);
%modules_loaded{%chosen<key>} := $module_ctx := $*MAIN_CTX;
DEBUG("done loading ", %chosen<load>) if $DEBUG;
}
else {
# Read source file.
Expand All @@ -143,8 +158,16 @@ class Perl6::ModuleLoader {
my $*MAIN_CTX;
$eval();
%modules_loaded{%chosen<key>} := $module_ctx := $*MAIN_CTX;
DEBUG("done loading ", %chosen<pm>) if $DEBUG;

}
nqp::pop(@*MODULES);
pir::set_hll_global__vsP('GLOBAL', $preserve_global);
CATCH {
pir::set_hll_global__vsP('GLOBAL', $preserve_global);
nqp::pop(@*MODULES);
nqp::rethrow($_);
}
}

# Provided we have a mainline and need to do global merging...
Expand Down
26 changes: 23 additions & 3 deletions src/Perl6/World.pm
Expand Up @@ -28,6 +28,24 @@ my $SIG_ELEM_NATIVE_INT_VALUE := 2097152;
my $SIG_ELEM_NATIVE_NUM_VALUE := 4194304;
my $SIG_ELEM_NATIVE_STR_VALUE := 8388608;

sub p6ize_recursive($x) {
if nqp::islist($x) {
my @copy := [];
for $x {
nqp::push(@copy, p6ize_recursive($_));
}
return pir::perl6ize_type__PP(@copy);
}
elsif pir::isa($x, 'Hash') {
my %copy := nqp::hash();
for $x {
%copy{$_.key} := p6ize_recursive($_.value);
}
return pir::perl6ize_type__PP(%copy).item;
}
pir::perl6ize_type__PP($x);
}

# This builds upon the SerializationContextBuilder to add the specifics
# needed by Rakudo Perl 6.
class Perl6::World is HLL::World {
Expand Down Expand Up @@ -174,7 +192,8 @@ class Perl6::World is HLL::World {
# during the deserialization.
method load_module($/, $module_name, $cur_GLOBALish) {
# Immediate loading.
my $module := Perl6::ModuleLoader.load_module($module_name, $cur_GLOBALish);
my $line := HLL::Compiler.lineof($/.orig, $/.from);
my $module := Perl6::ModuleLoader.load_module($module_name, $cur_GLOBALish, :$line);

# During deserialization, ensure that we get this module loaded.
if self.is_precompilation_mode() {
Expand All @@ -183,7 +202,7 @@ class Perl6::World is HLL::World {
PAST::Op.new(
:pasttype('callmethod'), :name('load_module'),
PAST::Var.new( :name('ModuleLoader'), :namespace([]), :scope('package') ),
$module_name
$module_name, PAST::Val.new(:value($line), :named('line'))
))));
}

Expand Down Expand Up @@ -1899,7 +1918,8 @@ class Perl6::World is HLL::World {
};

if $type_found {
%opts<line> := HLL::Compiler.lineof($/.orig, $/.from);
%opts<line> := HLL::Compiler.lineof($/.orig, $/.from);
%opts<modules> := p6ize_recursive(@*MODULES);
for %opts -> $p {
if pir::does($p.value, 'array') {
my @a := [];
Expand Down
9 changes: 8 additions & 1 deletion src/core/Exception.pm
Expand Up @@ -280,8 +280,15 @@ my role X::Comp is Exception {
has $.filename;
has $.line;
has $.column;
has @.modules;
multi method gist(::?CLASS:D:) {
"===SORRY!===\n$.message\nat $.filename():$.line";
my $r = "===SORRY!===\n$.message\nat $.filename():$.line";
for @.modules.reverse[1..*] {
$r ~= $_<module>.defined
?? "\n from module $_<module> file $_<filename>:$_<line>"
!! "\n from $_<filename>:$_<line>";
}
$r;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main.nqp
Expand Up @@ -27,6 +27,9 @@ sub MAIN(@ARGS) {
@clo.push('c');
@clo.push('I=s');
@clo.push('M=s');

# Set up module loading trace
my @*MODULES := [];

# Set up END block list, which we'll run at exit.
my @*END_PHASERS := [];
Expand Down

0 comments on commit 030721d

Please sign in to comment.