Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
attempt to stringify common structures for early comp exceptions
try to give better error messages than "Parcel<-1234134>"
during compile-time error reporting when compiling the core setting
  • Loading branch information
timo committed Apr 5, 2014
1 parent 39a18e2 commit 9cc033a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Perl6/World.nqp
Expand Up @@ -2635,12 +2635,38 @@ class Perl6::World is HLL::World {
);
try { return $ex.new(|%opts) };
}

my $Str;
my $Int;
my $Parcel;

try { $Str := self.find_symbol(["Str"]) }
try { $Int := self.find_symbol(["Int"]) }
try { $Parcel := self.find_symbol(["Parcel"]) }

sub safely_stringify($target) {
if $Str && nqp::istype($target, self.find_symbol(["Str"])) {
return ~nqp::unbox_s($target);
} elsif $Int && nqp::istype($target, self.find_symbol(["Int"])) {
return ~nqp::unbox_i($target);
} elsif $Parcel && nqp::istype($target, $Parcel) {
my $storage := nqp::getattr($target, $Parcel, '$!storage');
my @result;
for $storage {
nqp::push(@result, safely_stringify($_));
}
return "(" ~ join(", ", @result) ~ ")";
} else {
return ~$target;
}
}

my @err := ['Error while compiling, type ', join('::', $ex_type), "\n"];
for %opts -> $key {
@err.push: ' ';
@err.push: $key;
@err.push: ': ';
@err.push: %opts{$key};
@err.push: safely_stringify(%opts{$key});
@err.push: "\n";
}
nqp::findmethod(HLL::Grammar, 'panic')($/.CURSOR, join('', @err));
Expand Down

0 comments on commit 9cc033a

Please sign in to comment.