Skip to content
Newer
Older
100644 231 lines (204 sloc) 6.2 KB
c69d4ba @pmichaud Refactor core class stubs a bit.
pmichaud authored Aug 18, 2011
1 my class Nil { ... }
acb50df @moritz typed exception for eval with unknown :lang
moritz authored Jun 3, 2012
2 my class X::Eval::NoSuchLang { ... }
dac61a3 @pmichaud First pass at handling infinities in lists and ranges.
pmichaud authored Jun 18, 2011
3
65bec51 @pmichaud Add the first bit of gather/take functionality.
pmichaud authored Jun 18, 2011
4 my &THROW :=
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
5 -> | {
b22eefe @pmichaud Add &return and &return-rw .
pmichaud authored Jun 10, 2011
6 Q:PIR {
65bec51 @pmichaud Add the first bit of gather/take functionality.
pmichaud authored Jun 18, 2011
7 .local pmc args, payload, type, severity, ex
8 args = perl6_current_args_rpa
9 payload = args[0]
10 type = args[1]
11 severity = args[2]
12 unless null severity goto have_severity
13 severity = box .EXCEPT_NORMAL
14 have_severity:
b22eefe @pmichaud Add &return and &return-rw .
pmichaud authored Jun 10, 2011
15 ex = root_new ['parrot';'Exception']
65bec51 @pmichaud Add the first bit of gather/take functionality.
pmichaud authored Jun 18, 2011
16 setattribute ex, 'payload', payload
17 setattribute ex, 'type', type
18 setattribute ex, 'severity', severity
b22eefe @pmichaud Add &return and &return-rw .
pmichaud authored Jun 10, 2011
19 throw ex
20 };
65bec51 @pmichaud Add the first bit of gather/take functionality.
pmichaud authored Jun 18, 2011
21 0
b22eefe @pmichaud Add &return and &return-rw .
pmichaud authored Jun 10, 2011
22 };
23
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
24 my &RETURN-PARCEL := -> Mu \parcel {
25 my Mu $storage := nqp::getattr(parcel, Parcel, '$!storage');
95168b5 @pmichaud Fix multi-argument control functions (return, take, etc.).
pmichaud authored Jul 29, 2011
26 nqp::iseq_i(nqp::elems($storage), 0)
27 ?? Nil
28 !! (nqp::iseq_i(nqp::elems($storage), 1)
29 ?? nqp::shift($storage)
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
30 !! parcel)
95168b5 @pmichaud Fix multi-argument control functions (return, take, etc.).
pmichaud authored Jul 29, 2011
31 }
32
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
33 my &return-rw := -> | {
95168b5 @pmichaud Fix multi-argument control functions (return, take, etc.).
pmichaud authored Jul 29, 2011
34 my $parcel :=
6f79391 @jnthn Fix a bunch of incorrect pirop signatures that the slightly stricter …
jnthn authored Jul 21, 2012
35 &RETURN-PARCEL(nqp::p6parcel(pir::perl6_current_args_rpa__P(), Nil));
bc246a5 @jnthn pir => nqp and void fix.
jnthn authored Jul 23, 2012
36 nqp::p6routinereturn($parcel);
f647b57 @pmichaud Switch to using lexical returns. A return invocation now attaches
pmichaud authored Jun 27, 2011
37 $parcel
65bec51 @pmichaud Add the first bit of gather/take functionality.
pmichaud authored Jun 18, 2011
38 };
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
39 my &return := -> | {
95168b5 @pmichaud Fix multi-argument control functions (return, take, etc.).
pmichaud authored Jul 29, 2011
40 my $parcel :=
6f79391 @jnthn Fix a bunch of incorrect pirop signatures that the slightly stricter …
jnthn authored Jul 21, 2012
41 &RETURN-PARCEL(nqp::p6parcel(pir::perl6_current_args_rpa__P(), Nil));
bc246a5 @jnthn pir => nqp and void fix.
jnthn authored Jul 23, 2012
42 nqp::p6routinereturn(nqp::p6recont_ro($parcel));
f647b57 @pmichaud Switch to using lexical returns. A return invocation now attaches
pmichaud authored Jun 27, 2011
43 $parcel
65bec51 @pmichaud Add the first bit of gather/take functionality.
pmichaud authored Jun 18, 2011
44 };
b22eefe @pmichaud Add &return and &return-rw .
pmichaud authored Jun 10, 2011
45
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
46 my &take-rw := -> | {
95168b5 @pmichaud Fix multi-argument control functions (return, take, etc.).
pmichaud authored Jul 29, 2011
47 my $parcel :=
6f79391 @jnthn Fix a bunch of incorrect pirop signatures that the slightly stricter …
jnthn authored Jul 21, 2012
48 &RETURN-PARCEL(nqp::p6parcel(pir::perl6_current_args_rpa__P(), Nil));
65bec51 @pmichaud Add the first bit of gather/take functionality.
pmichaud authored Jun 18, 2011
49 THROW($parcel, pir::const::CONTROL_TAKE)
50 };
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
51 my &take := -> | {
95168b5 @pmichaud Fix multi-argument control functions (return, take, etc.).
pmichaud authored Jul 29, 2011
52 my $parcel :=
6f79391 @jnthn Fix a bunch of incorrect pirop signatures that the slightly stricter …
jnthn authored Jul 21, 2012
53 &RETURN-PARCEL(nqp::p6parcel(pir::perl6_current_args_rpa__P(), Nil));
b70b105 @KrisShannon Fix take over-flattening
KrisShannon authored Jan 1, 2012
54 THROW(nqp::p6recont_ro($parcel),
65bec51 @pmichaud Add the first bit of gather/take functionality.
pmichaud authored Jun 18, 2011
55 pir::const::CONTROL_TAKE)
56 };
b22eefe @pmichaud Add &return and &return-rw .
pmichaud authored Jun 10, 2011
57
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
58 my &last := -> | {
95168b5 @pmichaud Fix multi-argument control functions (return, take, etc.).
pmichaud authored Jul 29, 2011
59 my $parcel :=
6f79391 @jnthn Fix a bunch of incorrect pirop signatures that the slightly stricter …
jnthn authored Jul 21, 2012
60 &RETURN-PARCEL(nqp::p6parcel(pir::perl6_current_args_rpa__P(), Nil));
18dea93 @jnthn Add an nqp::p6decont and eliminate pir::perl6_decontainerize in the s…
jnthn authored Oct 23, 2011
61 THROW(nqp::p6decont($parcel),
dac61a3 @pmichaud First pass at handling infinities in lists and ranges.
pmichaud authored Jun 19, 2011
62 pir::const::CONTROL_LOOP_LAST)
63 };
64
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
65 my &next := -> | {
95168b5 @pmichaud Fix multi-argument control functions (return, take, etc.).
pmichaud authored Jul 29, 2011
66 my $parcel :=
6f79391 @jnthn Fix a bunch of incorrect pirop signatures that the slightly stricter …
jnthn authored Jul 21, 2012
67 &RETURN-PARCEL(nqp::p6parcel(pir::perl6_current_args_rpa__P(), Nil));
18dea93 @jnthn Add an nqp::p6decont and eliminate pir::perl6_decontainerize in the s…
jnthn authored Oct 23, 2011
68 THROW(nqp::p6decont($parcel),
dac61a3 @pmichaud First pass at handling infinities in lists and ranges.
pmichaud authored Jun 19, 2011
69 pir::const::CONTROL_LOOP_NEXT)
70 };
71
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
72 my &redo := -> | {
95168b5 @pmichaud Fix multi-argument control functions (return, take, etc.).
pmichaud authored Jul 29, 2011
73 my $parcel :=
6f79391 @jnthn Fix a bunch of incorrect pirop signatures that the slightly stricter …
jnthn authored Jul 21, 2012
74 &RETURN-PARCEL(nqp::p6parcel(pir::perl6_current_args_rpa__P(), Nil));
18dea93 @jnthn Add an nqp::p6decont and eliminate pir::perl6_decontainerize in the s…
jnthn authored Oct 23, 2011
75 THROW(nqp::p6decont($parcel),
dac61a3 @pmichaud First pass at handling infinities in lists and ranges.
pmichaud authored Jun 19, 2011
76 pir::const::CONTROL_LOOP_REDO)
77 };
78
c9417ca @moritz switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
moritz authored Aug 14, 2012
79 my &succeed := -> | {
95168b5 @pmichaud Fix multi-argument control functions (return, take, etc.).
pmichaud authored Jul 29, 2011
80 my $parcel :=
6f79391 @jnthn Fix a bunch of incorrect pirop signatures that the slightly stricter …
jnthn authored Jul 21, 2012
81 &RETURN-PARCEL(nqp::p6parcel(pir::perl6_current_args_rpa__P(), Nil));
18dea93 @jnthn Add an nqp::p6decont and eliminate pir::perl6_decontainerize in the s…
jnthn authored Oct 23, 2011
82 THROW(nqp::p6decont($parcel),
ca7573c @pmichaud Add infix:<~~> and things needed for given/when to work.
pmichaud authored Jun 23, 2011
83 pir::const::CONTROL_BREAK)
84 };
85
7233ca4 @pmichaud Initial infix:<...> sequencing operator.
pmichaud authored Jun 23, 2011
86 my &proceed := -> {
87 THROW(Nil, pir::const::CONTROL_CONTINUE)
88 }
89
4bc1ac3 @jnthn First cut implementation of callwith. Probably not perfect, but essen…
jnthn authored Jul 11, 2011
90 my &callwith := -> *@pos, *%named {
a47a56a @jnthn Improve error reporting for nextsame and friends when they are used w…
jnthn authored Feb 3, 2012
91 my Mu $dispatcher := pir::perl6_find_dispatcher__Ps('callwith');
4bc1ac3 @jnthn First cut implementation of callwith. Probably not perfect, but essen…
jnthn authored Jul 10, 2011
92 $dispatcher.exhausted ?? Nil !!
3d5e16b @jnthn Implement nextsame and callsame.
jnthn authored Jul 11, 2011
93 $dispatcher.call_with_args(|@pos, |%named)
4bc1ac3 @jnthn First cut implementation of callwith. Probably not perfect, but essen…
jnthn authored Jul 10, 2011
94 };
95
6849c6f @jnthn Implement nextwith and lastcall.
jnthn authored Jul 11, 2011
96 my &nextwith := -> *@pos, *%named {
a47a56a @jnthn Improve error reporting for nextsame and friends when they are used w…
jnthn authored Feb 3, 2012
97 my Mu $dispatcher := pir::perl6_find_dispatcher__Ps('nextwith');
a5d0ca2 @jnthn Fix handling of lack of candidate to defer to in nextsame/nextwith.
jnthn authored Sep 12, 2011
98 unless $dispatcher.exhausted {
bc246a5 @jnthn pir => nqp and void fix.
jnthn authored Jul 23, 2012
99 nqp::p6routinereturn(nqp::p6recont_ro(
d4bb162 @jnthn Incorporate various of the patches from mls++, with various updates a…
jnthn authored Mar 6, 2012
100 $dispatcher.call_with_args(|@pos, |%named)))
a5d0ca2 @jnthn Fix handling of lack of candidate to defer to in nextsame/nextwith.
jnthn authored Sep 12, 2011
101 }
102 Nil
3d5e16b @jnthn Implement nextsame and callsame.
jnthn authored Jul 11, 2011
103 };
104
105 my &callsame := -> {
a47a56a @jnthn Improve error reporting for nextsame and friends when they are used w…
jnthn authored Feb 3, 2012
106 my Mu $dispatcher := pir::perl6_find_dispatcher__Ps('callsame');
3d5e16b @jnthn Implement nextsame and callsame.
jnthn authored Jul 11, 2011
107 $dispatcher.exhausted ?? Nil !!
108 $dispatcher.call_with_capture(
109 pir::perl6_args_for_dispatcher__PP($dispatcher))
110 };
111
112 my &nextsame := -> {
a47a56a @jnthn Improve error reporting for nextsame and friends when they are used w…
jnthn authored Feb 3, 2012
113 my Mu $dispatcher := pir::perl6_find_dispatcher__Ps('nextsame');
a5d0ca2 @jnthn Fix handling of lack of candidate to defer to in nextsame/nextwith.
jnthn authored Sep 12, 2011
114 unless $dispatcher.exhausted {
bc246a5 @jnthn pir => nqp and void fix.
jnthn authored Jul 23, 2012
115 nqp::p6routinereturn(nqp::p6recont_ro(
d4bb162 @jnthn Incorporate various of the patches from mls++, with various updates a…
jnthn authored Mar 6, 2012
116 $dispatcher.call_with_capture(
117 pir::perl6_args_for_dispatcher__PP($dispatcher))))
a5d0ca2 @jnthn Fix handling of lack of candidate to defer to in nextsame/nextwith.
jnthn authored Sep 12, 2011
118 }
119 Nil
6849c6f @jnthn Implement nextwith and lastcall.
jnthn authored Jul 11, 2011
120 };
121
122 my &lastcall := -> {
a47a56a @jnthn Improve error reporting for nextsame and friends when they are used w…
jnthn authored Feb 3, 2012
123 pir::perl6_find_dispatcher__Ps('lastcall').last();
6849c6f @jnthn Implement nextwith and lastcall.
jnthn authored Jul 11, 2011
124 True
125 };
126
53c7856 @moritz switch protos to use | instead of |$
moritz authored Aug 13, 2012
127 proto sub die(|) is hidden_from_backtrace {*};
834d9d1 @moritz hide &die from backtraces, again
moritz authored Oct 4, 2011
128 multi sub die(Exception $e) is hidden_from_backtrace { $e.throw }
c3fb7d6 @moritz small X::AdHoc refactor
moritz authored Feb 10, 2012
129 multi sub die($payload) is hidden_from_backtrace {
130 X::AdHoc.new(:$payload).throw
131 }
132 multi sub die(*@msg) is hidden_from_backtrace {
133 X::AdHoc.new(payload => @msg.join).throw
134 }
656ff52 @mlschroe Add "outer" control handler, make most uncaught control exceptions fa…
mlschroe authored Nov 23, 2011
135
136 multi sub warn(*@msg) is hidden_from_backtrace {
f9b1ed7 @jnthn We need to provide explicit signatures for pir::ops now; this was mos…
jnthn authored Jul 21, 2012
137 my $ex := pir::new__Ps('Exception');
656ff52 @mlschroe Add "outer" control handler, make most uncaught control exceptions fa…
mlschroe authored Nov 23, 2011
138 pir::setattribute__0PPsP($ex, Exception, 'message', @msg.join(''));
139 pir::setattribute__0PPsP($ex, Exception, 'type', nqp::p6box_i(pir::const::CONTROL_OK));
140 pir::setattribute__0PPsP($ex, Exception, 'severity', nqp::p6box_i(pir::const::EXCEPT_WARNING));
e4b9254 @perlpilot Use nqp::throw
perlpilot authored May 31, 2012
141 nqp::throw($ex);
656ff52 @mlschroe Add "outer" control handler, make most uncaught control exceptions fa…
mlschroe authored Nov 23, 2011
142 0;
143 }
13e487b @jnthn eval, with outer lexicals visible. Means eval_lives_ok and eval_dies_…
jnthn authored Jun 26, 2011
144
53c7856 @moritz switch protos to use | instead of |$
moritz authored Aug 13, 2012
145 proto sub eval(|) {*}
e756635 @moritz make &eval a multi
moritz authored May 26, 2012
146 multi sub eval(Str $code, :$lang = 'perl6') {
13e487b @jnthn eval, with outer lexicals visible. Means eval_lives_ok and eval_dies_…
jnthn authored Jun 26, 2011
147 my $caller_ctx := Q:PIR {
148 $P0 = getinterp
149 %r = $P0['context';1]
150 };
9481a2c @moritz give eval()s a separate file annotation
moritz authored Feb 11, 2012
151 my $?FILES := 'eval_' ~ (state $no)++;
741a933 @moritz Do not catch exceptions from eval()
moritz authored Oct 5, 2011
152 my $compiler := pir::compreg__PS($lang);
acb50df @moritz typed exception for eval with unknown :lang
moritz authored Jun 3, 2012
153 X::Eval::NoSuchLang.new(:$lang).throw
154 if nqp::isnull($compiler);
86bb3ae @jnthn Make sure we don't generate a throwaway GLOBAL in an eval - just use …
jnthn authored Jan 16, 2012
155 my $pbc := $compiler.compile($code, :outer_ctx($caller_ctx), :global(GLOBAL));
741a933 @moritz Do not catch exceptions from eval()
moritz authored Oct 5, 2011
156 nqp::atpos($pbc, 0).set_outer_ctx($caller_ctx);
157 $pbc();
13e487b @jnthn eval, with outer lexicals visible. Means eval_lives_ok and eval_dies_…
jnthn authored Jun 26, 2011
158 }
998c18a @pmichaud Move &exit into src/core/control.pm, add a nqp:: opcode for it.
pmichaud authored Jun 26, 2011
159
160
161 sub exit($status = 0) {
1b5ab32 @jnthn Run END phasers when exit terminates a program.
jnthn authored May 8, 2012
162 $_() for pir::perl6ize_type__PP(@*END_PHASERS);
cb065c8 @moritz avoid a vtable call in get_integer
moritz authored Aug 10, 2012
163 nqp::exit(nqp::unbox_i($status.Int));
998c18a @pmichaud Move &exit into src/core/control.pm, add a nqp:: opcode for it.
pmichaud authored Jun 26, 2011
164 $status;
165 }
dc16a4f @pmichaud Refactor return handling to be in a single place (DRY). Handle the ca…
pmichaud authored Jun 27, 2011
166
0093252 Implement &run
GlitchMr authored Aug 20, 2012
167 sub run(*@args ($, *@)) {
81edc97 @jnthn The spawnw op can in some cases throw an exception; be sure to handle…
jnthn authored Sep 15, 2012
168 my $error_code;
169 try {
170 $error_code = nqp::p6box_i(
171 pir::spawnw__IP(
172 nqp::getattr(
173 @args.eager,
174 List,
175 '$!items'
176 )
0093252 Implement &run
GlitchMr authored Aug 20, 2012
177 )
81edc97 @jnthn The spawnw op can in some cases throw an exception; be sure to handle…
jnthn authored Sep 15, 2012
178 ) +> 8;
179 CATCH {
180 default {
181 $error_code = 1;
182 }
183 }
184 }
0093252 Implement &run
GlitchMr authored Aug 20, 2012
185 $error_code but !$error_code;
f34aa80 @moritz rename &run to &shell
moritz authored Sep 5, 2011
186 }
187
188 sub shell($cmd) {
251c5b3 @pmichaud Add run(), qx operator.
pmichaud authored Jul 27, 2011
189 my $status = 255;
190 try {
191 $status =
192 nqp::p6box_i(
193 pir::shr__0II(
194 pir::spawnw__Is(nqp::unbox_s($cmd)),
195 8));
196 }
197 $status;
198 }
199
d307831 @moritz Catch variable use before declaration (RT #61838)
moritz authored Nov 2, 2011
200 # XXX: Temporary definition of $Inf and $NaN until we have constants ava
201 # need to come pretty early, because we use it in lots of setting files
202 # constant Inf = ...
203 # constant NaN = ...
204 my $Inf = nqp::p6box_n(pir::set__Ns('Inf'));
205 my $NaN = nqp::p6box_n(pir::set__Ns('NaN'));
206
207
ac4d97c @masak [src/core/control.pm] add &sleep
masak authored Sep 9, 2011
208 sub sleep($seconds = $Inf) { # fractional seconds also allowed
209 my $time1 = time;
210 if $seconds ~~ $Inf {
930a1a5 @perlpilot Use nqp::sleep
perlpilot authored May 31, 2012
211 nqp::sleep(1e16) while True;
ac4d97c @masak [src/core/control.pm] add &sleep
masak authored Sep 9, 2011
212 } else {
930a1a5 @perlpilot Use nqp::sleep
perlpilot authored Jun 1, 2012
213 nqp::sleep($seconds.Num);
ac4d97c @masak [src/core/control.pm] add &sleep
masak authored Sep 9, 2011
214 }
215 my $time2 = time;
216 return $time2 - $time1;
217 }
218
251c5b3 @pmichaud Add run(), qx operator.
pmichaud authored Jul 27, 2011
219 sub QX($cmd) {
ef161f7 @perlpilot Use nqp::open
perlpilot authored May 31, 2012
220 my Mu $pio := nqp::open(nqp::unbox_s($cmd), 'rp');
251c5b3 @pmichaud Add run(), qx operator.
pmichaud authored Jul 27, 2011
221 fail "Unable to execute '$cmd'" unless $pio;
222 $pio.encoding('utf8');
223 my $result = nqp::p6box_s($pio.readall());
224 $pio.close();
225 $result;
226 }
227
53c7856 @moritz switch protos to use | instead of |$
moritz authored Aug 13, 2012
228 sub EXHAUST(|) {
69240df @moritz cut an exception type that I do not know how to trigger
moritz authored May 30, 2012
229 X::ControlFlow::Return.new.throw();
dc16a4f @pmichaud Refactor return handling to be in a single place (DRY). Handle the ca…
pmichaud authored Jun 27, 2011
230 }
Something went wrong with that request. Please try again.