This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #46947] Parse method-BLOCK arguments as a term
[perl5.git] / ext / B / t / optree_samples.t
CommitLineData
724aa791
JC
1#!perl
2
3BEGIN {
74517a3a 4 unshift @INC, 't';
9cd8f857
NC
5 require Config;
6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
8 exit 0;
9 }
27e11f68
NC
10 if (!$Config::Config{useperlio}) {
11 print "1..0 # Skip -- need perlio to walk the optree\n";
12 exit 0;
13 }
724aa791
JC
14}
15use OptreeCheck;
2ce64696 16use Config;
c23547d5 17plan tests => 46;
724aa791
JC
18
19pass("GENERAL OPTREE EXAMPLES");
20
21pass("IF,THEN,ELSE, ?:");
22
23checkOptree ( name => '-basic sub {if shift print then,else}',
24 bcopts => '-basic',
25 code => sub { if (shift) { print "then" }
26 else { print "else" }
27 },
be2b1c74 28 strip_open_hints => 1,
724aa791 29 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
538f5756
RZ
30# 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
31# - <@> lineseq KP ->7
4e2ac264 32# 1 <;> nextstate(main 665 optree_samples.t:24) v:>,<,% ->2
724aa791 33# - <1> null K/1 ->-
538f5756
RZ
34# 3 <|> cond_expr(other->4) K/1 ->8
35# 2 <0> shift s* ->3
724aa791 36# - <@> scope K ->-
538f5756
RZ
37# - <0> ex-nextstate v ->4
38# 6 <@> print sK ->7
39# 4 <0> pushmark s ->5
40# 5 <$> const[PV "then"] s ->6
41# d <@> leave KP ->7
42# 8 <0> enter ->9
4e2ac264 43# 9 <;> nextstate(main 663 optree_samples.t:25) v:>,<,% ->a
538f5756
RZ
44# c <@> print sK ->d
45# a <0> pushmark s ->b
46# b <$> const[PV "else"] s ->c
724aa791 47EOT_EOT
538f5756
RZ
48# 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
49# - <@> lineseq KP ->7
4e2ac264 50# 1 <;> nextstate(main 665 optree_samples.t:24) v:>,<,% ->2
724aa791 51# - <1> null K/1 ->-
538f5756
RZ
52# 3 <|> cond_expr(other->4) K/1 ->8
53# 2 <0> shift s* ->3
724aa791 54# - <@> scope K ->-
538f5756
RZ
55# - <0> ex-nextstate v ->4
56# 6 <@> print sK ->7
57# 4 <0> pushmark s ->5
58# 5 <$> const(PV "then") s ->6
59# d <@> leave KP ->7
60# 8 <0> enter ->9
4e2ac264 61# 9 <;> nextstate(main 663 optree_samples.t:25) v:>,<,% ->a
538f5756
RZ
62# c <@> print sK ->d
63# a <0> pushmark s ->b
64# b <$> const(PV "else") s ->c
724aa791
JC
65EONT_EONT
66
67checkOptree ( name => '-basic (see above, with my $a = shift)',
68 bcopts => '-basic',
69 code => sub { my $a = shift;
70 if ($a) { print "foo" }
71 else { print "bar" }
72 },
be2b1c74 73 strip_open_hints => 1,
724aa791 74 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
538f5756
RZ
75# b <1> leavesub[1 ref] K/REFC,1 ->(end)
76# - <@> lineseq KP ->b
4e2ac264 77# 1 <;> nextstate(main 666 optree_samples.t:70) v:>,<,% ->2
538f5756
RZ
78# 4 <2> sassign vKS/2 ->5
79# 2 <0> shift s* ->3
80# 3 <0> padsv[$a:666,670] sRM*/LVINTRO ->4
4e2ac264 81# 5 <;> nextstate(main 670 optree_samples.t:71) v:>,<,% ->6
724aa791 82# - <1> null K/1 ->-
538f5756
RZ
83# 7 <|> cond_expr(other->8) K/1 ->c
84# 6 <0> padsv[$a:666,670] s ->7
724aa791 85# - <@> scope K ->-
538f5756
RZ
86# - <0> ex-nextstate v ->8
87# a <@> print sK ->b
88# 8 <0> pushmark s ->9
89# 9 <$> const[PV "foo"] s ->a
90# h <@> leave KP ->b
91# c <0> enter ->d
4e2ac264 92# d <;> nextstate(main 668 optree_samples.t:72) v:>,<,% ->e
538f5756
RZ
93# g <@> print sK ->h
94# e <0> pushmark s ->f
95# f <$> const[PV "bar"] s ->g
724aa791 96EOT_EOT
538f5756
RZ
97# b <1> leavesub[1 ref] K/REFC,1 ->(end)
98# - <@> lineseq KP ->b
4e2ac264 99# 1 <;> nextstate(main 666 optree_samples.t:72) v:>,<,% ->2
538f5756
RZ
100# 4 <2> sassign vKS/2 ->5
101# 2 <0> shift s* ->3
102# 3 <0> padsv[$a:666,670] sRM*/LVINTRO ->4
4e2ac264 103# 5 <;> nextstate(main 670 optree_samples.t:73) v:>,<,% ->6
724aa791 104# - <1> null K/1 ->-
538f5756
RZ
105# 7 <|> cond_expr(other->8) K/1 ->c
106# 6 <0> padsv[$a:666,670] s ->7
724aa791 107# - <@> scope K ->-
538f5756
RZ
108# - <0> ex-nextstate v ->8
109# a <@> print sK ->b
110# 8 <0> pushmark s ->9
111# 9 <$> const(PV "foo") s ->a
112# h <@> leave KP ->b
113# c <0> enter ->d
4e2ac264 114# d <;> nextstate(main 668 optree_samples.t:74) v:>,<,% ->e
538f5756
RZ
115# g <@> print sK ->h
116# e <0> pushmark s ->f
117# f <$> const(PV "bar") s ->g
724aa791
JC
118EONT_EONT
119
120checkOptree ( name => '-exec sub {if shift print then,else}',
121 bcopts => '-exec',
122 code => sub { if (shift) { print "then" }
123 else { print "else" }
124 },
be2b1c74 125 strip_open_hints => 1,
724aa791 126 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
4e2ac264 127# 1 <;> nextstate(main 674 optree_samples.t:125) v:>,<,%
538f5756
RZ
128# 2 <0> shift s*
129# 3 <|> cond_expr(other->4) K/1
130# 4 <0> pushmark s
131# 5 <$> const[PV "then"] s
132# 6 <@> print sK
133# goto 7
134# 8 <0> enter
4e2ac264 135# 9 <;> nextstate(main 672 optree_samples.t:126) v:>,<,%
538f5756
RZ
136# a <0> pushmark s
137# b <$> const[PV "else"] s
138# c <@> print sK
139# d <@> leave KP
140# 7 <1> leavesub[1 ref] K/REFC,1
724aa791 141EOT_EOT
4e2ac264 142# 1 <;> nextstate(main 674 optree_samples.t:129) v:>,<,%
538f5756
RZ
143# 2 <0> shift s*
144# 3 <|> cond_expr(other->4) K/1
145# 4 <0> pushmark s
146# 5 <$> const(PV "then") s
147# 6 <@> print sK
148# goto 7
149# 8 <0> enter
4e2ac264 150# 9 <;> nextstate(main 672 optree_samples.t:130) v:>,<,%
538f5756
RZ
151# a <0> pushmark s
152# b <$> const(PV "else") s
153# c <@> print sK
154# d <@> leave KP
155# 7 <1> leavesub[1 ref] K/REFC,1
724aa791
JC
156EONT_EONT
157
158checkOptree ( name => '-exec (see above, with my $a = shift)',
159 bcopts => '-exec',
160 code => sub { my $a = shift;
161 if ($a) { print "foo" }
162 else { print "bar" }
163 },
be2b1c74 164 strip_open_hints => 1,
724aa791 165 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
4e2ac264 166# 1 <;> nextstate(main 675 optree_samples.t:165) v:>,<,%
538f5756
RZ
167# 2 <0> shift s*
168# 3 <0> padsv[$a:675,679] sRM*/LVINTRO
169# 4 <2> sassign vKS/2
4e2ac264 170# 5 <;> nextstate(main 679 optree_samples.t:166) v:>,<,%
538f5756
RZ
171# 6 <0> padsv[$a:675,679] s
172# 7 <|> cond_expr(other->8) K/1
173# 8 <0> pushmark s
174# 9 <$> const[PV "foo"] s
175# a <@> print sK
176# goto b
177# c <0> enter
4e2ac264 178# d <;> nextstate(main 677 optree_samples.t:167) v:>,<,%
538f5756
RZ
179# e <0> pushmark s
180# f <$> const[PV "bar"] s
181# g <@> print sK
182# h <@> leave KP
183# b <1> leavesub[1 ref] K/REFC,1
724aa791 184EOT_EOT
4e2ac264 185# 1 <;> nextstate(main 675 optree_samples.t:171) v:>,<,%
538f5756
RZ
186# 2 <0> shift s*
187# 3 <0> padsv[$a:675,679] sRM*/LVINTRO
188# 4 <2> sassign vKS/2
4e2ac264 189# 5 <;> nextstate(main 679 optree_samples.t:172) v:>,<,%
538f5756
RZ
190# 6 <0> padsv[$a:675,679] s
191# 7 <|> cond_expr(other->8) K/1
192# 8 <0> pushmark s
193# 9 <$> const(PV "foo") s
194# a <@> print sK
195# goto b
196# c <0> enter
4e2ac264 197# d <;> nextstate(main 677 optree_samples.t:173) v:>,<,%
538f5756
RZ
198# e <0> pushmark s
199# f <$> const(PV "bar") s
200# g <@> print sK
201# h <@> leave KP
202# b <1> leavesub[1 ref] K/REFC,1
724aa791
JC
203EONT_EONT
204
205checkOptree ( name => '-exec sub { print (shift) ? "foo" : "bar" }',
206 code => sub { print (shift) ? "foo" : "bar" },
207 bcopts => '-exec',
be2b1c74 208 strip_open_hints => 1,
724aa791 209 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
4e2ac264 210# 1 <;> nextstate(main 680 optree_samples.t:213) v:>,<,%
724aa791 211# 2 <0> pushmark s
538f5756
RZ
212# 3 <0> shift s*
213# 4 <@> print sK
214# 5 <|> cond_expr(other->6) K/1
215# 6 <$> const[PV "foo"] s
216# goto 7
217# 8 <$> const[PV "bar"] s
218# 7 <1> leavesub[1 ref] K/REFC,1
724aa791 219EOT_EOT
4e2ac264 220# 1 <;> nextstate(main 680 optree_samples.t:221) v:>,<,%
724aa791 221# 2 <0> pushmark s
538f5756
RZ
222# 3 <0> shift s*
223# 4 <@> print sK
224# 5 <|> cond_expr(other->6) K/1
225# 6 <$> const(PV "foo") s
226# goto 7
227# 8 <$> const(PV "bar") s
228# 7 <1> leavesub[1 ref] K/REFC,1
724aa791
JC
229EONT_EONT
230
231pass ("FOREACH");
232
233checkOptree ( name => '-exec sub { foreach (1..10) {print "foo $_"} }',
234 code => sub { foreach (1..10) {print "foo $_"} },
235 bcopts => '-exec',
be2b1c74 236 strip_open_hints => 1,
724aa791 237 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
be2b1c74 238# 1 <;> nextstate(main 443 optree.t:158) v:>,<,%
724aa791
JC
239# 2 <0> pushmark s
240# 3 <$> const[IV 1] s
241# 4 <$> const[IV 10] s
242# 5 <#> gv[*_] s
0d863452 243# 6 <{> enteriter(next->d last->g redo->7) lKS/8
724aa791
JC
244# e <0> iter s
245# f <|> and(other->7) K/1
be2b1c74 246# 7 <;> nextstate(main 442 optree.t:158) v:>,<,%
724aa791
JC
247# 8 <0> pushmark s
248# 9 <$> const[PV "foo "] s
249# a <#> gvsv[*_] s
250# b <2> concat[t4] sK/2
251# c <@> print vK
252# d <0> unstack s
253# goto e
254# g <2> leaveloop K/2
255# h <1> leavesub[1 ref] K/REFC,1
724aa791 256EOT_EOT
be2b1c74 257# 1 <;> nextstate(main 444 optree_samples.t:182) v:>,<,%
724aa791
JC
258# 2 <0> pushmark s
259# 3 <$> const(IV 1) s
260# 4 <$> const(IV 10) s
261# 5 <$> gv(*_) s
0d863452 262# 6 <{> enteriter(next->d last->g redo->7) lKS/8
724aa791
JC
263# e <0> iter s
264# f <|> and(other->7) K/1
be2b1c74 265# 7 <;> nextstate(main 443 optree_samples.t:182) v:>,<,%
724aa791
JC
266# 8 <0> pushmark s
267# 9 <$> const(PV "foo ") s
268# a <$> gvsv(*_) s
269# b <2> concat[t3] sK/2
270# c <@> print vK
271# d <0> unstack s
272# goto e
273# g <2> leaveloop K/2
274# h <1> leavesub[1 ref] K/REFC,1
275EONT_EONT
276
277checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
278 code => sub { print "foo $_" foreach (1..10) },
279 bcopts => '-basic',
be2b1c74 280 strip_open_hints => 1,
724aa791 281 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
ac56e7de
NC
282# g <1> leavesub[1 ref] K/REFC,1 ->(end)
283# - <@> lineseq KP ->g
be2b1c74 284# 1 <;> nextstate(main 445 optree.t:167) v:>,<,% ->2
ac56e7de
NC
285# f <2> leaveloop K/2 ->g
286# 6 <{> enteriter(next->c last->f redo->7) lKS/8 ->d
287# - <0> ex-pushmark s ->2
288# - <1> ex-list lK ->5
289# 2 <0> pushmark s ->3
290# 3 <$> const[IV 1] s ->4
291# 4 <$> const[IV 10] s ->5
292# 5 <#> gv[*_] s ->6
293# - <1> null K/1 ->f
294# e <|> and(other->7) K/1 ->f
295# d <0> iter s ->e
724aa791 296# - <@> lineseq sK ->-
ac56e7de
NC
297# b <@> print vK ->c
298# 7 <0> pushmark s ->8
299# - <1> ex-stringify sK/1 ->b
300# - <0> ex-pushmark s ->8
301# a <2> concat[t2] sK/2 ->b
302# 8 <$> const[PV "foo "] s ->9
303# - <1> ex-rv2sv sK/1 ->a
304# 9 <#> gvsv[*_] s ->a
305# c <0> unstack s ->d
724aa791 306EOT_EOT
ac56e7de
NC
307# g <1> leavesub[1 ref] K/REFC,1 ->(end)
308# - <@> lineseq KP ->g
be2b1c74 309# 1 <;> nextstate(main 446 optree_samples.t:192) v:>,<,% ->2
ac56e7de
NC
310# f <2> leaveloop K/2 ->g
311# 6 <{> enteriter(next->c last->f redo->7) lKS/8 ->d
312# - <0> ex-pushmark s ->2
313# - <1> ex-list lK ->5
314# 2 <0> pushmark s ->3
315# 3 <$> const(IV 1) s ->4
316# 4 <$> const(IV 10) s ->5
317# 5 <$> gv(*_) s ->6
318# - <1> null K/1 ->f
319# e <|> and(other->7) K/1 ->f
320# d <0> iter s ->e
724aa791 321# - <@> lineseq sK ->-
ac56e7de
NC
322# b <@> print vK ->c
323# 7 <0> pushmark s ->8
324# - <1> ex-stringify sK/1 ->b
325# - <0> ex-pushmark s ->8
326# a <2> concat[t1] sK/2 ->b
327# 8 <$> const(PV "foo ") s ->9
328# - <1> ex-rv2sv sK/1 ->a
329# 9 <$> gvsv(*_) s ->a
330# c <0> unstack s ->d
724aa791
JC
331EONT_EONT
332
498d59dd
SH
333checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
334 prog => 'foreach (1..10) {print qq{foo $_}}',
724aa791 335 bcopts => '-exec',
be2b1c74 336 strip_open_hints => 1,
724aa791
JC
337 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
338# 1 <0> enter
eae48c89 339# 2 <;> nextstate(main 2 -e:1) v:>,<,%,{
724aa791
JC
340# 3 <0> pushmark s
341# 4 <$> const[IV 1] s
342# 5 <$> const[IV 10] s
343# 6 <#> gv[*_] s
0d863452 344# 7 <{> enteriter(next->e last->h redo->8) lKS/8
724aa791
JC
345# f <0> iter s
346# g <|> and(other->8) vK/1
be2b1c74 347# 8 <;> nextstate(main 1 -e:1) v:>,<,%
724aa791
JC
348# 9 <0> pushmark s
349# a <$> const[PV "foo "] s
350# b <#> gvsv[*_] s
351# c <2> concat[t4] sK/2
352# d <@> print vK
353# e <0> unstack v
354# goto f
355# h <2> leaveloop vK/2
356# i <@> leave[1 ref] vKP/REFC
357EOT_EOT
358# 1 <0> enter
eae48c89 359# 2 <;> nextstate(main 2 -e:1) v:>,<,%,{
724aa791
JC
360# 3 <0> pushmark s
361# 4 <$> const(IV 1) s
362# 5 <$> const(IV 10) s
363# 6 <$> gv(*_) s
0d863452 364# 7 <{> enteriter(next->e last->h redo->8) lKS/8
724aa791
JC
365# f <0> iter s
366# g <|> and(other->8) vK/1
be2b1c74 367# 8 <;> nextstate(main 1 -e:1) v:>,<,%
724aa791
JC
368# 9 <0> pushmark s
369# a <$> const(PV "foo ") s
370# b <$> gvsv(*_) s
371# c <2> concat[t3] sK/2
372# d <@> print vK
373# e <0> unstack v
374# goto f
375# h <2> leaveloop vK/2
376# i <@> leave[1 ref] vKP/REFC
724aa791
JC
377EONT_EONT
378
379checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
380 code => sub { print "foo $_" foreach (1..10) },
381 bcopts => '-exec',
be2b1c74 382 strip_open_hints => 1,
724aa791 383 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
be2b1c74 384# 1 <;> nextstate(main 445 optree.t:167) v:>,<,%
ac56e7de
NC
385# 2 <0> pushmark s
386# 3 <$> const[IV 1] s
387# 4 <$> const[IV 10] s
388# 5 <#> gv[*_] s
389# 6 <{> enteriter(next->c last->f redo->7) lKS/8
390# d <0> iter s
391# e <|> and(other->7) K/1
392# 7 <0> pushmark s
393# 8 <$> const[PV "foo "] s
394# 9 <#> gvsv[*_] s
395# a <2> concat[t2] sK/2
396# b <@> print vK
397# c <0> unstack s
398# goto d
399# f <2> leaveloop K/2
400# g <1> leavesub[1 ref] K/REFC,1
724aa791 401EOT_EOT
be2b1c74 402# 1 <;> nextstate(main 447 optree_samples.t:252) v:>,<,%
ac56e7de
NC
403# 2 <0> pushmark s
404# 3 <$> const(IV 1) s
405# 4 <$> const(IV 10) s
406# 5 <$> gv(*_) s
407# 6 <{> enteriter(next->c last->f redo->7) lKS/8
408# d <0> iter s
409# e <|> and(other->7) K/1
410# 7 <0> pushmark s
411# 8 <$> const(PV "foo ") s
412# 9 <$> gvsv(*_) s
413# a <2> concat[t1] sK/2
414# b <@> print vK
415# c <0> unstack s
416# goto d
417# f <2> leaveloop K/2
418# g <1> leavesub[1 ref] K/REFC,1
724aa791
JC
419EONT_EONT
420
cc02ea56
JC
421pass("GREP: SAMPLES FROM PERLDOC -F GREP");
422
423checkOptree ( name => '@foo = grep(!/^\#/, @bar)',
424 code => '@foo = grep(!/^\#/, @bar)',
425 bcopts => '-exec',
426 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
d1718a7c 427# 1 <;> nextstate(main 496 (eval 20):1) v:{
cc02ea56
JC
428# 2 <0> pushmark s
429# 3 <0> pushmark s
430# 4 <#> gv[*bar] s
431# 5 <1> rv2av[t4] lKM/1
432# 6 <@> grepstart lK
433# 7 <|> grepwhile(other->8)[t5] lK
434# 8 </> match(/"^#"/) s/RTIME
435# 9 <1> not sK/1
436# goto 7
437# a <0> pushmark s
438# b <#> gv[*foo] s
439# c <1> rv2av[t2] lKRM*/1
440# d <2> aassign[t6] KS/COMMON
441# e <1> leavesub[1 ref] K/REFC,1
442EOT_EOT
d1718a7c 443# 1 <;> nextstate(main 496 (eval 20):1) v:{
cc02ea56
JC
444# 2 <0> pushmark s
445# 3 <0> pushmark s
446# 4 <$> gv(*bar) s
447# 5 <1> rv2av[t2] lKM/1
448# 6 <@> grepstart lK
449# 7 <|> grepwhile(other->8)[t3] lK
450# 8 </> match(/"^\\#"/) s/RTIME
451# 9 <1> not sK/1
452# goto 7
453# a <0> pushmark s
454# b <$> gv(*foo) s
455# c <1> rv2av[t1] lKRM*/1
456# d <2> aassign[t4] KS/COMMON
457# e <1> leavesub[1 ref] K/REFC,1
458EONT_EONT
459
460
461pass("MAP: SAMPLES FROM PERLDOC -F MAP");
462
463checkOptree ( name => '%h = map { getkey($_) => $_ } @a',
464 code => '%h = map { getkey($_) => $_ } @a',
465 bcopts => '-exec',
466 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
d1718a7c 467# 1 <;> nextstate(main 501 (eval 22):1) v:{
cc02ea56
JC
468# 2 <0> pushmark s
469# 3 <0> pushmark s
470# 4 <#> gv[*a] s
471# 5 <1> rv2av[t8] lKM/1
82aeefe1
DM
472# 6 <@> mapstart lK* < 5.017002
473# 6 <@> mapstart lK >=5.017002
cc02ea56
JC
474# 7 <|> mapwhile(other->8)[t9] lK
475# 8 <0> enter l
d1718a7c 476# 9 <;> nextstate(main 500 (eval 22):1) v:{
cc02ea56 477# a <0> pushmark s
7d3c8a68
S
478# b <#> gvsv[*_] s
479# c <#> gv[*getkey] s/EARLYCV
480# d <1> entersub[t5] lKS/TARG
481# e <#> gvsv[*_] s
482# f <@> leave lKP
cc02ea56 483# goto 7
7d3c8a68
S
484# g <0> pushmark s
485# h <#> gv[*h] s
486# i <1> rv2hv[t2] lKRM*/1 < 5.019006
487# i <1> rv2hv lKRM*/1 >=5.019006
488# j <2> aassign[t10] KS/COMMON
489# k <1> leavesub[1 ref] K/REFC,1
cc02ea56 490EOT_EOT
d1718a7c 491# 1 <;> nextstate(main 501 (eval 22):1) v:{
cc02ea56
JC
492# 2 <0> pushmark s
493# 3 <0> pushmark s
494# 4 <$> gv(*a) s
495# 5 <1> rv2av[t3] lKM/1
82aeefe1
DM
496# 6 <@> mapstart lK* < 5.017002
497# 6 <@> mapstart lK >=5.017002
cc02ea56
JC
498# 7 <|> mapwhile(other->8)[t4] lK
499# 8 <0> enter l
d1718a7c 500# 9 <;> nextstate(main 500 (eval 22):1) v:{
cc02ea56 501# a <0> pushmark s
7d3c8a68
S
502# b <$> gvsv(*_) s
503# c <$> gv(*getkey) s/EARLYCV
504# d <1> entersub[t2] lKS/TARG
505# e <$> gvsv(*_) s
506# f <@> leave lKP
cc02ea56 507# goto 7
7d3c8a68
S
508# g <0> pushmark s
509# h <$> gv(*h) s
510# i <1> rv2hv[t1] lKRM*/1 < 5.019006
511# i <1> rv2hv lKRM*/1 >=5.019006
512# j <2> aassign[t5] KS/COMMON
513# k <1> leavesub[1 ref] K/REFC,1
cc02ea56
JC
514EONT_EONT
515
516checkOptree ( name => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
517 code => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
518 bcopts => '-exec',
519 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
d1718a7c 520# 1 <;> nextstate(main 505 (eval 24):1) v
cc02ea56
JC
521# 2 <0> pushmark s
522# 3 <0> pushmark s
523# 4 <#> gv[*h] s
1a8bdda9
FC
524# 5 <1> rv2hv[t2] lKRM*/1 < 5.019006
525# 5 <1> rv2hv lKRM*/1 >=5.019006
cc02ea56 526# 6 <2> aassign[t3] vKS
d1718a7c 527# 7 <;> nextstate(main 506 (eval 24):1) v:{
cc02ea56
JC
528# 8 <0> pushmark sM
529# 9 <#> gv[*a] s
530# a <1> rv2av[t6] sKRM/1
531# b <#> gv[*_] s
532# c <1> rv2gv sKRM/1
0d863452 533# d <{> enteriter(next->o last->r redo->e) lKS/8
cc02ea56
JC
534# p <0> iter s
535# q <|> and(other->e) K/1
d1718a7c 536# e <;> nextstate(main 505 (eval 24):1) v:{
cc02ea56
JC
537# f <#> gvsv[*_] s
538# g <#> gv[*h] s
539# h <1> rv2hv sKR/1
540# i <0> pushmark s
541# j <#> gvsv[*_] s
542# k <#> gv[*getkey] s/EARLYCV
767eda44 543# l <1> entersub[t10] sKS/TARG
cc02ea56
JC
544# m <2> helem sKRM*/2
545# n <2> sassign vKS/2
546# o <0> unstack s
547# goto p
eae48c89 548# r <2> leaveloop KP/2
cc02ea56
JC
549# s <1> leavesub[1 ref] K/REFC,1
550EOT_EOT
d1718a7c 551# 1 <;> nextstate(main 505 (eval 24):1) v
cc02ea56
JC
552# 2 <0> pushmark s
553# 3 <0> pushmark s
554# 4 <$> gv(*h) s
1a8bdda9
FC
555# 5 <1> rv2hv[t1] lKRM*/1 < 5.019006
556# 5 <1> rv2hv lKRM*/1 >=5.019006
cc02ea56 557# 6 <2> aassign[t2] vKS
d1718a7c 558# 7 <;> nextstate(main 506 (eval 24):1) v:{
cc02ea56
JC
559# 8 <0> pushmark sM
560# 9 <$> gv(*a) s
561# a <1> rv2av[t3] sKRM/1
562# b <$> gv(*_) s
563# c <1> rv2gv sKRM/1
0d863452 564# d <{> enteriter(next->o last->r redo->e) lKS/8
cc02ea56
JC
565# p <0> iter s
566# q <|> and(other->e) K/1
d1718a7c 567# e <;> nextstate(main 505 (eval 24):1) v:{
cc02ea56
JC
568# f <$> gvsv(*_) s
569# g <$> gv(*h) s
570# h <1> rv2hv sKR/1
571# i <0> pushmark s
572# j <$> gvsv(*_) s
573# k <$> gv(*getkey) s/EARLYCV
767eda44 574# l <1> entersub[t4] sKS/TARG
cc02ea56
JC
575# m <2> helem sKRM*/2
576# n <2> sassign vKS/2
577# o <0> unstack s
578# goto p
eae48c89 579# r <2> leaveloop KP/2
cc02ea56
JC
580# s <1> leavesub[1 ref] K/REFC,1
581EONT_EONT
582
583checkOptree ( name => 'map $_+42, 10..20',
584 code => 'map $_+42, 10..20',
585 bcopts => '-exec',
586 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
d1718a7c 587# 1 <;> nextstate(main 497 (eval 20):1) v
cc02ea56
JC
588# 2 <0> pushmark s
589# 3 <$> const[AV ] s
590# 4 <1> rv2av lKPM/1
591# 5 <@> mapstart K
9ad9869c 592# 6 <|> mapwhile(other->7)[t5] K
cc02ea56
JC
593# 7 <#> gvsv[*_] s
594# 8 <$> const[IV 42] s
595# 9 <2> add[t2] sK/2
596# goto 6
597# a <1> leavesub[1 ref] K/REFC,1
598EOT_EOT
d1718a7c 599# 1 <;> nextstate(main 511 (eval 26):1) v
cc02ea56
JC
600# 2 <0> pushmark s
601# 3 <$> const(AV ) s
602# 4 <1> rv2av lKPM/1
603# 5 <@> mapstart K
604# 6 <|> mapwhile(other->7)[t4] K
605# 7 <$> gvsv(*_) s
606# 8 <$> const(IV 42) s
607# 9 <2> add[t1] sK/2
608# goto 6
609# a <1> leavesub[1 ref] K/REFC,1
610EONT_EONT
611
612pass("CONSTANTS");
613
498d59dd
SH
614checkOptree ( name => '-e use constant j => qq{junk}; print j',
615 prog => 'use constant j => qq{junk}; print j',
724aa791 616 bcopts => '-exec',
be2b1c74 617 strip_open_hints => 1,
724aa791
JC
618 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
619# 1 <0> enter
be2b1c74 620# 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
724aa791 621# 3 <0> pushmark s
82aeefe1
DM
622# 4 <$> const[PV "junk"] s* < 5.017002
623# 4 <$> const[PV "junk"] s*/FOLD >=5.017002
724aa791
JC
624# 5 <@> print vK
625# 6 <@> leave[1 ref] vKP/REFC
626EOT_EOT
627# 1 <0> enter
be2b1c74 628# 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
724aa791 629# 3 <0> pushmark s
82aeefe1
DM
630# 4 <$> const(PV "junk") s* < 5.017002
631# 4 <$> const(PV "junk") s*/FOLD >=5.017002
724aa791
JC
632# 5 <@> print vK
633# 6 <@> leave[1 ref] vKP/REFC
634EONT_EONT
635
437e3a7d
MH
636pass("rpeep - return \$x at end of sub");
637
638checkOptree ( name => '-exec sub { return 1 }',
639 code => sub { return 1 },
640 bcopts => '-exec',
641 strip_open_hints => 1,
642 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
0a60c50b 643# 1 <;> nextstate(main 1 -e:1) v:>,<,%
437e3a7d
MH
644# 2 <$> const[IV 1] s
645# 3 <1> leavesub[1 ref] K/REFC,1
646EOT_EOT
0a60c50b 647# 1 <;> nextstate(main 1 -e:1) v:>,<,%
437e3a7d
MH
648# 2 <$> const(IV 1) s
649# 3 <1> leavesub[1 ref] K/REFC,1
650EONT_EONT
651
4cb2d3f8
MH
652pass("rpeep - if ($a || $b)");
653
654checkOptree ( name => 'if ($a || $b) { } return 1',
655 code => 'if ($a || $b) { } return 1',
656 bcopts => '-exec',
657 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
658# 1 <;> nextstate(main 997 (eval 15):1) v
659# 2 <#> gvsv[*a] s
660# 3 <|> or(other->4) sK/1
661# 4 <#> gvsv[*b] s
662# 5 <|> and(other->6) vK/1
663# 6 <0> stub v
664# 7 <;> nextstate(main 997 (eval 15):1) v
665# 8 <$> const[IV 1] s
666# 9 <1> leavesub[1 ref] K/REFC,1
667EOT_EOT
668# 1 <;> nextstate(main 997 (eval 15):1) v
669# 2 <$> gvsv(*a) s
670# 3 <|> or(other->4) sK/1
671# 4 <$> gvsv(*b) s
672# 5 <|> and(other->6) vK/1
673# 6 <0> stub v
674# 7 <;> nextstate(main 3 (eval 3):1) v
675# 8 <$> const(IV 1) s
676# 9 <1> leavesub[1 ref] K/REFC,1
677EONT_EONT
678
679pass("rpeep - unless ($a && $b)");
680
681checkOptree ( name => 'unless ($a && $b) { } return 1',
682 code => 'unless ($a && $b) { } return 1',
683 bcopts => '-exec',
684 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
685# 1 <;> nextstate(main 997 (eval 15):1) v
686# 2 <#> gvsv[*a] s
687# 3 <|> and(other->4) sK/1
688# 4 <#> gvsv[*b] s
689# 5 <|> or(other->6) vK/1
690# 6 <0> stub v
691# 7 <;> nextstate(main 997 (eval 15):1) v
692# 8 <$> const[IV 1] s
693# 9 <1> leavesub[1 ref] K/REFC,1
694EOT_EOT
695# 1 <;> nextstate(main 997 (eval 15):1) v
696# 2 <$> gvsv(*a) s
697# 3 <|> and(other->4) sK/1
698# 4 <$> gvsv(*b) s
699# 5 <|> or(other->6) vK/1
700# 6 <0> stub v
701# 7 <;> nextstate(main 3 (eval 3):1) v
702# 8 <$> const(IV 1) s
703# 9 <1> leavesub[1 ref] K/REFC,1
704EONT_EONT
705
c23547d5
MH
706pass("rpeep - my $a; my @b; my %c; print 'f'");
707
708checkOptree ( name => 'my $a; my @b; my %c; return 1',
709 code => 'my $a; my @b; my %c; return 1',
710 bcopts => '-exec',
711 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
712# 1 <;> nextstate(main 991 (eval 17):1) v
713# 2 <0> padrange[$a:991,994; @b:992,994; %c:993,994] vM/LVINTRO,3
714# 3 <;> nextstate(main 994 (eval 17):1) v:{
715# 4 <$> const[IV 1] s
716# 5 <1> leavesub[1 ref] K/REFC,1
717EOT_EOT
718# 1 <;> nextstate(main 991 (eval 17):1) v
719# 2 <0> padrange[$a:991,994; @b:992,994; %c:993,994] vM/LVINTRO,3
720# 3 <;> nextstate(main 994 (eval 17):1) v:{
721# 4 <$> const(IV 1) s
722# 5 <1> leavesub[1 ref] K/REFC,1
723EONT_EONT
724
724aa791
JC
725__END__
726
727#######################################################################
728
729checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
730 code => sub { print (shift) ? "foo" : "bar" },
731 bcopts => '-exec',
732 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
733 insert threaded reference here
734EOT_EOT
735 insert non-threaded reference here
736EONT_EONT
737