This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix ext/B/t/optree_samples.t
[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 ->-
e3da8f02 37# - <;> ex-nextstate(main 1594 optree_samples.t:25) v:>,<,% ->4
538f5756
RZ
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 ->-
e3da8f02 55# - <;> ex-nextstate(main 1594 optree_samples.t:25) v:>,<,% ->4
538f5756
RZ
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 ->-
e3da8f02 86# - <;> ex-nextstate(main 1603 optree_samples.t:70) v:>,<,% ->8
538f5756
RZ
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 ->-
e3da8f02 108# - <;> ex-nextstate(main 1603 optree_samples.t:70) v:>,<,% ->8
538f5756
RZ
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
e839e6ed
DM
243# 6 <{> enteriter(next->c last->f redo->7) KS/DEF
244# d <0> iter s
245# e <|> and(other->7) K/1
4ea9a11b 246# 7 <;> nextstate(main 1659 optree_samples.t:234) v:>,<,%
724aa791 247# 8 <0> pushmark s
e839e6ed
DM
248# 9 <#> gvsv[*_] s
249# a <+> multiconcat("foo ",4,-1)[t5] sK/STRINGIFY
250# b <@> print vK
251# c <0> unstack s
252# goto d
253# f <2> leaveloop K/2
254# g <1> leavesub[1 ref] K/REFC,1
724aa791 255EOT_EOT
be2b1c74 256# 1 <;> nextstate(main 444 optree_samples.t:182) v:>,<,%
724aa791
JC
257# 2 <0> pushmark s
258# 3 <$> const(IV 1) s
259# 4 <$> const(IV 10) s
260# 5 <$> gv(*_) s
e839e6ed
DM
261# 6 <{> enteriter(next->c last->f redo->7) KS/DEF
262# d <0> iter s
263# e <|> and(other->7) K/1
be2b1c74 264# 7 <;> nextstate(main 443 optree_samples.t:182) v:>,<,%
724aa791 265# 8 <0> pushmark s
e839e6ed
DM
266# 9 <$> gvsv(*_) s
267# a <+> multiconcat("foo ",4,-1)[t4] sK/STRINGIFY
268# b <@> print vK
269# c <0> unstack s
270# goto d
271# f <2> leaveloop K/2
272# g <1> leavesub[1 ref] K/REFC,1
724aa791
JC
273EONT_EONT
274
275checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
276 code => sub { print "foo $_" foreach (1..10) },
277 bcopts => '-basic',
be2b1c74 278 strip_open_hints => 1,
724aa791 279 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
e839e6ed
DM
280# f <1> leavesub[1 ref] K/REFC,1 ->(end)
281# - <@> lineseq KP ->f
be2b1c74 282# 1 <;> nextstate(main 445 optree.t:167) v:>,<,% ->2
e839e6ed
DM
283# e <2> leaveloop K/2 ->f
284# 6 <{> enteriter(next->b last->e redo->7) KS/DEF ->c
ac56e7de
NC
285# - <0> ex-pushmark s ->2
286# - <1> ex-list lK ->5
287# 2 <0> pushmark s ->3
288# 3 <$> const[IV 1] s ->4
289# 4 <$> const[IV 10] s ->5
290# 5 <#> gv[*_] s ->6
e839e6ed
DM
291# - <1> null K/1 ->e
292# d <|> and(other->7) K/1 ->e
293# c <0> iter s ->d
724aa791 294# - <@> lineseq sK ->-
e839e6ed 295# a <@> print vK ->b
ac56e7de 296# 7 <0> pushmark s ->8
e839e6ed
DM
297# 9 <+> multiconcat("foo ",4,-1)[t3] sK/STRINGIFY ->a
298# - <0> ex-pushmark s ->-
299# - <0> ex-const s ->8
300# - <1> ex-rv2sv sK/1 ->9
301# 8 <#> gvsv[*_] s ->9
302# b <0> unstack s ->c
724aa791 303EOT_EOT
e839e6ed
DM
304# f <1> leavesub[1 ref] K/REFC,1 ->(end)
305# - <@> lineseq KP ->f
be2b1c74 306# 1 <;> nextstate(main 446 optree_samples.t:192) v:>,<,% ->2
e839e6ed
DM
307# e <2> leaveloop K/2 ->f
308# 6 <{> enteriter(next->b last->e redo->7) KS/DEF ->c
ac56e7de
NC
309# - <0> ex-pushmark s ->2
310# - <1> ex-list lK ->5
311# 2 <0> pushmark s ->3
312# 3 <$> const(IV 1) s ->4
313# 4 <$> const(IV 10) s ->5
314# 5 <$> gv(*_) s ->6
e839e6ed
DM
315# - <1> null K/1 ->e
316# d <|> and(other->7) K/1 ->e
317# c <0> iter s ->d
724aa791 318# - <@> lineseq sK ->-
e839e6ed 319# a <@> print vK ->b
ac56e7de 320# 7 <0> pushmark s ->8
e839e6ed
DM
321# 9 <+> multiconcat("foo ",4,-1)[t2] sK/STRINGIFY ->a
322# - <0> ex-pushmark s ->-
323# - <0> ex-const s ->8
324# - <1> ex-rv2sv sK/1 ->9
325# 8 <$> gvsv(*_) s ->9
326# b <0> unstack s ->c
724aa791
JC
327EONT_EONT
328
498d59dd
SH
329checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
330 prog => 'foreach (1..10) {print qq{foo $_}}',
724aa791 331 bcopts => '-exec',
be2b1c74 332 strip_open_hints => 1,
724aa791
JC
333 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
334# 1 <0> enter
eae48c89 335# 2 <;> nextstate(main 2 -e:1) v:>,<,%,{
724aa791
JC
336# 3 <0> pushmark s
337# 4 <$> const[IV 1] s
338# 5 <$> const[IV 10] s
339# 6 <#> gv[*_] s
e839e6ed
DM
340# 7 <{> enteriter(next->d last->g redo->8) vKS/DEF
341# e <0> iter s
342# f <|> and(other->8) vK/1
be2b1c74 343# 8 <;> nextstate(main 1 -e:1) v:>,<,%
724aa791 344# 9 <0> pushmark s
e839e6ed
DM
345# a <#> gvsv[*_] s
346# b <+> multiconcat("foo ",4,-1)[t5] sK/STRINGIFY
347# c <@> print vK
348# d <0> unstack v
349# goto e
350# g <2> leaveloop vK/2
351# h <@> leave[1 ref] vKP/REFC
724aa791
JC
352EOT_EOT
353# 1 <0> enter
eae48c89 354# 2 <;> nextstate(main 2 -e:1) v:>,<,%,{
724aa791
JC
355# 3 <0> pushmark s
356# 4 <$> const(IV 1) s
357# 5 <$> const(IV 10) s
358# 6 <$> gv(*_) s
e839e6ed
DM
359# 7 <{> enteriter(next->d last->g redo->8) vKS/DEF
360# e <0> iter s
361# f <|> and(other->8) vK/1
be2b1c74 362# 8 <;> nextstate(main 1 -e:1) v:>,<,%
724aa791 363# 9 <0> pushmark s
e839e6ed
DM
364# a <$> gvsv(*_) s
365# b <+> multiconcat("foo ",4,-1)[t4] sK/STRINGIFY
366# c <@> print vK
367# d <0> unstack v
368# goto e
369# g <2> leaveloop vK/2
370# h <@> leave[1 ref] vKP/REFC
724aa791
JC
371EONT_EONT
372
373checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
374 code => sub { print "foo $_" foreach (1..10) },
375 bcopts => '-exec',
be2b1c74 376 strip_open_hints => 1,
724aa791 377 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
be2b1c74 378# 1 <;> nextstate(main 445 optree.t:167) v:>,<,%
ac56e7de
NC
379# 2 <0> pushmark s
380# 3 <$> const[IV 1] s
381# 4 <$> const[IV 10] s
382# 5 <#> gv[*_] s
e839e6ed
DM
383# 6 <{> enteriter(next->b last->e redo->7) KS/DEF
384# c <0> iter s
385# d <|> and(other->7) K/1
ac56e7de 386# 7 <0> pushmark s
e839e6ed
DM
387# 8 <#> gvsv[*_] s
388# 9 <+> multiconcat("foo ",4,-1)[t3] sK/STRINGIFY
389# a <@> print vK
390# b <0> unstack s
391# goto c
392# e <2> leaveloop K/2
393# f <1> leavesub[1 ref] K/REFC,1
724aa791 394EOT_EOT
be2b1c74 395# 1 <;> nextstate(main 447 optree_samples.t:252) v:>,<,%
ac56e7de
NC
396# 2 <0> pushmark s
397# 3 <$> const(IV 1) s
398# 4 <$> const(IV 10) s
399# 5 <$> gv(*_) s
e839e6ed
DM
400# 6 <{> enteriter(next->b last->e redo->7) KS/DEF
401# c <0> iter s
402# d <|> and(other->7) K/1
ac56e7de 403# 7 <0> pushmark s
e839e6ed
DM
404# 8 <$> gvsv(*_) s
405# 9 <+> multiconcat("foo ",4,-1)[t2] sK/STRINGIFY
406# a <@> print vK
407# b <0> unstack s
408# goto c
409# e <2> leaveloop K/2
410# f <1> leavesub[1 ref] K/REFC,1
724aa791
JC
411EONT_EONT
412
cc02ea56
JC
413pass("GREP: SAMPLES FROM PERLDOC -F GREP");
414
415checkOptree ( name => '@foo = grep(!/^\#/, @bar)',
416 code => '@foo = grep(!/^\#/, @bar)',
417 bcopts => '-exec',
418 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
d1718a7c 419# 1 <;> nextstate(main 496 (eval 20):1) v:{
cc02ea56
JC
420# 2 <0> pushmark s
421# 3 <0> pushmark s
422# 4 <#> gv[*bar] s
423# 5 <1> rv2av[t4] lKM/1
424# 6 <@> grepstart lK
425# 7 <|> grepwhile(other->8)[t5] lK
2e2d70f2 426# 8 </> match(/"^#"/) s
cc02ea56
JC
427# 9 <1> not sK/1
428# goto 7
429# a <0> pushmark s
430# b <#> gv[*foo] s
431# c <1> rv2av[t2] lKRM*/1
a5f48505 432# d <2> aassign[t6] KS/COM_AGG
cc02ea56
JC
433# e <1> leavesub[1 ref] K/REFC,1
434EOT_EOT
d1718a7c 435# 1 <;> nextstate(main 496 (eval 20):1) v:{
cc02ea56
JC
436# 2 <0> pushmark s
437# 3 <0> pushmark s
438# 4 <$> gv(*bar) s
439# 5 <1> rv2av[t2] lKM/1
440# 6 <@> grepstart lK
441# 7 <|> grepwhile(other->8)[t3] lK
2e2d70f2 442# 8 </> match(/"^\\#"/) s
cc02ea56
JC
443# 9 <1> not sK/1
444# goto 7
445# a <0> pushmark s
446# b <$> gv(*foo) s
447# c <1> rv2av[t1] lKRM*/1
a5f48505 448# d <2> aassign[t4] KS/COM_AGG
cc02ea56
JC
449# e <1> leavesub[1 ref] K/REFC,1
450EONT_EONT
451
452
453pass("MAP: SAMPLES FROM PERLDOC -F MAP");
454
455checkOptree ( name => '%h = map { getkey($_) => $_ } @a',
456 code => '%h = map { getkey($_) => $_ } @a',
457 bcopts => '-exec',
458 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
d1718a7c 459# 1 <;> nextstate(main 501 (eval 22):1) v:{
cc02ea56
JC
460# 2 <0> pushmark s
461# 3 <0> pushmark s
462# 4 <#> gv[*a] s
463# 5 <1> rv2av[t8] lKM/1
82aeefe1
DM
464# 6 <@> mapstart lK* < 5.017002
465# 6 <@> mapstart lK >=5.017002
cc02ea56
JC
466# 7 <|> mapwhile(other->8)[t9] lK
467# 8 <0> enter l
d1718a7c 468# 9 <;> nextstate(main 500 (eval 22):1) v:{
cc02ea56 469# a <0> pushmark s
7d3c8a68
SM
470# b <#> gvsv[*_] s
471# c <#> gv[*getkey] s/EARLYCV
472# d <1> entersub[t5] lKS/TARG
473# e <#> gvsv[*_] s
474# f <@> leave lKP
cc02ea56 475# goto 7
7d3c8a68
SM
476# g <0> pushmark s
477# h <#> gv[*h] s
e84e4286 478# i <1> rv2hv[t2] lKRM*
a5f48505 479# j <2> aassign[t10] KS/COM_AGG
7d3c8a68 480# k <1> leavesub[1 ref] K/REFC,1
cc02ea56 481EOT_EOT
d1718a7c 482# 1 <;> nextstate(main 501 (eval 22):1) v:{
cc02ea56
JC
483# 2 <0> pushmark s
484# 3 <0> pushmark s
485# 4 <$> gv(*a) s
486# 5 <1> rv2av[t3] lKM/1
82aeefe1
DM
487# 6 <@> mapstart lK* < 5.017002
488# 6 <@> mapstart lK >=5.017002
cc02ea56
JC
489# 7 <|> mapwhile(other->8)[t4] lK
490# 8 <0> enter l
d1718a7c 491# 9 <;> nextstate(main 500 (eval 22):1) v:{
cc02ea56 492# a <0> pushmark s
7d3c8a68
SM
493# b <$> gvsv(*_) s
494# c <$> gv(*getkey) s/EARLYCV
495# d <1> entersub[t2] lKS/TARG
496# e <$> gvsv(*_) s
497# f <@> leave lKP
cc02ea56 498# goto 7
7d3c8a68
SM
499# g <0> pushmark s
500# h <$> gv(*h) s
e84e4286 501# i <1> rv2hv[t1] lKRM*
a5f48505 502# j <2> aassign[t5] KS/COM_AGG
7d3c8a68 503# k <1> leavesub[1 ref] K/REFC,1
cc02ea56
JC
504EONT_EONT
505
506checkOptree ( name => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
507 code => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
508 bcopts => '-exec',
509 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
d1718a7c 510# 1 <;> nextstate(main 505 (eval 24):1) v
cc02ea56
JC
511# 2 <0> pushmark s
512# 3 <0> pushmark s
513# 4 <#> gv[*h] s
e84e4286 514# 5 <1> rv2hv[t2] lKRM*
cc02ea56 515# 6 <2> aassign[t3] vKS
d1718a7c 516# 7 <;> nextstate(main 506 (eval 24):1) v:{
cc02ea56
JC
517# 8 <0> pushmark sM
518# 9 <#> gv[*a] s
519# a <1> rv2av[t6] sKRM/1
520# b <#> gv[*_] s
521# c <1> rv2gv sKRM/1
c5f78d08 522# d <{> enteriter(next->o last->r redo->e) KS/DEF
cc02ea56
JC
523# p <0> iter s
524# q <|> and(other->e) K/1
d1718a7c 525# e <;> nextstate(main 505 (eval 24):1) v:{
cc02ea56
JC
526# f <#> gvsv[*_] s
527# g <#> gv[*h] s
748f2c65 528# h <1> rv2hv sKR
cc02ea56
JC
529# i <0> pushmark s
530# j <#> gvsv[*_] s
531# k <#> gv[*getkey] s/EARLYCV
767eda44 532# l <1> entersub[t10] sKS/TARG
cc02ea56
JC
533# m <2> helem sKRM*/2
534# n <2> sassign vKS/2
535# o <0> unstack s
536# goto p
eae48c89 537# r <2> leaveloop KP/2
cc02ea56
JC
538# s <1> leavesub[1 ref] K/REFC,1
539EOT_EOT
d1718a7c 540# 1 <;> nextstate(main 505 (eval 24):1) v
cc02ea56
JC
541# 2 <0> pushmark s
542# 3 <0> pushmark s
543# 4 <$> gv(*h) s
e84e4286 544# 5 <1> rv2hv[t1] lKRM*
cc02ea56 545# 6 <2> aassign[t2] vKS
d1718a7c 546# 7 <;> nextstate(main 506 (eval 24):1) v:{
cc02ea56
JC
547# 8 <0> pushmark sM
548# 9 <$> gv(*a) s
549# a <1> rv2av[t3] sKRM/1
550# b <$> gv(*_) s
551# c <1> rv2gv sKRM/1
c5f78d08 552# d <{> enteriter(next->o last->r redo->e) KS/DEF
cc02ea56
JC
553# p <0> iter s
554# q <|> and(other->e) K/1
d1718a7c 555# e <;> nextstate(main 505 (eval 24):1) v:{
cc02ea56
JC
556# f <$> gvsv(*_) s
557# g <$> gv(*h) s
748f2c65 558# h <1> rv2hv sKR
cc02ea56
JC
559# i <0> pushmark s
560# j <$> gvsv(*_) s
561# k <$> gv(*getkey) s/EARLYCV
767eda44 562# l <1> entersub[t4] sKS/TARG
cc02ea56
JC
563# m <2> helem sKRM*/2
564# n <2> sassign vKS/2
565# o <0> unstack s
566# goto p
eae48c89 567# r <2> leaveloop KP/2
cc02ea56
JC
568# s <1> leavesub[1 ref] K/REFC,1
569EONT_EONT
570
571checkOptree ( name => 'map $_+42, 10..20',
572 code => 'map $_+42, 10..20',
573 bcopts => '-exec',
574 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
d1718a7c 575# 1 <;> nextstate(main 497 (eval 20):1) v
cc02ea56
JC
576# 2 <0> pushmark s
577# 3 <$> const[AV ] s
578# 4 <1> rv2av lKPM/1
579# 5 <@> mapstart K
9ad9869c 580# 6 <|> mapwhile(other->7)[t5] K
cc02ea56
JC
581# 7 <#> gvsv[*_] s
582# 8 <$> const[IV 42] s
583# 9 <2> add[t2] sK/2
584# goto 6
585# a <1> leavesub[1 ref] K/REFC,1
586EOT_EOT
d1718a7c 587# 1 <;> nextstate(main 511 (eval 26):1) v
cc02ea56
JC
588# 2 <0> pushmark s
589# 3 <$> const(AV ) s
590# 4 <1> rv2av lKPM/1
591# 5 <@> mapstart K
592# 6 <|> mapwhile(other->7)[t4] K
593# 7 <$> gvsv(*_) s
594# 8 <$> const(IV 42) s
595# 9 <2> add[t1] sK/2
596# goto 6
597# a <1> leavesub[1 ref] K/REFC,1
598EONT_EONT
599
600pass("CONSTANTS");
601
498d59dd
SH
602checkOptree ( name => '-e use constant j => qq{junk}; print j',
603 prog => 'use constant j => qq{junk}; print j',
724aa791 604 bcopts => '-exec',
be2b1c74 605 strip_open_hints => 1,
724aa791
JC
606 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
607# 1 <0> enter
be2b1c74 608# 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
724aa791 609# 3 <0> pushmark s
82aeefe1
DM
610# 4 <$> const[PV "junk"] s* < 5.017002
611# 4 <$> const[PV "junk"] s*/FOLD >=5.017002
724aa791
JC
612# 5 <@> print vK
613# 6 <@> leave[1 ref] vKP/REFC
614EOT_EOT
615# 1 <0> enter
be2b1c74 616# 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
724aa791 617# 3 <0> pushmark s
82aeefe1
DM
618# 4 <$> const(PV "junk") s* < 5.017002
619# 4 <$> const(PV "junk") s*/FOLD >=5.017002
724aa791
JC
620# 5 <@> print vK
621# 6 <@> leave[1 ref] vKP/REFC
622EONT_EONT
623
437e3a7d
MH
624pass("rpeep - return \$x at end of sub");
625
626checkOptree ( name => '-exec sub { return 1 }',
627 code => sub { return 1 },
628 bcopts => '-exec',
629 strip_open_hints => 1,
630 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
0a60c50b 631# 1 <;> nextstate(main 1 -e:1) v:>,<,%
437e3a7d
MH
632# 2 <$> const[IV 1] s
633# 3 <1> leavesub[1 ref] K/REFC,1
634EOT_EOT
0a60c50b 635# 1 <;> nextstate(main 1 -e:1) v:>,<,%
437e3a7d
MH
636# 2 <$> const(IV 1) s
637# 3 <1> leavesub[1 ref] K/REFC,1
638EONT_EONT
639
4cb2d3f8
MH
640pass("rpeep - if ($a || $b)");
641
642checkOptree ( name => 'if ($a || $b) { } return 1',
643 code => 'if ($a || $b) { } return 1',
644 bcopts => '-exec',
645 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
646# 1 <;> nextstate(main 997 (eval 15):1) v
647# 2 <#> gvsv[*a] s
648# 3 <|> or(other->4) sK/1
649# 4 <#> gvsv[*b] s
650# 5 <|> and(other->6) vK/1
651# 6 <0> stub v
652# 7 <;> nextstate(main 997 (eval 15):1) v
653# 8 <$> const[IV 1] s
654# 9 <1> leavesub[1 ref] K/REFC,1
655EOT_EOT
656# 1 <;> nextstate(main 997 (eval 15):1) v
657# 2 <$> gvsv(*a) s
658# 3 <|> or(other->4) sK/1
659# 4 <$> gvsv(*b) s
660# 5 <|> and(other->6) vK/1
661# 6 <0> stub v
662# 7 <;> nextstate(main 3 (eval 3):1) v
663# 8 <$> const(IV 1) s
664# 9 <1> leavesub[1 ref] K/REFC,1
665EONT_EONT
666
667pass("rpeep - unless ($a && $b)");
668
669checkOptree ( name => 'unless ($a && $b) { } return 1',
670 code => 'unless ($a && $b) { } return 1',
671 bcopts => '-exec',
672 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
673# 1 <;> nextstate(main 997 (eval 15):1) v
674# 2 <#> gvsv[*a] s
675# 3 <|> and(other->4) sK/1
676# 4 <#> gvsv[*b] s
677# 5 <|> or(other->6) vK/1
678# 6 <0> stub v
679# 7 <;> nextstate(main 997 (eval 15):1) v
680# 8 <$> const[IV 1] s
681# 9 <1> leavesub[1 ref] K/REFC,1
682EOT_EOT
683# 1 <;> nextstate(main 997 (eval 15):1) v
684# 2 <$> gvsv(*a) s
685# 3 <|> and(other->4) sK/1
686# 4 <$> gvsv(*b) s
687# 5 <|> or(other->6) vK/1
688# 6 <0> stub v
689# 7 <;> nextstate(main 3 (eval 3):1) v
690# 8 <$> const(IV 1) s
691# 9 <1> leavesub[1 ref] K/REFC,1
692EONT_EONT
693
c23547d5
MH
694pass("rpeep - my $a; my @b; my %c; print 'f'");
695
696checkOptree ( name => 'my $a; my @b; my %c; return 1',
697 code => 'my $a; my @b; my %c; return 1',
698 bcopts => '-exec',
699 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
700# 1 <;> nextstate(main 991 (eval 17):1) v
e9fb18e4 701# 2 <0> padrange[$a:991,994; @b:992,994; %c:993,994] vM/LVINTRO,range=3
c23547d5
MH
702# 3 <;> nextstate(main 994 (eval 17):1) v:{
703# 4 <$> const[IV 1] s
704# 5 <1> leavesub[1 ref] K/REFC,1
705EOT_EOT
706# 1 <;> nextstate(main 991 (eval 17):1) v
e9fb18e4 707# 2 <0> padrange[$a:991,994; @b:992,994; %c:993,994] vM/LVINTRO,range=3
c23547d5
MH
708# 3 <;> nextstate(main 994 (eval 17):1) v:{
709# 4 <$> const(IV 1) s
710# 5 <1> leavesub[1 ref] K/REFC,1
711EONT_EONT
712
724aa791
JC
713__END__
714
715#######################################################################
716
717checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
718 code => sub { print (shift) ? "foo" : "bar" },
719 bcopts => '-exec',
720 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
721 insert threaded reference here
722EOT_EOT
723 insert non-threaded reference here
724EONT_EONT
725