This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Maintainers.pl: Make blead upstream for B::Concise
[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;
3857d07c 17plan tests => 34;
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');
51530e33 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
51530e33 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');
51530e33 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
472# 6 <@> mapstart lK*
473# 7 <|> mapwhile(other->8)[t9] lK
474# 8 <0> enter l
51530e33 475# 9 <;> nextstate(main 500 (eval 22):1) v:%,{
cc02ea56
JC
476# a <0> pushmark s
477# b <0> pushmark s
478# c <#> gvsv[*_] s
479# d <#> gv[*getkey] s/EARLYCV
767eda44 480# e <1> entersub[t5] lKS/TARG
cc02ea56
JC
481# f <#> gvsv[*_] s
482# g <@> list lK
483# h <@> leave lKP
484# goto 7
485# i <0> pushmark s
486# j <#> gv[*h] s
487# k <1> rv2hv[t2] lKRM*/1
488# l <2> aassign[t10] KS/COMMON
489# m <1> leavesub[1 ref] K/REFC,1
490EOT_EOT
51530e33 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
496# 6 <@> mapstart lK*
497# 7 <|> mapwhile(other->8)[t4] lK
498# 8 <0> enter l
51530e33 499# 9 <;> nextstate(main 500 (eval 22):1) v:%,{
cc02ea56
JC
500# a <0> pushmark s
501# b <0> pushmark s
502# c <$> gvsv(*_) s
503# d <$> gv(*getkey) s/EARLYCV
767eda44 504# e <1> entersub[t2] lKS/TARG
cc02ea56
JC
505# f <$> gvsv(*_) s
506# g <@> list lK
507# h <@> leave lKP
508# goto 7
509# i <0> pushmark s
510# j <$> gv(*h) s
511# k <1> rv2hv[t1] lKRM*/1
512# l <2> aassign[t5] KS/COMMON
513# m <1> leavesub[1 ref] K/REFC,1
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');
51530e33 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
524# 5 <1> rv2hv[t2] lKRM*/1
525# 6 <2> aassign[t3] vKS
51530e33 526# 7 <;> nextstate(main 506 (eval 24):1) v:%,{
cc02ea56
JC
527# 8 <0> pushmark sM
528# 9 <#> gv[*a] s
529# a <1> rv2av[t6] sKRM/1
530# b <#> gv[*_] s
531# c <1> rv2gv sKRM/1
0d863452 532# d <{> enteriter(next->o last->r redo->e) lKS/8
cc02ea56
JC
533# p <0> iter s
534# q <|> and(other->e) K/1
51530e33 535# e <;> nextstate(main 505 (eval 24):1) v:%,{
cc02ea56
JC
536# f <#> gvsv[*_] s
537# g <#> gv[*h] s
538# h <1> rv2hv sKR/1
539# i <0> pushmark s
540# j <#> gvsv[*_] s
541# k <#> gv[*getkey] s/EARLYCV
767eda44 542# l <1> entersub[t10] sKS/TARG
cc02ea56
JC
543# m <2> helem sKRM*/2
544# n <2> sassign vKS/2
545# o <0> unstack s
546# goto p
eae48c89 547# r <2> leaveloop KP/2
cc02ea56
JC
548# s <1> leavesub[1 ref] K/REFC,1
549EOT_EOT
51530e33 550# 1 <;> nextstate(main 505 (eval 24):1) v:%
cc02ea56
JC
551# 2 <0> pushmark s
552# 3 <0> pushmark s
553# 4 <$> gv(*h) s
554# 5 <1> rv2hv[t1] lKRM*/1
555# 6 <2> aassign[t2] vKS
51530e33 556# 7 <;> nextstate(main 506 (eval 24):1) v:%,{
cc02ea56
JC
557# 8 <0> pushmark sM
558# 9 <$> gv(*a) s
559# a <1> rv2av[t3] sKRM/1
560# b <$> gv(*_) s
561# c <1> rv2gv sKRM/1
0d863452 562# d <{> enteriter(next->o last->r redo->e) lKS/8
cc02ea56
JC
563# p <0> iter s
564# q <|> and(other->e) K/1
51530e33 565# e <;> nextstate(main 505 (eval 24):1) v:%,{
cc02ea56
JC
566# f <$> gvsv(*_) s
567# g <$> gv(*h) s
568# h <1> rv2hv sKR/1
569# i <0> pushmark s
570# j <$> gvsv(*_) s
571# k <$> gv(*getkey) s/EARLYCV
767eda44 572# l <1> entersub[t4] sKS/TARG
cc02ea56
JC
573# m <2> helem sKRM*/2
574# n <2> sassign vKS/2
575# o <0> unstack s
576# goto p
eae48c89 577# r <2> leaveloop KP/2
cc02ea56
JC
578# s <1> leavesub[1 ref] K/REFC,1
579EONT_EONT
580
581checkOptree ( name => 'map $_+42, 10..20',
582 code => 'map $_+42, 10..20',
583 bcopts => '-exec',
584 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
51530e33 585# 1 <;> nextstate(main 497 (eval 20):1) v:%
cc02ea56
JC
586# 2 <0> pushmark s
587# 3 <$> const[AV ] s
588# 4 <1> rv2av lKPM/1
589# 5 <@> mapstart K
9ad9869c 590# 6 <|> mapwhile(other->7)[t5] K
cc02ea56
JC
591# 7 <#> gvsv[*_] s
592# 8 <$> const[IV 42] s
593# 9 <2> add[t2] sK/2
594# goto 6
595# a <1> leavesub[1 ref] K/REFC,1
596EOT_EOT
51530e33 597# 1 <;> nextstate(main 511 (eval 26):1) v:%
cc02ea56
JC
598# 2 <0> pushmark s
599# 3 <$> const(AV ) s
600# 4 <1> rv2av lKPM/1
601# 5 <@> mapstart K
602# 6 <|> mapwhile(other->7)[t4] K
603# 7 <$> gvsv(*_) s
604# 8 <$> const(IV 42) s
605# 9 <2> add[t1] sK/2
606# goto 6
607# a <1> leavesub[1 ref] K/REFC,1
608EONT_EONT
609
610pass("CONSTANTS");
611
498d59dd
SH
612checkOptree ( name => '-e use constant j => qq{junk}; print j',
613 prog => 'use constant j => qq{junk}; print j',
724aa791 614 bcopts => '-exec',
be2b1c74 615 strip_open_hints => 1,
724aa791
JC
616 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
617# 1 <0> enter
be2b1c74 618# 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
724aa791 619# 3 <0> pushmark s
6b7c6d95 620# 4 <$> const[PV "junk"] s*
724aa791
JC
621# 5 <@> print vK
622# 6 <@> leave[1 ref] vKP/REFC
623EOT_EOT
624# 1 <0> enter
be2b1c74 625# 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
724aa791 626# 3 <0> pushmark s
6b7c6d95 627# 4 <$> const(PV "junk") s*
724aa791
JC
628# 5 <@> print vK
629# 6 <@> leave[1 ref] vKP/REFC
630EONT_EONT
631
632__END__
633
634#######################################################################
635
636checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
637 code => sub { print (shift) ? "foo" : "bar" },
638 bcopts => '-exec',
639 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
640 insert threaded reference here
641EOT_EOT
642 insert non-threaded reference here
643EONT_EONT
644