Skip to content

Commit

Permalink
Merge branch 'nom-exceptions' into nom
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Sep 27, 2011
2 parents 3e8911a + b522144 commit 287b0d8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/core/Cool.pm
Expand Up @@ -170,6 +170,10 @@ my class Cool {
method trim () { self.Stringy.trim };
method trim-leading () { self.Stringy.trim-leading };
method trim-trailing() { self.Stringy.trim-trailing };

method eval(*%opts) {
eval(self.Stringy, |%opts);
}
}

sub chop($s) { $s.chop }
Expand Down
20 changes: 16 additions & 4 deletions src/core/Exception.pm
Expand Up @@ -6,6 +6,9 @@ my class Exception {
}

method throw() {
nqp::bindattr(self, Exception, '$!ex', pir::new('Exception'))
unless pir::defined($!ex);
pir::setattribute__vPsP($!ex, 'payload', pir::perl6_decontainerize__PP(self));
pir::throw__0P($!ex)
}
method rethrow() {
Expand All @@ -14,10 +17,19 @@ my class Exception {
}

sub EXCEPTION(|$) {
my $ex := nqp::create(Exception);
nqp::bindattr($ex, Exception, '$!ex',
nqp::shift(pir::perl6_current_args_rpa__P()));
$ex;
my Mu $parrot_ex := nqp::shift(pir::perl6_current_args_rpa__P());
if nqp::p6bool(nqp::iseq_i(nqp::atkey($parrot_ex, 'type'), pir::const::CONTROL_ERROR)) {

my Mu $payload := nqp::atkey($parrot_ex, 'payload');
my $ex := pir::defined($payload) ?? $payload !! nqp::create(Exception);
nqp::bindattr($ex, Exception, '$!ex', $parrot_ex);
$ex;
} else {
nqp::say("Caught exception of unknown type -- this probably should not happen");
my $ex := nqp::create(Exception);
nqp::bindattr($ex, Exception, '$!ex', $parrot_ex);
$ex;
}
}


Expand Down
5 changes: 3 additions & 2 deletions src/core/control.pm
Expand Up @@ -136,8 +136,9 @@ my &lastcall := -> {
True
};

sub die(*@msg) is hidden_from_backtrace { pir::die__0P(@msg.join('')) }

proto sub die(|$) is hidden_from_backtrace {*};
multi sub die(Exception $e) { $e.throw }
multi sub die(*@msg) { pir::die__0P(@msg.join('')) }
# XXX TODO: Should really throw a warning exception.
sub warn(*@msg) is hidden_from_backtrace { $*ERR.say(@msg.join('')) }

Expand Down
1 change: 1 addition & 0 deletions src/core/stubs.pm
Expand Up @@ -8,6 +8,7 @@ my class Bag is Iterable does Associative { }
my class Set is Iterable does Associative { }
my class KeyHash is Iterable does Associative { }
my class Seq is List does Positional { }
my class Exception { ... }

sub DYNAMIC(\$name) is rw {
my Mu $x := pir::find_dynamic_lex__Ps(nqp::unbox_s($name));
Expand Down

0 comments on commit 287b0d8

Please sign in to comment.