Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
make fail, die and Failure.new cheaper
  • Loading branch information
timo committed Oct 3, 2015
1 parent 98d9b87 commit 2e92038
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/core/Failure.pm
Expand Up @@ -7,8 +7,9 @@ my class Failure {
self.bless(:$exception);
}
multi method new($payload =
(CALLER::CALLER::.EXISTS-KEY('$!') and CALLER::CALLER::('$!').DEFINITE)
?? CALLER::CALLER::('$!') !! 'Failed') {
nqp::ctxlexpad(nqp::ctxcaller(nqp::ctxcaller(nqp::ctx))).EXISTS-KEY('$!')
&& nqp::ctxlexpad(nqp::ctxcaller(nqp::ctxcaller(nqp::ctx)))('$!').DEFINITE
?? nqp::ctxlexpad(nqp::ctxcaller(nqp::ctxcaller(nqp::ctx)))('$!') !! "Died") {
if ($payload ~~ Exception) {
self.bless(:exception($payload));
}
Expand Down Expand Up @@ -78,8 +79,9 @@ multi sub fail(Exception:U $e) {
$fail
}
multi sub fail($payload =
(CALLER::CALLER::.EXISTS-KEY('$!') and CALLER::CALLER::('$!').DEFINITE)
?? CALLER::CALLER::('$!') !! 'Failed') {
nqp::ctxlexpad(nqp::ctxcaller(nqp::ctxcaller(nqp::ctx))).EXISTS-KEY('$!')
&& nqp::ctxlexpad(nqp::ctxcaller(nqp::ctxcaller(nqp::ctx)))('$!').DEFINITE
?? nqp::ctxlexpad(nqp::ctxcaller(nqp::ctxcaller(nqp::ctx)))('$!') !! "Died") {

my Mu $return := nqp::getlexcaller('RETURN');

Expand Down
5 changes: 3 additions & 2 deletions src/core/control.pm
Expand Up @@ -172,8 +172,9 @@ multi sub die(Exception:U $e) {
X::AdHoc.new(:payload("Died with undefined " ~ $e.^name)).throw;
}
multi sub die($payload =
(CALLER::CALLER::.EXISTS-KEY('$!') and CALLER::CALLER::('$!').DEFINITE)
?? CALLER::CALLER::('$!') !! "Died") {
nqp::ctxlexpad(nqp::ctxcaller(nqp::ctxcaller(nqp::ctx))).EXISTS-KEY('$!')
&& nqp::ctxlexpad(nqp::ctxcaller(nqp::ctxcaller(nqp::ctx)))('$!').DEFINITE
?? nqp::ctxlexpad(nqp::ctxcaller(nqp::ctxcaller(nqp::ctx)))('$!') !! "Died") {
if $payload ~~ Exception {
$payload.throw;
}
Expand Down

0 comments on commit 2e92038

Please sign in to comment.