Mercurial > hg > Others > Rakudo
annotate src/core.c/Failure.pm6 @ 0:c341f82e7ad7 default tip
Rakudo branch in cr.ie.u-ryukyu.ac.jp
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 Dec 2019 16:50:27 +0900 |
parents | |
children |
rev | line source |
---|---|
0
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 my class Failure is Nil { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 has $.exception; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 has $.backtrace; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 #?if !jvm |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 has int $!handled; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 #?endif |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 #?if jvm |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 has Int $!handled; # alas, native int breaks on the JVM |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 #?endif |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 method !SET-SELF($!exception) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 $!backtrace = $!exception.backtrace || Backtrace.new(3); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 $!exception.reset-backtrace; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 self |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 multi method new(Failure:D:) { self!throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 multi method new(Failure:U:) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 my $stash := CALLER::LEXICAL::; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 my $payload = ($stash<$!>:exists && $stash<$!>.DEFINITE) ?? $stash<$!> !! "Failed"; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 nqp::create(self)!SET-SELF( |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 $payload ~~ Exception ?? $payload !! X::AdHoc.new(:$payload) |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 ) |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 multi method new(Failure:U: Exception:D \exception) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 nqp::create(self)!SET-SELF(exception) |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 multi method new(Failure:U: $payload) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 nqp::create(self)!SET-SELF(X::AdHoc.new(:$payload)) |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 multi method new(Failure:U: |cap (*@msg)) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 nqp::create(self)!SET-SELF(X::AdHoc.from-slurpy(|cap)) |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 submethod DESTROY () { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 note "WARNING: unhandled Failure detected in DESTROY. If you meant " |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 ~ "to ignore it, you can mark it as handled by calling .Bool, " |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 ~ ".so, .not, or .defined methods. The Failure was:\n" ~ self.mess |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 unless $!handled; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 # allow Failures to throw when they replace an Iterable |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 multi method iterator(Failure:D:) { self!throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 multi method list(Failure:D:) { self!throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 # Marks the Failure has handled (since we're now fatalizing it) and throws. |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 method !throw(Failure:D:) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 $!handled = 1; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 $!exception.throw($!backtrace); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 # Turns out multidimensional lookups are one way to leak unhandled failures, so |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 # we'll just propagate the initial failure much as we propagate Nil on methods. |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 method AT-POS(|) { self } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 method AT-KEY(|) { self } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 multi method defined(Failure:D: --> False) { $!handled = 1 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 multi method Bool(Failure:D: --> False) { $!handled = 1 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 method handled() is rw { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 Proxy.new( |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 FETCH => { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 #?if !jvm |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 nqp::hllbool($!handled) |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 #?endif |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 #?if jvm |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 $!handled.Bool |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 #?endif |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 }, |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 STORE => -> $, $value { $!handled = $value.Bool.Numeric } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 ) |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 method Capture() { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 self.DEFINITE.not || $!handled |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 ?? X::Cannot::Capture.new(what => self).throw |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 !! self!throw |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 method Int(Failure:D:) { $!handled ?? Int !! self!throw(); } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 method Num(Failure:D:) { $!handled ?? NaN !! self!throw(); } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 method Numeric(Failure:D:) { $!handled ?? NaN !! self!throw(); } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 method Set(Failure:D:) { $!handled ?? Set.new(self) !! self!throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 method SetHash(Failure:D:) { $!handled ?? SetHash.new(self) !! self!throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 method Bag(Failure:D:) { $!handled ?? Bag.new(self) !! self!throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 method BagHash(Failure:D:) { $!handled ?? BagHash.new(self) !! self!throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 method Mix(Failure:D:) { $!handled ?? Mix.new(self) !! self!throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 method MixHash(Failure:D:) { $!handled ?? MixHash.new(self) !! self!throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 multi method Str(Failure:D:) { $!handled ?? $.mess !! self!throw(); } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 multi method gist(Failure:D:) { $!handled ?? $.mess !! self!throw(); } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 multi method gist(Failure:U:) { '(' ~ self.^name ~ ')' } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 multi method perl(Failure:D:) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 $!handled ?? '&CORE::infix:<orelse>(' ~ self.Mu::perl ~ ', *.self)' |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 !! self.Mu::perl |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 multi method perl(Failure:U:) { self.^name } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 method mess (Failure:D:) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 my $message = (try self.exception.message) // self.exception.^name ~ ' with no message'; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 "(HANDLED) " x $!handled ~ "$message\n" ~ self.backtrace; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 method sink(Failure:D:) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 self!throw() unless $!handled |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 method self(Failure:D:) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 self!throw() unless $!handled; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 self |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 method CALL-ME(Failure:D: |) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 self!throw() |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 method FALLBACK(Failure:D: *@) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 self!throw() |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 method STORE(Failure:D: *@) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 self!throw() |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 proto sub fail(|) {*}; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 multi sub fail(--> Nil) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 my $stash := CALLER::LEXICAL::; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124 my $payload = ($stash<$!>:exists && $stash<$!>.DEFINITE) ?? $stash<$!> !! "Failed"; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126 my $fail := Failure.new( $payload ~~ Exception |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 ?? $payload !! X::AdHoc.new(:$payload)); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 nqp::throwpayloadlexcaller(nqp::const::CONTROL_RETURN, $fail); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 CATCH { $fail.exception.throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 multi sub fail(Exception:U $e --> Nil) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 my $fail := Failure.new( |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134 X::AdHoc.new(:payload("Failed with undefined " ~ $e.^name)) |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 ); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 nqp::throwpayloadlexcaller(nqp::const::CONTROL_RETURN, $fail); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
137 CATCH { $fail.exception.throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 multi sub fail($payload --> Nil) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140 my $fail := Failure.new( $payload ~~ Exception |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 ?? $payload |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 !! X::AdHoc.new(:$payload) |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143 ); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144 nqp::throwpayloadlexcaller(nqp::const::CONTROL_RETURN, $fail); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 CATCH { $fail.exception.throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147 multi sub fail(|cap (*@msg) --> Nil) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 my $fail := Failure.new(X::AdHoc.from-slurpy(|cap)); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
149 nqp::throwpayloadlexcaller(nqp::const::CONTROL_RETURN, $fail); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 CATCH { $fail.exception.throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
152 multi sub fail(Failure:U $f --> Nil) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
153 my $fail := Failure.new( |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154 X::AdHoc.new(:payload("Failed with undefined " ~ $f.^name)) |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 ); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 nqp::throwpayloadlexcaller(nqp::const::CONTROL_RETURN, $fail); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157 CATCH { $fail.exception.throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
158 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
159 multi sub fail(Failure:D $fail --> Nil) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
160 $fail.handled = 0; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161 nqp::throwpayloadlexcaller(nqp::const::CONTROL_RETURN, $fail); |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162 CATCH { $fail.exception.throw } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
163 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
164 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
165 multi sub die(Failure:D $f --> Nil) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166 $f.exception.throw |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168 multi sub die(Failure:U $f --> Nil) { |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 X::AdHoc.new(:payload("Died with undefined " ~ $f.^name)).throw; |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170 } |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171 |
c341f82e7ad7
Rakudo branch in cr.ie.u-ryukyu.ac.jp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
172 # vim: ft=perl6 expandtab sw=4 |