6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
10 if (!$Config::Config{useperlio}) {
11 print "1..0 # Skip -- need perlio to walk the optree\n";
19 pass("GENERAL OPTREE EXAMPLES");
21 pass("IF,THEN,ELSE, ?:");
23 checkOptree ( name => '-basic sub {if shift print then,else}',
25 code => sub { if (shift) { print "then" }
28 strip_open_hints => 1,
29 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
30 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
31 # - <@> lineseq KP ->7
32 # 1 <;> nextstate(main 665 optree_samples.t:24) v:>,<,% ->2
34 # 3 <|> cond_expr(other->4) K/1 ->8
37 # - <0> ex-nextstate v ->4
39 # 4 <0> pushmark s ->5
40 # 5 <$> const[PV "then"] s ->6
43 # 9 <;> nextstate(main 663 optree_samples.t:25) v:>,<,% ->a
45 # a <0> pushmark s ->b
46 # b <$> const[PV "else"] s ->c
48 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
49 # - <@> lineseq KP ->7
50 # 1 <;> nextstate(main 665 optree_samples.t:24) v:>,<,% ->2
52 # 3 <|> cond_expr(other->4) K/1 ->8
55 # - <0> ex-nextstate v ->4
57 # 4 <0> pushmark s ->5
58 # 5 <$> const(PV "then") s ->6
61 # 9 <;> nextstate(main 663 optree_samples.t:25) v:>,<,% ->a
63 # a <0> pushmark s ->b
64 # b <$> const(PV "else") s ->c
67 checkOptree ( name => '-basic (see above, with my $a = shift)',
69 code => sub { my $a = shift;
70 if ($a) { print "foo" }
73 strip_open_hints => 1,
74 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
75 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
76 # - <@> lineseq KP ->b
77 # 1 <;> nextstate(main 666 optree_samples.t:70) v:>,<,% ->2
78 # 4 <2> sassign vKS/2 ->5
80 # 3 <0> padsv[$a:666,670] sRM*/LVINTRO ->4
81 # 5 <;> nextstate(main 670 optree_samples.t:71) v:>,<,% ->6
83 # 7 <|> cond_expr(other->8) K/1 ->c
84 # 6 <0> padsv[$a:666,670] s ->7
86 # - <0> ex-nextstate v ->8
88 # 8 <0> pushmark s ->9
89 # 9 <$> const[PV "foo"] s ->a
92 # d <;> nextstate(main 668 optree_samples.t:72) v:>,<,% ->e
94 # e <0> pushmark s ->f
95 # f <$> const[PV "bar"] s ->g
97 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
98 # - <@> lineseq KP ->b
99 # 1 <;> nextstate(main 666 optree_samples.t:72) v:>,<,% ->2
100 # 4 <2> sassign vKS/2 ->5
102 # 3 <0> padsv[$a:666,670] sRM*/LVINTRO ->4
103 # 5 <;> nextstate(main 670 optree_samples.t:73) v:>,<,% ->6
105 # 7 <|> cond_expr(other->8) K/1 ->c
106 # 6 <0> padsv[$a:666,670] s ->7
108 # - <0> ex-nextstate v ->8
110 # 8 <0> pushmark s ->9
111 # 9 <$> const(PV "foo") s ->a
114 # d <;> nextstate(main 668 optree_samples.t:74) v:>,<,% ->e
116 # e <0> pushmark s ->f
117 # f <$> const(PV "bar") s ->g
120 checkOptree ( name => '-exec sub {if shift print then,else}',
122 code => sub { if (shift) { print "then" }
123 else { print "else" }
125 strip_open_hints => 1,
126 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
127 # 1 <;> nextstate(main 674 optree_samples.t:125) v:>,<,%
129 # 3 <|> cond_expr(other->4) K/1
131 # 5 <$> const[PV "then"] s
135 # 9 <;> nextstate(main 672 optree_samples.t:126) v:>,<,%
137 # b <$> const[PV "else"] s
140 # 7 <1> leavesub[1 ref] K/REFC,1
142 # 1 <;> nextstate(main 674 optree_samples.t:129) v:>,<,%
144 # 3 <|> cond_expr(other->4) K/1
146 # 5 <$> const(PV "then") s
150 # 9 <;> nextstate(main 672 optree_samples.t:130) v:>,<,%
152 # b <$> const(PV "else") s
155 # 7 <1> leavesub[1 ref] K/REFC,1
158 checkOptree ( name => '-exec (see above, with my $a = shift)',
160 code => sub { my $a = shift;
161 if ($a) { print "foo" }
164 strip_open_hints => 1,
165 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
166 # 1 <;> nextstate(main 675 optree_samples.t:165) v:>,<,%
168 # 3 <0> padsv[$a:675,679] sRM*/LVINTRO
169 # 4 <2> sassign vKS/2
170 # 5 <;> nextstate(main 679 optree_samples.t:166) v:>,<,%
171 # 6 <0> padsv[$a:675,679] s
172 # 7 <|> cond_expr(other->8) K/1
174 # 9 <$> const[PV "foo"] s
178 # d <;> nextstate(main 677 optree_samples.t:167) v:>,<,%
180 # f <$> const[PV "bar"] s
183 # b <1> leavesub[1 ref] K/REFC,1
185 # 1 <;> nextstate(main 675 optree_samples.t:171) v:>,<,%
187 # 3 <0> padsv[$a:675,679] sRM*/LVINTRO
188 # 4 <2> sassign vKS/2
189 # 5 <;> nextstate(main 679 optree_samples.t:172) v:>,<,%
190 # 6 <0> padsv[$a:675,679] s
191 # 7 <|> cond_expr(other->8) K/1
193 # 9 <$> const(PV "foo") s
197 # d <;> nextstate(main 677 optree_samples.t:173) v:>,<,%
199 # f <$> const(PV "bar") s
202 # b <1> leavesub[1 ref] K/REFC,1
205 checkOptree ( name => '-exec sub { print (shift) ? "foo" : "bar" }',
206 code => sub { print (shift) ? "foo" : "bar" },
208 strip_open_hints => 1,
209 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
210 # 1 <;> nextstate(main 680 optree_samples.t:213) v:>,<,%
214 # 5 <|> cond_expr(other->6) K/1
215 # 6 <$> const[PV "foo"] s
217 # 8 <$> const[PV "bar"] s
218 # 7 <1> leavesub[1 ref] K/REFC,1
220 # 1 <;> nextstate(main 680 optree_samples.t:221) v:>,<,%
224 # 5 <|> cond_expr(other->6) K/1
225 # 6 <$> const(PV "foo") s
227 # 8 <$> const(PV "bar") s
228 # 7 <1> leavesub[1 ref] K/REFC,1
233 checkOptree ( name => '-exec sub { foreach (1..10) {print "foo $_"} }',
234 code => sub { foreach (1..10) {print "foo $_"} },
236 strip_open_hints => 1,
237 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
238 # 1 <;> nextstate(main 443 optree.t:158) v:>,<,%
240 # 3 <$> const[IV 1] s
241 # 4 <$> const[IV 10] s
243 # 6 <{> enteriter(next->d last->g redo->7) lKS/8
245 # f <|> and(other->7) K/1
246 # 7 <;> nextstate(main 442 optree.t:158) v:>,<,%
248 # 9 <$> const[PV "foo "] s
250 # b <2> concat[t4] sK/2
254 # g <2> leaveloop K/2
255 # h <1> leavesub[1 ref] K/REFC,1
257 # 1 <;> nextstate(main 444 optree_samples.t:182) v:>,<,%
259 # 3 <$> const(IV 1) s
260 # 4 <$> const(IV 10) s
262 # 6 <{> enteriter(next->d last->g redo->7) lKS/8
264 # f <|> and(other->7) K/1
265 # 7 <;> nextstate(main 443 optree_samples.t:182) v:>,<,%
267 # 9 <$> const(PV "foo ") s
269 # b <2> concat[t3] sK/2
273 # g <2> leaveloop K/2
274 # h <1> leavesub[1 ref] K/REFC,1
277 checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
278 code => sub { print "foo $_" foreach (1..10) },
280 strip_open_hints => 1,
281 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
282 # g <1> leavesub[1 ref] K/REFC,1 ->(end)
283 # - <@> lineseq KP ->g
284 # 1 <;> nextstate(main 445 optree.t:167) v:>,<,% ->2
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
294 # e <|> and(other->7) K/1 ->f
296 # - <@> lineseq sK ->-
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
307 # g <1> leavesub[1 ref] K/REFC,1 ->(end)
308 # - <@> lineseq KP ->g
309 # 1 <;> nextstate(main 446 optree_samples.t:192) v:>,<,% ->2
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
319 # e <|> and(other->7) K/1 ->f
321 # - <@> lineseq sK ->-
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
333 checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
334 prog => 'foreach (1..10) {print qq{foo $_}}',
336 strip_open_hints => 1,
337 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
339 # 2 <;> nextstate(main 2 -e:1) v:>,<,%,{
341 # 4 <$> const[IV 1] s
342 # 5 <$> const[IV 10] s
344 # 7 <{> enteriter(next->e last->h redo->8) lKS/8
346 # g <|> and(other->8) vK/1
347 # 8 <;> nextstate(main 1 -e:1) v:>,<,%
349 # a <$> const[PV "foo "] s
351 # c <2> concat[t4] sK/2
355 # h <2> leaveloop vK/2
356 # i <@> leave[1 ref] vKP/REFC
359 # 2 <;> nextstate(main 2 -e:1) v:>,<,%,{
361 # 4 <$> const(IV 1) s
362 # 5 <$> const(IV 10) s
364 # 7 <{> enteriter(next->e last->h redo->8) lKS/8
366 # g <|> and(other->8) vK/1
367 # 8 <;> nextstate(main 1 -e:1) v:>,<,%
369 # a <$> const(PV "foo ") s
371 # c <2> concat[t3] sK/2
375 # h <2> leaveloop vK/2
376 # i <@> leave[1 ref] vKP/REFC
379 checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
380 code => sub { print "foo $_" foreach (1..10) },
382 strip_open_hints => 1,
383 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
384 # 1 <;> nextstate(main 445 optree.t:167) v:>,<,%
386 # 3 <$> const[IV 1] s
387 # 4 <$> const[IV 10] s
389 # 6 <{> enteriter(next->c last->f redo->7) lKS/8
391 # e <|> and(other->7) K/1
393 # 8 <$> const[PV "foo "] s
395 # a <2> concat[t2] sK/2
399 # f <2> leaveloop K/2
400 # g <1> leavesub[1 ref] K/REFC,1
402 # 1 <;> nextstate(main 447 optree_samples.t:252) v:>,<,%
404 # 3 <$> const(IV 1) s
405 # 4 <$> const(IV 10) s
407 # 6 <{> enteriter(next->c last->f redo->7) lKS/8
409 # e <|> and(other->7) K/1
411 # 8 <$> const(PV "foo ") s
413 # a <2> concat[t1] sK/2
417 # f <2> leaveloop K/2
418 # g <1> leavesub[1 ref] K/REFC,1
421 pass("GREP: SAMPLES FROM PERLDOC -F GREP");
423 checkOptree ( name => '@foo = grep(!/^\#/, @bar)',
424 code => '@foo = grep(!/^\#/, @bar)',
426 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
427 # 1 <;> nextstate(main 496 (eval 20):1) v:{
431 # 5 <1> rv2av[t4] lKM/1
433 # 7 <|> grepwhile(other->8)[t5] lK
434 # 8 </> match(/"^#"/) s/RTIME
439 # c <1> rv2av[t2] lKRM*/1
440 # d <2> aassign[t6] KS/COMMON
441 # e <1> leavesub[1 ref] K/REFC,1
443 # 1 <;> nextstate(main 496 (eval 20):1) v:{
447 # 5 <1> rv2av[t2] lKM/1
449 # 7 <|> grepwhile(other->8)[t3] lK
450 # 8 </> match(/"^\\#"/) s/RTIME
455 # c <1> rv2av[t1] lKRM*/1
456 # d <2> aassign[t4] KS/COMMON
457 # e <1> leavesub[1 ref] K/REFC,1
461 pass("MAP: SAMPLES FROM PERLDOC -F MAP");
463 checkOptree ( name => '%h = map { getkey($_) => $_ } @a',
464 code => '%h = map { getkey($_) => $_ } @a',
466 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
467 # 1 <;> nextstate(main 501 (eval 22):1) v:{
471 # 5 <1> rv2av[t8] lKM/1
472 # 6 <@> mapstart lK* < 5.017002
473 # 6 <@> mapstart lK >=5.017002
474 # 7 <|> mapwhile(other->8)[t9] lK
476 # 9 <;> nextstate(main 500 (eval 22):1) v:{
479 # c <#> gv[*getkey] s/EARLYCV
480 # d <1> entersub[t5] lKS/TARG
486 # i <1> rv2hv[t2] lKRM*/1 < 5.019006
487 # i <1> rv2hv lKRM*/1 >=5.019006
488 # j <2> aassign[t10] KS/COMMON
489 # k <1> leavesub[1 ref] K/REFC,1
491 # 1 <;> nextstate(main 501 (eval 22):1) v:{
495 # 5 <1> rv2av[t3] lKM/1
496 # 6 <@> mapstart lK* < 5.017002
497 # 6 <@> mapstart lK >=5.017002
498 # 7 <|> mapwhile(other->8)[t4] lK
500 # 9 <;> nextstate(main 500 (eval 22):1) v:{
503 # c <$> gv(*getkey) s/EARLYCV
504 # d <1> entersub[t2] lKS/TARG
510 # i <1> rv2hv[t1] lKRM*/1 < 5.019006
511 # i <1> rv2hv lKRM*/1 >=5.019006
512 # j <2> aassign[t5] KS/COMMON
513 # k <1> leavesub[1 ref] K/REFC,1
516 checkOptree ( name => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
517 code => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
519 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
520 # 1 <;> nextstate(main 505 (eval 24):1) v
524 # 5 <1> rv2hv[t2] lKRM*/1 < 5.019006
525 # 5 <1> rv2hv lKRM*/1 >=5.019006
526 # 6 <2> aassign[t3] vKS
527 # 7 <;> nextstate(main 506 (eval 24):1) v:{
530 # a <1> rv2av[t6] sKRM/1
533 # d <{> enteriter(next->o last->r redo->e) lKS/8
535 # q <|> and(other->e) K/1
536 # e <;> nextstate(main 505 (eval 24):1) v:{
542 # k <#> gv[*getkey] s/EARLYCV
543 # l <1> entersub[t10] sKS/TARG
544 # m <2> helem sKRM*/2
545 # n <2> sassign vKS/2
548 # r <2> leaveloop KP/2
549 # s <1> leavesub[1 ref] K/REFC,1
551 # 1 <;> nextstate(main 505 (eval 24):1) v
555 # 5 <1> rv2hv[t1] lKRM*/1 < 5.019006
556 # 5 <1> rv2hv lKRM*/1 >=5.019006
557 # 6 <2> aassign[t2] vKS
558 # 7 <;> nextstate(main 506 (eval 24):1) v:{
561 # a <1> rv2av[t3] sKRM/1
564 # d <{> enteriter(next->o last->r redo->e) lKS/8
566 # q <|> and(other->e) K/1
567 # e <;> nextstate(main 505 (eval 24):1) v:{
573 # k <$> gv(*getkey) s/EARLYCV
574 # l <1> entersub[t4] sKS/TARG
575 # m <2> helem sKRM*/2
576 # n <2> sassign vKS/2
579 # r <2> leaveloop KP/2
580 # s <1> leavesub[1 ref] K/REFC,1
583 checkOptree ( name => 'map $_+42, 10..20',
584 code => 'map $_+42, 10..20',
586 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
587 # 1 <;> nextstate(main 497 (eval 20):1) v
592 # 6 <|> mapwhile(other->7)[t5] K
594 # 8 <$> const[IV 42] s
597 # a <1> leavesub[1 ref] K/REFC,1
599 # 1 <;> nextstate(main 511 (eval 26):1) v
604 # 6 <|> mapwhile(other->7)[t4] K
606 # 8 <$> const(IV 42) s
609 # a <1> leavesub[1 ref] K/REFC,1
614 checkOptree ( name => '-e use constant j => qq{junk}; print j',
615 prog => 'use constant j => qq{junk}; print j',
617 strip_open_hints => 1,
618 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
620 # 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
622 # 4 <$> const[PV "junk"] s* < 5.017002
623 # 4 <$> const[PV "junk"] s*/FOLD >=5.017002
625 # 6 <@> leave[1 ref] vKP/REFC
628 # 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
630 # 4 <$> const(PV "junk") s* < 5.017002
631 # 4 <$> const(PV "junk") s*/FOLD >=5.017002
633 # 6 <@> leave[1 ref] vKP/REFC
636 pass("rpeep - return \$x at end of sub");
638 checkOptree ( name => '-exec sub { return 1 }',
639 code => sub { return 1 },
641 strip_open_hints => 1,
642 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
643 # 1 <;> nextstate(main 1 -e:1) v:>,<,%
644 # 2 <$> const[IV 1] s
645 # 3 <1> leavesub[1 ref] K/REFC,1
647 # 1 <;> nextstate(main 1 -e:1) v:>,<,%
648 # 2 <$> const(IV 1) s
649 # 3 <1> leavesub[1 ref] K/REFC,1
652 pass("rpeep - if ($a || $b)");
654 checkOptree ( name => 'if ($a || $b) { } return 1',
655 code => 'if ($a || $b) { } return 1',
657 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
658 # 1 <;> nextstate(main 997 (eval 15):1) v
660 # 3 <|> or(other->4) sK/1
662 # 5 <|> and(other->6) vK/1
664 # 7 <;> nextstate(main 997 (eval 15):1) v
665 # 8 <$> const[IV 1] s
666 # 9 <1> leavesub[1 ref] K/REFC,1
668 # 1 <;> nextstate(main 997 (eval 15):1) v
670 # 3 <|> or(other->4) sK/1
672 # 5 <|> and(other->6) vK/1
674 # 7 <;> nextstate(main 3 (eval 3):1) v
675 # 8 <$> const(IV 1) s
676 # 9 <1> leavesub[1 ref] K/REFC,1
679 pass("rpeep - unless ($a && $b)");
681 checkOptree ( name => 'unless ($a && $b) { } return 1',
682 code => 'unless ($a && $b) { } return 1',
684 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
685 # 1 <;> nextstate(main 997 (eval 15):1) v
687 # 3 <|> and(other->4) sK/1
689 # 5 <|> or(other->6) vK/1
691 # 7 <;> nextstate(main 997 (eval 15):1) v
692 # 8 <$> const[IV 1] s
693 # 9 <1> leavesub[1 ref] K/REFC,1
695 # 1 <;> nextstate(main 997 (eval 15):1) v
697 # 3 <|> and(other->4) sK/1
699 # 5 <|> or(other->6) vK/1
701 # 7 <;> nextstate(main 3 (eval 3):1) v
702 # 8 <$> const(IV 1) s
703 # 9 <1> leavesub[1 ref] K/REFC,1
706 pass("rpeep - my $a; my @b; my %c; print 'f'");
708 checkOptree ( name => 'my $a; my @b; my %c; return 1',
709 code => 'my $a; my @b; my %c; return 1',
711 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
712 # 1 <;> nextstate(main 991 (eval 17):1) v
713 # 2 <0> padrange[$a:991,994; @b:992,994; %c:993,994] vM/LVINTRO,3
714 # 3 <;> nextstate(main 994 (eval 17):1) v:{
715 # 4 <$> const[IV 1] s
716 # 5 <1> leavesub[1 ref] K/REFC,1
718 # 1 <;> nextstate(main 991 (eval 17):1) v
719 # 2 <0> padrange[$a:991,994; @b:992,994; %c:993,994] vM/LVINTRO,3
720 # 3 <;> nextstate(main 994 (eval 17):1) v:{
721 # 4 <$> const(IV 1) s
722 # 5 <1> leavesub[1 ref] K/REFC,1
727 #######################################################################
729 checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
730 code => sub { print (shift) ? "foo" : "bar" },
732 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
733 insert threaded reference here
735 insert non-threaded reference here