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