5 @INC = ('../lib', '../ext/B/t');
7 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
8 print "1..0 # Skip -- Perl configured without B module\n";
12 print "1..0 # Skip -- TODO - provide golden result regexps for 5.8\n";
21 skip "no perlio in this build", 20 unless $Config::Config{useperlio};
23 pass("GENERAL OPTREE EXAMPLES");
25 pass("IF,THEN,ELSE, ?:");
27 checkOptree ( name => '-basic sub {if shift print then,else}',
29 code => sub { if (shift) { print "then" }
32 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
33 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
34 # - <@> lineseq KP ->9
35 # 1 <;> nextstate(main 426 optree.t:16) v ->2
37 # 5 <|> cond_expr(other->6) K/1 ->a
38 # 4 <1> shift sK/1 ->5
39 # 3 <1> rv2av[t2] sKRM/1 ->4
42 # - <0> ex-nextstate v ->6
44 # 6 <0> pushmark s ->7
45 # 7 <$> const[PV "then"] s ->8
48 # b <;> nextstate(main 424 optree.t:17) v ->c
50 # c <0> pushmark s ->d
51 # d <$> const[PV "else"] s ->e
53 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
54 # - <@> lineseq KP ->9
55 # 1 <;> nextstate(main 427 optree_samples.t:18) v ->2
57 # 5 <|> cond_expr(other->6) K/1 ->a
58 # 4 <1> shift sK/1 ->5
59 # 3 <1> rv2av[t1] sKRM/1 ->4
62 # - <0> ex-nextstate v ->6
64 # 6 <0> pushmark s ->7
65 # 7 <$> const(PV "then") s ->8
68 # b <;> nextstate(main 425 optree_samples.t:19) v ->c
70 # c <0> pushmark s ->d
71 # d <$> const(PV "else") s ->e
74 checkOptree ( name => '-basic (see above, with my $a = shift)',
76 code => sub { my $a = shift;
77 if ($a) { print "foo" }
80 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
81 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
82 # - <@> lineseq KP ->d
83 # 1 <;> nextstate(main 431 optree.t:68) v ->2
84 # 6 <2> sassign vKS/2 ->7
85 # 4 <1> shift sK/1 ->5
86 # 3 <1> rv2av[t3] sKRM/1 ->4
88 # 5 <0> padsv[$a:431,435] sRM*/LVINTRO ->6
89 # 7 <;> nextstate(main 435 optree.t:69) v ->8
91 # 9 <|> cond_expr(other->a) K/1 ->e
92 # 8 <0> padsv[$a:431,435] s ->9
94 # - <0> ex-nextstate v ->a
96 # a <0> pushmark s ->b
97 # b <$> const[PV "foo"] s ->c
100 # f <;> nextstate(main 433 optree.t:70) v ->g
102 # g <0> pushmark s ->h
103 # h <$> const[PV "bar"] s ->i
105 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
106 # - <@> lineseq KP ->d
107 # 1 <;> nextstate(main 428 optree_samples.t:48) v ->2
108 # 6 <2> sassign vKS/2 ->7
109 # 4 <1> shift sK/1 ->5
110 # 3 <1> rv2av[t2] sKRM/1 ->4
112 # 5 <0> padsv[$a:428,432] sRM*/LVINTRO ->6
113 # 7 <;> nextstate(main 432 optree_samples.t:49) v ->8
115 # 9 <|> cond_expr(other->a) K/1 ->e
116 # 8 <0> padsv[$a:428,432] s ->9
118 # - <0> ex-nextstate v ->a
120 # a <0> pushmark s ->b
121 # b <$> const(PV "foo") s ->c
124 # f <;> nextstate(main 430 optree_samples.t:50) v ->g
126 # g <0> pushmark s ->h
127 # h <$> const(PV "bar") s ->i
130 checkOptree ( name => '-exec sub {if shift print then,else}',
132 code => sub { if (shift) { print "then" }
133 else { print "else" }
135 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
136 # 1 <;> nextstate(main 426 optree.t:16) v
138 # 3 <1> rv2av[t2] sKRM/1
140 # 5 <|> cond_expr(other->6) K/1
142 # 7 <$> const[PV "then"] s
146 # b <;> nextstate(main 424 optree.t:17) v
148 # d <$> const[PV "else"] s
151 # 9 <1> leavesub[1 ref] K/REFC,1
153 # 1 <;> nextstate(main 436 optree_samples.t:123) v
155 # 3 <1> rv2av[t1] sKRM/1
157 # 5 <|> cond_expr(other->6) K/1
159 # 7 <$> const(PV "then") s
163 # b <;> nextstate(main 434 optree_samples.t:124) v
165 # d <$> const(PV "else") s
168 # 9 <1> leavesub[1 ref] K/REFC,1
171 checkOptree ( name => '-exec (see above, with my $a = shift)',
173 code => sub { my $a = shift;
174 if ($a) { print "foo" }
177 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
178 # 1 <;> nextstate(main 423 optree.t:16) v
180 # 3 <1> rv2av[t3] sKRM/1
182 # 5 <0> padsv[$a:423,427] sRM*/LVINTRO
183 # 6 <2> sassign vKS/2
184 # 7 <;> nextstate(main 427 optree.t:17) v
185 # 8 <0> padsv[$a:423,427] s
186 # 9 <|> cond_expr(other->a) K/1
188 # b <$> const[PV "foo"] s
192 # f <;> nextstate(main 425 optree.t:18) v
194 # h <$> const[PV "bar"] s
197 # d <1> leavesub[1 ref] K/REFC,1
199 # 1 <;> nextstate(main 437 optree_samples.t:112) v
201 # 3 <1> rv2av[t2] sKRM/1
203 # 5 <0> padsv[$a:437,441] sRM*/LVINTRO
204 # 6 <2> sassign vKS/2
205 # 7 <;> nextstate(main 441 optree_samples.t:113) v
206 # 8 <0> padsv[$a:437,441] s
207 # 9 <|> cond_expr(other->a) K/1
209 # b <$> const(PV "foo") s
213 # f <;> nextstate(main 439 optree_samples.t:114) v
215 # h <$> const(PV "bar") s
218 # d <1> leavesub[1 ref] K/REFC,1
221 checkOptree ( name => '-exec sub { print (shift) ? "foo" : "bar" }',
222 code => sub { print (shift) ? "foo" : "bar" },
224 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
225 # 1 <;> nextstate(main 428 optree.t:31) v
228 # 4 <1> rv2av[t2] sKRM/1
231 # 7 <|> cond_expr(other->8) K/1
232 # 8 <$> const[PV "foo"] s
234 # a <$> const[PV "bar"] s
235 # 9 <1> leavesub[1 ref] K/REFC,1
237 # 1 <;> nextstate(main 442 optree_samples.t:144) v
240 # 4 <1> rv2av[t1] sKRM/1
243 # 7 <|> cond_expr(other->8) K/1
244 # 8 <$> const(PV "foo") s
246 # a <$> const(PV "bar") s
247 # 9 <1> leavesub[1 ref] K/REFC,1
252 checkOptree ( name => '-exec sub { foreach (1..10) {print "foo $_"} }',
253 code => sub { foreach (1..10) {print "foo $_"} },
255 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
256 # 1 <;> nextstate(main 443 optree.t:158) v
258 # 3 <$> const[IV 1] s
259 # 4 <$> const[IV 10] s
261 # 6 <{> enteriter(next->d last->g redo->7) lKS
263 # f <|> and(other->7) K/1
264 # 7 <;> nextstate(main 442 optree.t:158) v
266 # 9 <$> const[PV "foo "] s
268 # b <2> concat[t4] sK/2
272 # g <2> leaveloop K/2
273 # h <1> leavesub[1 ref] K/REFC,1
275 # 1 <;> nextstate(main 444 optree_samples.t:182) v
277 # 3 <$> const(IV 1) s
278 # 4 <$> const(IV 10) s
280 # 6 <{> enteriter(next->d last->g redo->7) lKS
282 # f <|> and(other->7) K/1
283 # 7 <;> nextstate(main 443 optree_samples.t:182) v
285 # 9 <$> const(PV "foo ") s
287 # b <2> concat[t3] sK/2
291 # g <2> leaveloop K/2
292 # h <1> leavesub[1 ref] K/REFC,1
295 checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
296 code => sub { print "foo $_" foreach (1..10) },
298 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
299 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
300 # - <@> lineseq KP ->h
301 # 1 <;> nextstate(main 445 optree.t:167) v ->2
302 # 2 <;> nextstate(main 445 optree.t:167) v ->3
303 # g <2> leaveloop K/2 ->h
304 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
305 # - <0> ex-pushmark s ->3
306 # - <1> ex-list lK ->6
307 # 3 <0> pushmark s ->4
308 # 4 <$> const[IV 1] s ->5
309 # 5 <$> const[IV 10] s ->6
312 # f <|> and(other->8) K/1 ->g
314 # - <@> lineseq sK ->-
316 # 8 <0> pushmark s ->9
317 # - <1> ex-stringify sK/1 ->c
318 # - <0> ex-pushmark s ->9
319 # b <2> concat[t2] sK/2 ->c
320 # 9 <$> const[PV "foo "] s ->a
321 # - <1> ex-rv2sv sK/1 ->b
322 # a <#> gvsv[*_] s ->b
323 # d <0> unstack s ->e
325 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
326 # - <@> lineseq KP ->h
327 # 1 <;> nextstate(main 446 optree_samples.t:192) v ->2
328 # 2 <;> nextstate(main 446 optree_samples.t:192) v ->3
329 # g <2> leaveloop K/2 ->h
330 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
331 # - <0> ex-pushmark s ->3
332 # - <1> ex-list lK ->6
333 # 3 <0> pushmark s ->4
334 # 4 <$> const(IV 1) s ->5
335 # 5 <$> const(IV 10) s ->6
338 # f <|> and(other->8) K/1 ->g
340 # - <@> lineseq sK ->-
342 # 8 <0> pushmark s ->9
343 # - <1> ex-stringify sK/1 ->c
344 # - <0> ex-pushmark s ->9
345 # b <2> concat[t1] sK/2 ->c
346 # 9 <$> const(PV "foo ") s ->a
347 # - <1> ex-rv2sv sK/1 ->b
348 # a <$> gvsv(*_) s ->b
349 # d <0> unstack s ->e
352 checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
353 prog => 'foreach (1..10) {print qq{foo $_}}',
355 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
357 # 2 <;> nextstate(main 2 -e:1) v
359 # 4 <$> const[IV 1] s
360 # 5 <$> const[IV 10] s
362 # 7 <{> enteriter(next->e last->h redo->8) lKS
364 # g <|> and(other->8) vK/1
365 # 8 <;> nextstate(main 1 -e:1) v
367 # a <$> const[PV "foo "] s
369 # c <2> concat[t4] sK/2
373 # h <2> leaveloop vK/2
374 # i <@> leave[1 ref] vKP/REFC
377 # 2 <;> nextstate(main 2 -e:1) v
379 # 4 <$> const(IV 1) s
380 # 5 <$> const(IV 10) s
382 # 7 <{> enteriter(next->e last->h redo->8) lKS
384 # g <|> and(other->8) vK/1
385 # 8 <;> nextstate(main 1 -e:1) v
387 # a <$> const(PV "foo ") s
389 # c <2> concat[t3] sK/2
393 # h <2> leaveloop vK/2
394 # i <@> leave[1 ref] vKP/REFC
397 checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
398 code => sub { print "foo $_" foreach (1..10) },
400 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
401 # 1 <;> nextstate(main 445 optree.t:167) v
402 # 2 <;> nextstate(main 445 optree.t:167) v
404 # 4 <$> const[IV 1] s
405 # 5 <$> const[IV 10] s
407 # 7 <{> enteriter(next->d last->g redo->8) lKS
409 # f <|> and(other->8) K/1
411 # 9 <$> const[PV "foo "] s
413 # b <2> concat[t2] sK/2
417 # g <2> leaveloop K/2
418 # h <1> leavesub[1 ref] K/REFC,1
420 # 1 <;> nextstate(main 447 optree_samples.t:252) v
421 # 2 <;> nextstate(main 447 optree_samples.t:252) v
423 # 4 <$> const(IV 1) s
424 # 5 <$> const(IV 10) s
426 # 7 <{> enteriter(next->d last->g redo->8) lKS
428 # f <|> and(other->8) K/1
430 # 9 <$> const(PV "foo ") s
432 # b <2> concat[t1] sK/2
436 # g <2> leaveloop K/2
437 # h <1> leavesub[1 ref] K/REFC,1
440 pass("GREP: SAMPLES FROM PERLDOC -F GREP");
442 checkOptree ( name => '@foo = grep(!/^\#/, @bar)',
443 code => '@foo = grep(!/^\#/, @bar)',
445 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
446 # 1 <;> nextstate(main 496 (eval 20):1) v
450 # 5 <1> rv2av[t4] lKM/1
452 # 7 <|> grepwhile(other->8)[t5] lK
453 # 8 </> match(/"^#"/) s/RTIME
458 # c <1> rv2av[t2] lKRM*/1
459 # d <2> aassign[t6] KS/COMMON
460 # e <1> leavesub[1 ref] K/REFC,1
462 # 1 <;> nextstate(main 496 (eval 20):1) v
466 # 5 <1> rv2av[t2] lKM/1
468 # 7 <|> grepwhile(other->8)[t3] lK
469 # 8 </> match(/"^\\#"/) s/RTIME
474 # c <1> rv2av[t1] lKRM*/1
475 # d <2> aassign[t4] KS/COMMON
476 # e <1> leavesub[1 ref] K/REFC,1
480 pass("MAP: SAMPLES FROM PERLDOC -F MAP");
482 checkOptree ( name => '%h = map { getkey($_) => $_ } @a',
483 code => '%h = map { getkey($_) => $_ } @a',
485 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
486 # 1 <;> nextstate(main 501 (eval 22):1) v
490 # 5 <1> rv2av[t8] lKM/1
492 # 7 <|> mapwhile(other->8)[t9] lK
494 # 9 <;> nextstate(main 500 (eval 22):1) v
498 # d <#> gv[*getkey] s/EARLYCV
499 # e <1> entersub[t5] lKS/TARG,1
506 # k <1> rv2hv[t2] lKRM*/1
507 # l <2> aassign[t10] KS/COMMON
508 # m <1> leavesub[1 ref] K/REFC,1
510 # 1 <;> nextstate(main 501 (eval 22):1) v
514 # 5 <1> rv2av[t3] lKM/1
516 # 7 <|> mapwhile(other->8)[t4] lK
518 # 9 <;> nextstate(main 500 (eval 22):1) v
522 # d <$> gv(*getkey) s/EARLYCV
523 # e <1> entersub[t2] lKS/TARG,1
530 # k <1> rv2hv[t1] lKRM*/1
531 # l <2> aassign[t5] KS/COMMON
532 # m <1> leavesub[1 ref] K/REFC,1
535 checkOptree ( name => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
536 code => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
538 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
539 # 1 <;> nextstate(main 505 (eval 24):1) v
543 # 5 <1> rv2hv[t2] lKRM*/1
544 # 6 <2> aassign[t3] vKS
545 # 7 <;> nextstate(main 506 (eval 24):1) v
548 # a <1> rv2av[t6] sKRM/1
551 # d <{> enteriter(next->o last->r redo->e) lKS
553 # q <|> and(other->e) K/1
554 # e <;> nextstate(main 505 (eval 24):1) v
560 # k <#> gv[*getkey] s/EARLYCV
561 # l <1> entersub[t10] sKS/TARG,1
562 # m <2> helem sKRM*/2
563 # n <2> sassign vKS/2
566 # r <2> leaveloop K/2
567 # s <1> leavesub[1 ref] K/REFC,1
569 # 1 <;> nextstate(main 505 (eval 24):1) v
573 # 5 <1> rv2hv[t1] lKRM*/1
574 # 6 <2> aassign[t2] vKS
575 # 7 <;> nextstate(main 506 (eval 24):1) v
578 # a <1> rv2av[t3] sKRM/1
581 # d <{> enteriter(next->o last->r redo->e) lKS
583 # q <|> and(other->e) K/1
584 # e <;> nextstate(main 505 (eval 24):1) v
590 # k <$> gv(*getkey) s/EARLYCV
591 # l <1> entersub[t4] sKS/TARG,1
592 # m <2> helem sKRM*/2
593 # n <2> sassign vKS/2
596 # r <2> leaveloop K/2
597 # s <1> leavesub[1 ref] K/REFC,1
600 checkOptree ( name => 'map $_+42, 10..20',
601 code => 'map $_+42, 10..20',
603 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
604 # 1 <;> nextstate(main 497 (eval 20):1) v
609 # 6 <|> mapwhile(other->7)[t7] K
611 # 8 <$> const[IV 42] s
614 # a <1> leavesub[1 ref] K/REFC,1
616 # 1 <;> nextstate(main 511 (eval 26):1) v
621 # 6 <|> mapwhile(other->7)[t4] K
623 # 8 <$> const(IV 42) s
626 # a <1> leavesub[1 ref] K/REFC,1
631 checkOptree ( name => '-e use constant j => qq{junk}; print j',
632 prog => 'use constant j => qq{junk}; print j',
634 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
636 # 2 <;> nextstate(main 71 -e:1) v
638 # 4 <$> const[PV "junk"] s
640 # 6 <@> leave[1 ref] vKP/REFC
643 # 2 <;> nextstate(main 71 -e:1) v
645 # 4 <$> const(PV "junk") s
647 # 6 <@> leave[1 ref] vKP/REFC
654 #######################################################################
656 checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
657 code => sub { print (shift) ? "foo" : "bar" },
659 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
660 insert threaded reference here
662 insert non-threaded reference here