Skip to content

Commit

Permalink
Merge branch 'world-rethrow' into nom
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed May 25, 2012
2 parents 5274a37 + 6d6e154 commit ecf355f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/Perl6/World.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,10 @@ class Perl6::World is HLL::World {

# Adds a method to the meta-object.
method pkg_add_method($/, $obj, $meta_method_name, $name, $code_object) {
$obj.HOW."$meta_method_name"($obj, $name, $code_object);
self.ex-handle($/, {
$obj.HOW."$meta_method_name"($obj, $name, $code_object)
}
)
}

# Handles setting the body block code for a role.
Expand Down Expand Up @@ -1917,4 +1920,35 @@ class Perl6::World is HLL::World {
$/.CURSOR.panic(nqp::join('', @err));
}
}

method ex-handle($/, $code) {
my $res;
my $ex;
my $nok;
try {
$res := $code();
CATCH {
$nok := 1;
$ex := $_;
}
}
if $nok {
$*W.rethrow($/, $ex);
} else {
$res;
}
}

method rethrow($/, $err) {
my $ex_t := self.find_symbol(['X', 'Comp', 'AdHoc']);
my $coercer := self.find_symbol(['&COMP_EXCEPTION']);
my $p6ex := $coercer($err);
nqp::bindattr($p6ex, $ex_t, '$!filename',
nqp::box_s(pir::find_caller_lex__ps('$?FILES'),
self.find_symbol(['Str'])));
nqp::bindattr($p6ex, $ex_t, '$!line',
nqp::box_i(HLL::Compiler.lineof($/.orig, $/.from),
self.find_symbol(['Int'])));
$p6ex.rethrow();
}
}
19 changes: 19 additions & 0 deletions src/core/Exception.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ my class Exception {
pir::throw__0P($!ex)
}
method rethrow() is hidden_from_backtrace {
pir::setattribute__vPsP($!ex, 'payload', nqp::p6decont(self));
pir::rethrow__0P($!ex)
}
}
Expand Down Expand Up @@ -73,6 +74,21 @@ sub EXCEPTION(|$) {
}
}

my class X::Comp::AdHoc { ... }
sub COMP_EXCEPTION(|$) {
my Mu $parrot_ex := nqp::shift(pir::perl6_current_args_rpa__P());
my Mu $payload := nqp::atkey($parrot_ex, 'payload');
if nqp::p6bool(pir::type_check__IPP($payload, Exception)) {
nqp::bindattr($payload, Exception, '$!ex', $parrot_ex);
$payload;
} else {
my $ex := nqp::create(X::Comp::AdHoc);
nqp::bindattr($ex, Exception, '$!ex', $parrot_ex);
nqp::bindattr($ex, X::AdHoc, '$!payload', nqp::p6box_s(nqp::atkey($parrot_ex, 'message')));
$ex;
}
}


do {
sub is_runtime($bt) {
Expand Down Expand Up @@ -254,6 +270,9 @@ my role X::Comp is Exception {
}
}

# XXX a hack for getting line numbers from exceptions from the metamodel
my class X::Comp::AdHoc is X::AdHoc does X::Comp { }

my role X::Syntax does X::Comp { }
my role X::Pod { }

Expand Down

0 comments on commit ecf355f

Please sign in to comment.