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