This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #121104] avoid using a less sane find(1)
[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;
4cb2d3f8 17plan tests => 43;
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
JC
477# a <0> pushmark s
478# b <0> pushmark s
479# c <#> gvsv[*_] s
480# d <#> gv[*getkey] s/EARLYCV
767eda44 481# e <1> entersub[t5] lKS/TARG
cc02ea56
JC
482# f <#> gvsv[*_] s
483# g <@> list lK
484# h <@> leave lKP
485# goto 7
486# i <0> pushmark s
487# j <#> gv[*h] s
1a8bdda9
FC
488# k <1> rv2hv[t2] lKRM*/1 < 5.019006
489# k <1> rv2hv lKRM*/1 >=5.019006
cc02ea56
JC
490# l <2> aassign[t10] KS/COMMON
491# m <1> leavesub[1 ref] K/REFC,1
492EOT_EOT
d1718a7c 493# 1 <;> nextstate(main 501 (eval 22):1) v:{
cc02ea56
JC
494# 2 <0> pushmark s
495# 3 <0> pushmark s
496# 4 <$> gv(*a) s
497# 5 <1> rv2av[t3] lKM/1
82aeefe1
DM
498# 6 <@> mapstart lK* < 5.017002
499# 6 <@> mapstart lK >=5.017002
cc02ea56
JC
500# 7 <|> mapwhile(other->8)[t4] lK
501# 8 <0> enter l
d1718a7c 502# 9 <;> nextstate(main 500 (eval 22):1) v:{
cc02ea56
JC
503# a <0> pushmark s
504# b <0> pushmark s
505# c <$> gvsv(*_) s
506# d <$> gv(*getkey) s/EARLYCV
767eda44 507# e <1> entersub[t2] lKS/TARG
cc02ea56
JC
508# f <$> gvsv(*_) s
509# g <@> list lK
510# h <@> leave lKP
511# goto 7
512# i <0> pushmark s
513# j <$> gv(*h) s
1a8bdda9
FC
514# k <1> rv2hv[t1] lKRM*/1 < 5.019006
515# k <1> rv2hv lKRM*/1 >=5.019006
cc02ea56
JC
516# l <2> aassign[t5] KS/COMMON
517# m <1> leavesub[1 ref] K/REFC,1
518EONT_EONT
519
520checkOptree ( name => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
521 code => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
522 bcopts => '-exec',
523 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
d1718a7c 524# 1 <;> nextstate(main 505 (eval 24):1) v
cc02ea56
JC
525# 2 <0> pushmark s
526# 3 <0> pushmark s
527# 4 <#> gv[*h] s
1a8bdda9
FC
528# 5 <1> rv2hv[t2] lKRM*/1 < 5.019006
529# 5 <1> rv2hv lKRM*/1 >=5.019006
cc02ea56 530# 6 <2> aassign[t3] vKS
d1718a7c 531# 7 <;> nextstate(main 506 (eval 24):1) v:{
cc02ea56
JC
532# 8 <0> pushmark sM
533# 9 <#> gv[*a] s
534# a <1> rv2av[t6] sKRM/1
535# b <#> gv[*_] s
536# c <1> rv2gv sKRM/1
0d863452 537# d <{> enteriter(next->o last->r redo->e) lKS/8
cc02ea56
JC
538# p <0> iter s
539# q <|> and(other->e) K/1
d1718a7c 540# e <;> nextstate(main 505 (eval 24):1) v:{
cc02ea56
JC
541# f <#> gvsv[*_] s
542# g <#> gv[*h] s
543# h <1> rv2hv sKR/1
544# i <0> pushmark s
545# j <#> gvsv[*_] s
546# k <#> gv[*getkey] s/EARLYCV
767eda44 547# l <1> entersub[t10] sKS/TARG
cc02ea56
JC
548# m <2> helem sKRM*/2
549# n <2> sassign vKS/2
550# o <0> unstack s
551# goto p
eae48c89 552# r <2> leaveloop KP/2
cc02ea56
JC
553# s <1> leavesub[1 ref] K/REFC,1
554EOT_EOT
d1718a7c 555# 1 <;> nextstate(main 505 (eval 24):1) v
cc02ea56
JC
556# 2 <0> pushmark s
557# 3 <0> pushmark s
558# 4 <$> gv(*h) s
1a8bdda9
FC
559# 5 <1> rv2hv[t1] lKRM*/1 < 5.019006
560# 5 <1> rv2hv lKRM*/1 >=5.019006
cc02ea56 561# 6 <2> aassign[t2] vKS
d1718a7c 562# 7 <;> nextstate(main 506 (eval 24):1) v:{
cc02ea56
JC
563# 8 <0> pushmark sM
564# 9 <$> gv(*a) s
565# a <1> rv2av[t3] sKRM/1
566# b <$> gv(*_) s
567# c <1> rv2gv sKRM/1
0d863452 568# d <{> enteriter(next->o last->r redo->e) lKS/8
cc02ea56
JC
569# p <0> iter s
570# q <|> and(other->e) K/1
d1718a7c 571# e <;> nextstate(main 505 (eval 24):1) v:{
cc02ea56
JC
572# f <$> gvsv(*_) s
573# g <$> gv(*h) s
574# h <1> rv2hv sKR/1
575# i <0> pushmark s
576# j <$> gvsv(*_) s
577# k <$> gv(*getkey) s/EARLYCV
767eda44 578# l <1> entersub[t4] sKS/TARG
cc02ea56
JC
579# m <2> helem sKRM*/2
580# n <2> sassign vKS/2
581# o <0> unstack s
582# goto p
eae48c89 583# r <2> leaveloop KP/2
cc02ea56
JC
584# s <1> leavesub[1 ref] K/REFC,1
585EONT_EONT
586
587checkOptree ( name => 'map $_+42, 10..20',
588 code => 'map $_+42, 10..20',
589 bcopts => '-exec',
590 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
d1718a7c 591# 1 <;> nextstate(main 497 (eval 20):1) v
cc02ea56
JC
592# 2 <0> pushmark s
593# 3 <$> const[AV ] s
594# 4 <1> rv2av lKPM/1
595# 5 <@> mapstart K
9ad9869c 596# 6 <|> mapwhile(other->7)[t5] K
cc02ea56
JC
597# 7 <#> gvsv[*_] s
598# 8 <$> const[IV 42] s
599# 9 <2> add[t2] sK/2
600# goto 6
601# a <1> leavesub[1 ref] K/REFC,1
602EOT_EOT
d1718a7c 603# 1 <;> nextstate(main 511 (eval 26):1) v
cc02ea56
JC
604# 2 <0> pushmark s
605# 3 <$> const(AV ) s
606# 4 <1> rv2av lKPM/1
607# 5 <@> mapstart K
608# 6 <|> mapwhile(other->7)[t4] K
609# 7 <$> gvsv(*_) s
610# 8 <$> const(IV 42) s
611# 9 <2> add[t1] sK/2
612# goto 6
613# a <1> leavesub[1 ref] K/REFC,1
614EONT_EONT
615
616pass("CONSTANTS");
617
498d59dd
SH
618checkOptree ( name => '-e use constant j => qq{junk}; print j',
619 prog => 'use constant j => qq{junk}; print j',
724aa791 620 bcopts => '-exec',
be2b1c74 621 strip_open_hints => 1,
724aa791
JC
622 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
623# 1 <0> enter
be2b1c74 624# 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
724aa791 625# 3 <0> pushmark s
82aeefe1
DM
626# 4 <$> const[PV "junk"] s* < 5.017002
627# 4 <$> const[PV "junk"] s*/FOLD >=5.017002
724aa791
JC
628# 5 <@> print vK
629# 6 <@> leave[1 ref] vKP/REFC
630EOT_EOT
631# 1 <0> enter
be2b1c74 632# 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
724aa791 633# 3 <0> pushmark s
82aeefe1
DM
634# 4 <$> const(PV "junk") s* < 5.017002
635# 4 <$> const(PV "junk") s*/FOLD >=5.017002
724aa791
JC
636# 5 <@> print vK
637# 6 <@> leave[1 ref] vKP/REFC
638EONT_EONT
639
437e3a7d
MH
640pass("rpeep - return \$x at end of sub");
641
642checkOptree ( name => '-exec sub { return 1 }',
643 code => sub { return 1 },
644 bcopts => '-exec',
645 strip_open_hints => 1,
646 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
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
650EOT_EOT
0a60c50b 651# 1 <;> nextstate(main 1 -e:1) v:>,<,%
437e3a7d
MH
652# 2 <$> const(IV 1) s
653# 3 <1> leavesub[1 ref] K/REFC,1
654EONT_EONT
655
4cb2d3f8
MH
656pass("rpeep - if ($a || $b)");
657
658checkOptree ( name => 'if ($a || $b) { } return 1',
659 code => 'if ($a || $b) { } return 1',
660 bcopts => '-exec',
661 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
662# 1 <;> nextstate(main 997 (eval 15):1) v
663# 2 <#> gvsv[*a] s
664# 3 <|> or(other->4) sK/1
665# 4 <#> gvsv[*b] s
666# 5 <|> and(other->6) vK/1
667# 6 <0> stub v
668# 7 <;> nextstate(main 997 (eval 15):1) v
669# 8 <$> const[IV 1] s
670# 9 <1> leavesub[1 ref] K/REFC,1
671EOT_EOT
672# 1 <;> nextstate(main 997 (eval 15):1) v
673# 2 <$> gvsv(*a) s
674# 3 <|> or(other->4) sK/1
675# 4 <$> gvsv(*b) s
676# 5 <|> and(other->6) vK/1
677# 6 <0> stub v
678# 7 <;> nextstate(main 3 (eval 3):1) v
679# 8 <$> const(IV 1) s
680# 9 <1> leavesub[1 ref] K/REFC,1
681EONT_EONT
682
683pass("rpeep - unless ($a && $b)");
684
685checkOptree ( name => 'unless ($a && $b) { } return 1',
686 code => 'unless ($a && $b) { } return 1',
687 bcopts => '-exec',
688 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
689# 1 <;> nextstate(main 997 (eval 15):1) v
690# 2 <#> gvsv[*a] s
691# 3 <|> and(other->4) sK/1
692# 4 <#> gvsv[*b] s
693# 5 <|> or(other->6) vK/1
694# 6 <0> stub v
695# 7 <;> nextstate(main 997 (eval 15):1) v
696# 8 <$> const[IV 1] s
697# 9 <1> leavesub[1 ref] K/REFC,1
698EOT_EOT
699# 1 <;> nextstate(main 997 (eval 15):1) v
700# 2 <$> gvsv(*a) s
701# 3 <|> and(other->4) sK/1
702# 4 <$> gvsv(*b) s
703# 5 <|> or(other->6) vK/1
704# 6 <0> stub v
705# 7 <;> nextstate(main 3 (eval 3):1) v
706# 8 <$> const(IV 1) s
707# 9 <1> leavesub[1 ref] K/REFC,1
708EONT_EONT
709
724aa791
JC
710__END__
711
712#######################################################################
713
714checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
715 code => sub { print (shift) ? "foo" : "bar" },
716 bcopts => '-exec',
717 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
718 insert threaded reference here
719EOT_EOT
720 insert non-threaded reference here
721EONT_EONT
722