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