6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
10 # require 'test.pl'; # now done by OptreeCheck
16 skip "no perlio in this build", 20 unless $Config::Config{useperlio};
18 pass("GENERAL OPTREE EXAMPLES");
20 pass("IF,THEN,ELSE, ?:");
22 checkOptree ( name => '-basic sub {if shift print then,else}',
24 code => sub { if (shift) { print "then" }
27 strip_open_hints => 1,
28 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
29 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
30 # - <@> lineseq KP ->7
31 # 1 <;> nextstate(main 665 optree_samples.t:24) v:>,<,% ->2
33 # 3 <|> cond_expr(other->4) K/1 ->8
36 # - <0> ex-nextstate v ->4
38 # 4 <0> pushmark s ->5
39 # 5 <$> const[PV "then"] s ->6
42 # 9 <;> nextstate(main 663 optree_samples.t:25) v:>,<,% ->a
44 # a <0> pushmark s ->b
45 # b <$> const[PV "else"] s ->c
47 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
48 # - <@> lineseq KP ->7
49 # 1 <;> nextstate(main 665 optree_samples.t:24) v:>,<,% ->2
51 # 3 <|> cond_expr(other->4) K/1 ->8
54 # - <0> ex-nextstate v ->4
56 # 4 <0> pushmark s ->5
57 # 5 <$> const(PV "then") s ->6
60 # 9 <;> nextstate(main 663 optree_samples.t:25) v:>,<,% ->a
62 # a <0> pushmark s ->b
63 # b <$> const(PV "else") s ->c
66 checkOptree ( name => '-basic (see above, with my $a = shift)',
68 code => sub { my $a = shift;
69 if ($a) { print "foo" }
72 strip_open_hints => 1,
73 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
74 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
75 # - <@> lineseq KP ->b
76 # 1 <;> nextstate(main 666 optree_samples.t:70) v:>,<,% ->2
77 # 4 <2> sassign vKS/2 ->5
79 # 3 <0> padsv[$a:666,670] sRM*/LVINTRO ->4
80 # 5 <;> nextstate(main 670 optree_samples.t:71) v:>,<,% ->6
82 # 7 <|> cond_expr(other->8) K/1 ->c
83 # 6 <0> padsv[$a:666,670] s ->7
85 # - <0> ex-nextstate v ->8
87 # 8 <0> pushmark s ->9
88 # 9 <$> const[PV "foo"] s ->a
91 # d <;> nextstate(main 668 optree_samples.t:72) v:>,<,% ->e
93 # e <0> pushmark s ->f
94 # f <$> const[PV "bar"] s ->g
96 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
97 # - <@> lineseq KP ->b
98 # 1 <;> nextstate(main 666 optree_samples.t:72) v:>,<,% ->2
99 # 4 <2> sassign vKS/2 ->5
101 # 3 <0> padsv[$a:666,670] sRM*/LVINTRO ->4
102 # 5 <;> nextstate(main 670 optree_samples.t:73) v:>,<,% ->6
104 # 7 <|> cond_expr(other->8) K/1 ->c
105 # 6 <0> padsv[$a:666,670] s ->7
107 # - <0> ex-nextstate v ->8
109 # 8 <0> pushmark s ->9
110 # 9 <$> const(PV "foo") s ->a
113 # d <;> nextstate(main 668 optree_samples.t:74) v:>,<,% ->e
115 # e <0> pushmark s ->f
116 # f <$> const(PV "bar") s ->g
119 checkOptree ( name => '-exec sub {if shift print then,else}',
121 code => sub { if (shift) { print "then" }
122 else { print "else" }
124 strip_open_hints => 1,
125 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
126 # 1 <;> nextstate(main 674 optree_samples.t:125) v:>,<,%
128 # 3 <|> cond_expr(other->4) K/1
130 # 5 <$> const[PV "then"] s
134 # 9 <;> nextstate(main 672 optree_samples.t:126) v:>,<,%
136 # b <$> const[PV "else"] s
139 # 7 <1> leavesub[1 ref] K/REFC,1
141 # 1 <;> nextstate(main 674 optree_samples.t:129) v:>,<,%
143 # 3 <|> cond_expr(other->4) K/1
145 # 5 <$> const(PV "then") s
149 # 9 <;> nextstate(main 672 optree_samples.t:130) v:>,<,%
151 # b <$> const(PV "else") s
154 # 7 <1> leavesub[1 ref] K/REFC,1
157 checkOptree ( name => '-exec (see above, with my $a = shift)',
159 code => sub { my $a = shift;
160 if ($a) { print "foo" }
163 strip_open_hints => 1,
164 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
165 # 1 <;> nextstate(main 675 optree_samples.t:165) v:>,<,%
167 # 3 <0> padsv[$a:675,679] sRM*/LVINTRO
168 # 4 <2> sassign vKS/2
169 # 5 <;> nextstate(main 679 optree_samples.t:166) v:>,<,%
170 # 6 <0> padsv[$a:675,679] s
171 # 7 <|> cond_expr(other->8) K/1
173 # 9 <$> const[PV "foo"] s
177 # d <;> nextstate(main 677 optree_samples.t:167) v:>,<,%
179 # f <$> const[PV "bar"] s
182 # b <1> leavesub[1 ref] K/REFC,1
184 # 1 <;> nextstate(main 675 optree_samples.t:171) v:>,<,%
186 # 3 <0> padsv[$a:675,679] sRM*/LVINTRO
187 # 4 <2> sassign vKS/2
188 # 5 <;> nextstate(main 679 optree_samples.t:172) v:>,<,%
189 # 6 <0> padsv[$a:675,679] s
190 # 7 <|> cond_expr(other->8) K/1
192 # 9 <$> const(PV "foo") s
196 # d <;> nextstate(main 677 optree_samples.t:173) v:>,<,%
198 # f <$> const(PV "bar") s
201 # b <1> leavesub[1 ref] K/REFC,1
204 checkOptree ( name => '-exec sub { print (shift) ? "foo" : "bar" }',
205 code => sub { print (shift) ? "foo" : "bar" },
207 strip_open_hints => 1,
208 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
209 # 1 <;> nextstate(main 680 optree_samples.t:213) v:>,<,%
213 # 5 <|> cond_expr(other->6) K/1
214 # 6 <$> const[PV "foo"] s
216 # 8 <$> const[PV "bar"] s
217 # 7 <1> leavesub[1 ref] K/REFC,1
219 # 1 <;> nextstate(main 680 optree_samples.t:221) v:>,<,%
223 # 5 <|> cond_expr(other->6) K/1
224 # 6 <$> const(PV "foo") s
226 # 8 <$> const(PV "bar") s
227 # 7 <1> leavesub[1 ref] K/REFC,1
232 checkOptree ( name => '-exec sub { foreach (1..10) {print "foo $_"} }',
233 code => sub { foreach (1..10) {print "foo $_"} },
235 strip_open_hints => 1,
236 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
237 # 1 <;> nextstate(main 443 optree.t:158) v:>,<,%
239 # 3 <$> const[IV 1] s
240 # 4 <$> const[IV 10] s
242 # 6 <{> enteriter(next->d last->g redo->7) lKS/8
244 # f <|> and(other->7) K/1
245 # 7 <;> nextstate(main 442 optree.t:158) v:>,<,%
247 # 9 <$> const[PV "foo "] s
249 # b <2> concat[t4] sK/2
253 # g <2> leaveloop K/2
254 # h <1> leavesub[1 ref] K/REFC,1
256 # 1 <;> nextstate(main 444 optree_samples.t:182) v:>,<,%
258 # 3 <$> const(IV 1) s
259 # 4 <$> const(IV 10) s
261 # 6 <{> enteriter(next->d last->g redo->7) lKS/8
263 # f <|> and(other->7) K/1
264 # 7 <;> nextstate(main 443 optree_samples.t:182) v:>,<,%
266 # 9 <$> const(PV "foo ") s
268 # b <2> concat[t3] sK/2
272 # g <2> leaveloop K/2
273 # h <1> leavesub[1 ref] K/REFC,1
276 checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
277 code => sub { print "foo $_" foreach (1..10) },
279 strip_open_hints => 1,
280 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
281 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
282 # - <@> lineseq KP ->h
283 # 1 <;> nextstate(main 445 optree.t:167) v:>,<,% ->2
284 # 2 <;> nextstate(main 445 optree.t:167) v:>,<,% ->3
285 # g <2> leaveloop K/2 ->h
286 # 7 <{> enteriter(next->d last->g redo->8) lKS/8 ->e
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
294 # f <|> and(other->8) K/1 ->g
296 # - <@> lineseq sK ->-
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
307 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
308 # - <@> lineseq KP ->h
309 # 1 <;> nextstate(main 446 optree_samples.t:192) v:>,<,% ->2
310 # 2 <;> nextstate(main 446 optree_samples.t:192) v:>,<,% ->3
311 # g <2> leaveloop K/2 ->h
312 # 7 <{> enteriter(next->d last->g redo->8) lKS/8 ->e
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
320 # f <|> and(other->8) K/1 ->g
322 # - <@> lineseq sK ->-
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
334 checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
335 prog => 'foreach (1..10) {print qq{foo $_}}',
337 strip_open_hints => 1,
338 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
340 # 2 <;> nextstate(main 2 -e:1) v:>,<,%
342 # 4 <$> const[IV 1] s
343 # 5 <$> const[IV 10] s
345 # 7 <{> enteriter(next->e last->h redo->8) lKS/8
347 # g <|> and(other->8) vK/1
348 # 8 <;> nextstate(main 1 -e:1) v:>,<,%
350 # a <$> const[PV "foo "] s
352 # c <2> concat[t4] sK/2
356 # h <2> leaveloop vK/2
357 # i <@> leave[1 ref] vKP/REFC
360 # 2 <;> nextstate(main 2 -e:1) v:>,<,%
362 # 4 <$> const(IV 1) s
363 # 5 <$> const(IV 10) s
365 # 7 <{> enteriter(next->e last->h redo->8) lKS/8
367 # g <|> and(other->8) vK/1
368 # 8 <;> nextstate(main 1 -e:1) v:>,<,%
370 # a <$> const(PV "foo ") s
372 # c <2> concat[t3] sK/2
376 # h <2> leaveloop vK/2
377 # i <@> leave[1 ref] vKP/REFC
380 checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
381 code => sub { print "foo $_" foreach (1..10) },
383 strip_open_hints => 1,
384 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
385 # 1 <;> nextstate(main 445 optree.t:167) v:>,<,%
386 # 2 <;> nextstate(main 445 optree.t:167) v:>,<,%
388 # 4 <$> const[IV 1] s
389 # 5 <$> const[IV 10] s
391 # 7 <{> enteriter(next->d last->g redo->8) lKS/8
393 # f <|> and(other->8) K/1
395 # 9 <$> const[PV "foo "] s
397 # b <2> concat[t2] sK/2
401 # g <2> leaveloop K/2
402 # h <1> leavesub[1 ref] K/REFC,1
404 # 1 <;> nextstate(main 447 optree_samples.t:252) v:>,<,%
405 # 2 <;> nextstate(main 447 optree_samples.t:252) v:>,<,%
407 # 4 <$> const(IV 1) s
408 # 5 <$> const(IV 10) s
410 # 7 <{> enteriter(next->d last->g redo->8) lKS/8
412 # f <|> and(other->8) K/1
414 # 9 <$> const(PV "foo ") s
416 # b <2> concat[t1] sK/2
420 # g <2> leaveloop K/2
421 # h <1> leavesub[1 ref] K/REFC,1
424 pass("GREP: SAMPLES FROM PERLDOC -F GREP");
426 checkOptree ( name => '@foo = grep(!/^\#/, @bar)',
427 code => '@foo = grep(!/^\#/, @bar)',
429 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
430 # 1 <;> nextstate(main 496 (eval 20):1) v:{
434 # 5 <1> rv2av[t4] lKM/1
436 # 7 <|> grepwhile(other->8)[t5] lK
437 # 8 </> match(/"^#"/) s/RTIME
442 # c <1> rv2av[t2] lKRM*/1
443 # d <2> aassign[t6] KS/COMMON
444 # e <1> leavesub[1 ref] K/REFC,1
446 # 1 <;> nextstate(main 496 (eval 20):1) v:{
450 # 5 <1> rv2av[t2] lKM/1
452 # 7 <|> grepwhile(other->8)[t3] lK
453 # 8 </> match(/"^\\#"/) s/RTIME
458 # c <1> rv2av[t1] lKRM*/1
459 # d <2> aassign[t4] KS/COMMON
460 # e <1> leavesub[1 ref] K/REFC,1
464 pass("MAP: SAMPLES FROM PERLDOC -F MAP");
466 checkOptree ( name => '%h = map { getkey($_) => $_ } @a',
467 code => '%h = map { getkey($_) => $_ } @a',
469 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
470 # 1 <;> nextstate(main 501 (eval 22):1) v:{
474 # 5 <1> rv2av[t8] lKM/1
476 # 7 <|> mapwhile(other->8)[t9] lK
478 # 9 <;> nextstate(main 500 (eval 22):1) v:{
482 # d <#> gv[*getkey] s/EARLYCV
483 # e <1> entersub[t5] lKS/TARG,1
490 # k <1> rv2hv[t2] lKRM*/1
491 # l <2> aassign[t10] KS/COMMON
492 # m <1> leavesub[1 ref] K/REFC,1
494 # 1 <;> nextstate(main 501 (eval 22):1) v:{
498 # 5 <1> rv2av[t3] lKM/1
500 # 7 <|> mapwhile(other->8)[t4] lK
502 # 9 <;> nextstate(main 500 (eval 22):1) v:{
506 # d <$> gv(*getkey) s/EARLYCV
507 # e <1> entersub[t2] lKS/TARG,1
514 # k <1> rv2hv[t1] lKRM*/1
515 # l <2> aassign[t5] KS/COMMON
516 # m <1> leavesub[1 ref] K/REFC,1
519 checkOptree ( name => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
520 code => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
522 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
523 # 1 <;> nextstate(main 505 (eval 24):1) v
527 # 5 <1> rv2hv[t2] lKRM*/1
528 # 6 <2> aassign[t3] vKS
529 # 7 <;> nextstate(main 506 (eval 24):1) v:{
532 # a <1> rv2av[t6] sKRM/1
535 # d <{> enteriter(next->o last->r redo->e) lKS/8
537 # q <|> and(other->e) K/1
538 # e <;> nextstate(main 505 (eval 24):1) v:{
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
550 # r <2> leaveloop K/2
551 # s <1> leavesub[1 ref] K/REFC,1
553 # 1 <;> nextstate(main 505 (eval 24):1) v
557 # 5 <1> rv2hv[t1] lKRM*/1
558 # 6 <2> aassign[t2] vKS
559 # 7 <;> nextstate(main 506 (eval 24):1) v:{
562 # a <1> rv2av[t3] sKRM/1
565 # d <{> enteriter(next->o last->r redo->e) lKS/8
567 # q <|> and(other->e) K/1
568 # e <;> nextstate(main 505 (eval 24):1) v:{
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
580 # r <2> leaveloop K/2
581 # s <1> leavesub[1 ref] K/REFC,1
584 checkOptree ( name => 'map $_+42, 10..20',
585 code => 'map $_+42, 10..20',
587 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
588 # 1 <;> nextstate(main 497 (eval 20):1) v
593 # 6 <|> mapwhile(other->7)[t5] K
595 # 8 <$> const[IV 42] s
598 # a <1> leavesub[1 ref] K/REFC,1
600 # 1 <;> nextstate(main 511 (eval 26):1) v
605 # 6 <|> mapwhile(other->7)[t4] K
607 # 8 <$> const(IV 42) s
610 # a <1> leavesub[1 ref] K/REFC,1
615 checkOptree ( name => '-e use constant j => qq{junk}; print j',
616 prog => 'use constant j => qq{junk}; print j',
618 strip_open_hints => 1,
619 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
621 # 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
623 # 4 <$> const[PV "junk"] s
625 # 6 <@> leave[1 ref] vKP/REFC
628 # 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
630 # 4 <$> const(PV "junk") s
632 # 6 <@> leave[1 ref] vKP/REFC
639 #######################################################################
641 checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
642 code => sub { print (shift) ? "foo" : "bar" },
644 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
645 insert threaded reference here
647 insert non-threaded reference here