5 @INC = ('../lib', '../ext/B/t');
12 skip "no perlio in this build", 20 unless $Config::Config{useperlio};
14 pass("GENERAL OPTREE EXAMPLES");
16 pass("IF,THEN,ELSE, ?:");
18 checkOptree ( name => '-basic sub {if shift print then,else}',
20 code => sub { if (shift) { print "then" }
23 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
24 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
25 # - <@> lineseq KP ->9
26 # 1 <;> nextstate(main 426 optree.t:16) v ->2
28 # 5 <|> cond_expr(other->6) K/1 ->a
29 # 4 <1> shift sK/1 ->5
30 # 3 <1> rv2av[t2] sKRM/1 ->4
33 # - <0> ex-nextstate v ->6
35 # 6 <0> pushmark s ->7
36 # 7 <$> const[PV "then"] s ->8
39 # b <;> nextstate(main 424 optree.t:17) v ->c
41 # c <0> pushmark s ->d
42 # d <$> const[PV "else"] s ->e
44 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
45 # - <@> lineseq KP ->9
46 # 1 <;> nextstate(main 427 optree_samples.t:18) v ->2
48 # 5 <|> cond_expr(other->6) K/1 ->a
49 # 4 <1> shift sK/1 ->5
50 # 3 <1> rv2av[t1] sKRM/1 ->4
53 # - <0> ex-nextstate v ->6
55 # 6 <0> pushmark s ->7
56 # 7 <$> const(PV "then") s ->8
59 # b <;> nextstate(main 425 optree_samples.t:19) v ->c
61 # c <0> pushmark s ->d
62 # d <$> const(PV "else") s ->e
65 checkOptree ( name => '-basic (see above, with my $a = shift)',
67 code => sub { my $a = shift;
68 if ($a) { print "foo" }
71 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
72 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
73 # - <@> lineseq KP ->d
74 # 1 <;> nextstate(main 431 optree.t:68) v ->2
75 # 6 <2> sassign vKS/2 ->7
76 # 4 <1> shift sK/1 ->5
77 # 3 <1> rv2av[t3] sKRM/1 ->4
79 # 5 <0> padsv[$a:431,435] sRM*/LVINTRO ->6
80 # 7 <;> nextstate(main 435 optree.t:69) v ->8
82 # 9 <|> cond_expr(other->a) K/1 ->e
83 # 8 <0> padsv[$a:431,435] s ->9
85 # - <0> ex-nextstate v ->a
87 # a <0> pushmark s ->b
88 # b <$> const[PV "foo"] s ->c
91 # f <;> nextstate(main 433 optree.t:70) v ->g
93 # g <0> pushmark s ->h
94 # h <$> const[PV "bar"] s ->i
96 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
97 # - <@> lineseq KP ->d
98 # 1 <;> nextstate(main 428 optree_samples.t:48) v ->2
99 # 6 <2> sassign vKS/2 ->7
100 # 4 <1> shift sK/1 ->5
101 # 3 <1> rv2av[t2] sKRM/1 ->4
103 # 5 <0> padsv[$a:428,432] sRM*/LVINTRO ->6
104 # 7 <;> nextstate(main 432 optree_samples.t:49) v ->8
106 # 9 <|> cond_expr(other->a) K/1 ->e
107 # 8 <0> padsv[$a:428,432] s ->9
109 # - <0> ex-nextstate v ->a
111 # a <0> pushmark s ->b
112 # b <$> const(PV "foo") s ->c
115 # f <;> nextstate(main 430 optree_samples.t:50) v ->g
117 # g <0> pushmark s ->h
118 # h <$> const(PV "bar") s ->i
121 checkOptree ( name => '-exec sub {if shift print then,else}',
123 code => sub { if (shift) { print "then" }
124 else { print "else" }
126 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
127 # 1 <;> nextstate(main 426 optree.t:16) v
129 # 3 <1> rv2av[t2] sKRM/1
131 # 5 <|> cond_expr(other->6) K/1
133 # 7 <$> const[PV "then"] s
137 # b <;> nextstate(main 424 optree.t:17) v
139 # d <$> const[PV "else"] s
142 # 9 <1> leavesub[1 ref] K/REFC,1
144 # 1 <;> nextstate(main 436 optree_samples.t:123) v
146 # 3 <1> rv2av[t1] sKRM/1
148 # 5 <|> cond_expr(other->6) K/1
150 # 7 <$> const(PV "then") s
154 # b <;> nextstate(main 434 optree_samples.t:124) v
156 # d <$> const(PV "else") s
159 # 9 <1> leavesub[1 ref] K/REFC,1
162 checkOptree ( name => '-exec (see above, with my $a = shift)',
164 code => sub { my $a = shift;
165 if ($a) { print "foo" }
168 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
169 # 1 <;> nextstate(main 423 optree.t:16) v
171 # 3 <1> rv2av[t3] sKRM/1
173 # 5 <0> padsv[$a:423,427] sRM*/LVINTRO
174 # 6 <2> sassign vKS/2
175 # 7 <;> nextstate(main 427 optree.t:17) v
176 # 8 <0> padsv[$a:423,427] s
177 # 9 <|> cond_expr(other->a) K/1
179 # b <$> const[PV "foo"] s
183 # f <;> nextstate(main 425 optree.t:18) v
185 # h <$> const[PV "bar"] s
188 # d <1> leavesub[1 ref] K/REFC,1
190 # 1 <;> nextstate(main 437 optree_samples.t:112) v
192 # 3 <1> rv2av[t2] sKRM/1
194 # 5 <0> padsv[$a:437,441] sRM*/LVINTRO
195 # 6 <2> sassign vKS/2
196 # 7 <;> nextstate(main 441 optree_samples.t:113) v
197 # 8 <0> padsv[$a:437,441] s
198 # 9 <|> cond_expr(other->a) K/1
200 # b <$> const(PV "foo") s
204 # f <;> nextstate(main 439 optree_samples.t:114) v
206 # h <$> const(PV "bar") s
209 # d <1> leavesub[1 ref] K/REFC,1
212 checkOptree ( name => '-exec sub { print (shift) ? "foo" : "bar" }',
213 code => sub { print (shift) ? "foo" : "bar" },
215 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
216 # 1 <;> nextstate(main 428 optree.t:31) v
219 # 4 <1> rv2av[t2] sKRM/1
222 # 7 <|> cond_expr(other->8) K/1
223 # 8 <$> const[PV "foo"] s
225 # a <$> const[PV "bar"] s
226 # 9 <1> leavesub[1 ref] K/REFC,1
228 # 1 <;> nextstate(main 442 optree_samples.t:144) v
231 # 4 <1> rv2av[t1] sKRM/1
234 # 7 <|> cond_expr(other->8) K/1
235 # 8 <$> const(PV "foo") s
237 # a <$> const(PV "bar") s
238 # 9 <1> leavesub[1 ref] K/REFC,1
243 checkOptree ( name => '-exec sub { foreach (1..10) {print "foo $_"} }',
244 code => sub { foreach (1..10) {print "foo $_"} },
246 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
247 # 1 <;> nextstate(main 443 optree.t:158) v
249 # 3 <$> const[IV 1] s
250 # 4 <$> const[IV 10] s
252 # 6 <{> enteriter(next->d last->g redo->7) lKS
254 # f <|> and(other->7) K/1
255 # 7 <;> nextstate(main 442 optree.t:158) v
257 # 9 <$> const[PV "foo "] s
259 # b <2> concat[t4] sK/2
263 # g <2> leaveloop K/2
264 # h <1> leavesub[1 ref] K/REFC,1
266 # 1 <;> nextstate(main 444 optree_samples.t:182) v
268 # 3 <$> const(IV 1) s
269 # 4 <$> const(IV 10) s
271 # 6 <{> enteriter(next->d last->g redo->7) lKS
273 # f <|> and(other->7) K/1
274 # 7 <;> nextstate(main 443 optree_samples.t:182) v
276 # 9 <$> const(PV "foo ") s
278 # b <2> concat[t3] sK/2
282 # g <2> leaveloop K/2
283 # h <1> leavesub[1 ref] K/REFC,1
286 checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
287 code => sub { print "foo $_" foreach (1..10) },
289 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
290 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
291 # - <@> lineseq KP ->h
292 # 1 <;> nextstate(main 445 optree.t:167) v ->2
293 # 2 <;> nextstate(main 445 optree.t:167) v ->3
294 # g <2> leaveloop K/2 ->h
295 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
296 # - <0> ex-pushmark s ->3
297 # - <1> ex-list lK ->6
298 # 3 <0> pushmark s ->4
299 # 4 <$> const[IV 1] s ->5
300 # 5 <$> const[IV 10] s ->6
303 # f <|> and(other->8) K/1 ->g
305 # - <@> lineseq sK ->-
307 # 8 <0> pushmark s ->9
308 # - <1> ex-stringify sK/1 ->c
309 # - <0> ex-pushmark s ->9
310 # b <2> concat[t2] sK/2 ->c
311 # 9 <$> const[PV "foo "] s ->a
312 # - <1> ex-rv2sv sK/1 ->b
313 # a <#> gvsv[*_] s ->b
314 # d <0> unstack s ->e
316 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
317 # - <@> lineseq KP ->h
318 # 1 <;> nextstate(main 446 optree_samples.t:192) v ->2
319 # 2 <;> nextstate(main 446 optree_samples.t:192) v ->3
320 # g <2> leaveloop K/2 ->h
321 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
322 # - <0> ex-pushmark s ->3
323 # - <1> ex-list lK ->6
324 # 3 <0> pushmark s ->4
325 # 4 <$> const(IV 1) s ->5
326 # 5 <$> const(IV 10) s ->6
329 # f <|> and(other->8) K/1 ->g
331 # - <@> lineseq sK ->-
333 # 8 <0> pushmark s ->9
334 # - <1> ex-stringify sK/1 ->c
335 # - <0> ex-pushmark s ->9
336 # b <2> concat[t1] sK/2 ->c
337 # 9 <$> const(PV "foo ") s ->a
338 # - <1> ex-rv2sv sK/1 ->b
339 # a <$> gvsv(*_) s ->b
340 # d <0> unstack s ->e
343 checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
344 prog => 'foreach (1..10) {print qq{foo $_}}',
346 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
348 # 2 <;> nextstate(main 2 -e:1) v
350 # 4 <$> const[IV 1] s
351 # 5 <$> const[IV 10] s
353 # 7 <{> enteriter(next->e last->h redo->8) lKS
355 # g <|> and(other->8) vK/1
356 # 8 <;> nextstate(main 1 -e:1) v
358 # a <$> const[PV "foo "] s
360 # c <2> concat[t4] sK/2
364 # h <2> leaveloop vK/2
365 # i <@> leave[1 ref] vKP/REFC
368 # 2 <;> nextstate(main 2 -e:1) v
370 # 4 <$> const(IV 1) s
371 # 5 <$> const(IV 10) s
373 # 7 <{> enteriter(next->e last->h redo->8) lKS
375 # g <|> and(other->8) vK/1
376 # 8 <;> nextstate(main 1 -e:1) v
378 # a <$> const(PV "foo ") s
380 # c <2> concat[t3] sK/2
384 # h <2> leaveloop vK/2
385 # i <@> leave[1 ref] vKP/REFC
388 checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
389 code => sub { print "foo $_" foreach (1..10) },
391 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
392 # 1 <;> nextstate(main 445 optree.t:167) v
393 # 2 <;> nextstate(main 445 optree.t:167) v
395 # 4 <$> const[IV 1] s
396 # 5 <$> const[IV 10] s
398 # 7 <{> enteriter(next->d last->g redo->8) lKS
400 # f <|> and(other->8) K/1
402 # 9 <$> const[PV "foo "] s
404 # b <2> concat[t2] sK/2
408 # g <2> leaveloop K/2
409 # h <1> leavesub[1 ref] K/REFC,1
411 # 1 <;> nextstate(main 447 optree_samples.t:252) v
412 # 2 <;> nextstate(main 447 optree_samples.t:252) v
414 # 4 <$> const(IV 1) s
415 # 5 <$> const(IV 10) s
417 # 7 <{> enteriter(next->d last->g redo->8) lKS
419 # f <|> and(other->8) K/1
421 # 9 <$> const(PV "foo ") s
423 # b <2> concat[t1] sK/2
427 # g <2> leaveloop K/2
428 # h <1> leavesub[1 ref] K/REFC,1
431 pass("GREP: SAMPLES FROM PERLDOC -F GREP");
433 checkOptree ( name => '@foo = grep(!/^\#/, @bar)',
434 code => '@foo = grep(!/^\#/, @bar)',
436 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
437 # 1 <;> nextstate(main 496 (eval 20):1) v
441 # 5 <1> rv2av[t4] lKM/1
443 # 7 <|> grepwhile(other->8)[t5] lK
444 # 8 </> match(/"^#"/) s/RTIME
449 # c <1> rv2av[t2] lKRM*/1
450 # d <2> aassign[t6] KS/COMMON
451 # e <1> leavesub[1 ref] K/REFC,1
453 # 1 <;> nextstate(main 496 (eval 20):1) v
457 # 5 <1> rv2av[t2] lKM/1
459 # 7 <|> grepwhile(other->8)[t3] lK
460 # 8 </> match(/"^\\#"/) s/RTIME
465 # c <1> rv2av[t1] lKRM*/1
466 # d <2> aassign[t4] KS/COMMON
467 # e <1> leavesub[1 ref] K/REFC,1
471 pass("MAP: SAMPLES FROM PERLDOC -F MAP");
473 checkOptree ( name => '%h = map { getkey($_) => $_ } @a',
474 code => '%h = map { getkey($_) => $_ } @a',
476 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
477 # 1 <;> nextstate(main 501 (eval 22):1) v
481 # 5 <1> rv2av[t8] lKM/1
483 # 7 <|> mapwhile(other->8)[t9] lK
485 # 9 <;> nextstate(main 500 (eval 22):1) v
489 # d <#> gv[*getkey] s/EARLYCV
490 # e <1> entersub[t5] lKS/TARG,1
497 # k <1> rv2hv[t2] lKRM*/1
498 # l <2> aassign[t10] KS/COMMON
499 # m <1> leavesub[1 ref] K/REFC,1
501 # 1 <;> nextstate(main 501 (eval 22):1) v
505 # 5 <1> rv2av[t3] lKM/1
507 # 7 <|> mapwhile(other->8)[t4] lK
509 # 9 <;> nextstate(main 500 (eval 22):1) v
513 # d <$> gv(*getkey) s/EARLYCV
514 # e <1> entersub[t2] lKS/TARG,1
521 # k <1> rv2hv[t1] lKRM*/1
522 # l <2> aassign[t5] KS/COMMON
523 # m <1> leavesub[1 ref] K/REFC,1
526 checkOptree ( name => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
527 code => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
529 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
530 # 1 <;> nextstate(main 505 (eval 24):1) v
534 # 5 <1> rv2hv[t2] lKRM*/1
535 # 6 <2> aassign[t3] vKS
536 # 7 <;> nextstate(main 506 (eval 24):1) v
539 # a <1> rv2av[t6] sKRM/1
542 # d <{> enteriter(next->o last->r redo->e) lKS
544 # q <|> and(other->e) K/1
545 # e <;> nextstate(main 505 (eval 24):1) v
551 # k <#> gv[*getkey] s/EARLYCV
552 # l <1> entersub[t10] sKS/TARG,1
553 # m <2> helem sKRM*/2
554 # n <2> sassign vKS/2
557 # r <2> leaveloop K/2
558 # s <1> leavesub[1 ref] K/REFC,1
560 # 1 <;> nextstate(main 505 (eval 24):1) v
564 # 5 <1> rv2hv[t1] lKRM*/1
565 # 6 <2> aassign[t2] vKS
566 # 7 <;> nextstate(main 506 (eval 24):1) v
569 # a <1> rv2av[t3] sKRM/1
572 # d <{> enteriter(next->o last->r redo->e) lKS
574 # q <|> and(other->e) K/1
575 # e <;> nextstate(main 505 (eval 24):1) v
581 # k <$> gv(*getkey) s/EARLYCV
582 # l <1> entersub[t4] sKS/TARG,1
583 # m <2> helem sKRM*/2
584 # n <2> sassign vKS/2
587 # r <2> leaveloop K/2
588 # s <1> leavesub[1 ref] K/REFC,1
591 checkOptree ( name => 'map $_+42, 10..20',
592 code => 'map $_+42, 10..20',
594 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
595 # 1 <;> nextstate(main 497 (eval 20):1) v
600 # 6 <|> mapwhile(other->7)[t7] K
602 # 8 <$> const[IV 42] s
605 # a <1> leavesub[1 ref] K/REFC,1
607 # 1 <;> nextstate(main 511 (eval 26):1) v
612 # 6 <|> mapwhile(other->7)[t4] K
614 # 8 <$> const(IV 42) s
617 # a <1> leavesub[1 ref] K/REFC,1
622 checkOptree ( name => '-e use constant j => qq{junk}; print j',
623 prog => 'use constant j => qq{junk}; print j',
625 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
627 # 2 <;> nextstate(main 71 -e:1) v
629 # 4 <$> const[PV "junk"] s
631 # 6 <@> leave[1 ref] vKP/REFC
634 # 2 <;> nextstate(main 71 -e:1) v
636 # 4 <$> const(PV "junk") s
638 # 6 <@> leave[1 ref] vKP/REFC
645 #######################################################################
647 checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
648 code => sub { print (shift) ? "foo" : "bar" },
650 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
651 insert threaded reference here
653 insert non-threaded reference here