5 @INC = ('../lib', '../ext/B/t');
12 skip "no perlio in this build", 13 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 # B::Concise::compile(CODE(0x81a77b4))
25 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
26 # - <@> lineseq KP ->9
27 # 1 <;> nextstate(main 426 optree.t:16) v ->2
29 # 5 <|> cond_expr(other->6) K/1 ->a
30 # 4 <1> shift sK/1 ->5
31 # 3 <1> rv2av[t2] sKRM/1 ->4
34 # - <0> ex-nextstate v ->6
36 # 6 <0> pushmark s ->7
37 # 7 <$> const[PV "then"] s ->8
40 # b <;> nextstate(main 424 optree.t:17) v ->c
42 # c <0> pushmark s ->d
43 # d <$> const[PV "else"] s ->e
45 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
46 # - <@> lineseq KP ->9
47 # 1 <;> nextstate(main 427 optree_samples.t:18) v ->2
49 # 5 <|> cond_expr(other->6) K/1 ->a
50 # 4 <1> shift sK/1 ->5
51 # 3 <1> rv2av[t1] sKRM/1 ->4
54 # - <0> ex-nextstate v ->6
56 # 6 <0> pushmark s ->7
57 # 7 <$> const(PV "then") s ->8
60 # b <;> nextstate(main 425 optree_samples.t:19) v ->c
62 # c <0> pushmark s ->d
63 # d <$> const(PV "else") s ->e
66 checkOptree ( name => '-basic (see above, with my $a = shift)',
68 code => sub { my $a = shift;
69 if ($a) { print "foo" }
72 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
73 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
74 # - <@> lineseq KP ->d
75 # 1 <;> nextstate(main 431 optree.t:68) v ->2
76 # 6 <2> sassign vKS/2 ->7
77 # 4 <1> shift sK/1 ->5
78 # 3 <1> rv2av[t3] sKRM/1 ->4
80 # 5 <0> padsv[$a:431,435] sRM*/LVINTRO ->6
81 # 7 <;> nextstate(main 435 optree.t:69) v ->8
83 # 9 <|> cond_expr(other->a) K/1 ->e
84 # 8 <0> padsv[$a:431,435] s ->9
86 # - <0> ex-nextstate v ->a
88 # a <0> pushmark s ->b
89 # b <$> const[PV "foo"] s ->c
92 # f <;> nextstate(main 433 optree.t:70) v ->g
94 # g <0> pushmark s ->h
95 # h <$> const[PV "bar"] s ->i
97 # 1 <;> nextstate(main 45 optree.t:23) v
98 # 2 <0> padsv[$a:45,46] M/LVINTRO
99 # 3 <1> leavesub[1 ref] K/REFC,1
100 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
101 # - <@> lineseq KP ->d
102 # 1 <;> nextstate(main 428 optree_samples.t:48) v ->2
103 # 6 <2> sassign vKS/2 ->7
104 # 4 <1> shift sK/1 ->5
105 # 3 <1> rv2av[t2] sKRM/1 ->4
107 # 5 <0> padsv[$a:428,432] sRM*/LVINTRO ->6
108 # 7 <;> nextstate(main 432 optree_samples.t:49) v ->8
110 # 9 <|> cond_expr(other->a) K/1 ->e
111 # 8 <0> padsv[$a:428,432] s ->9
113 # - <0> ex-nextstate v ->a
115 # a <0> pushmark s ->b
116 # b <$> const(PV "foo") s ->c
119 # f <;> nextstate(main 430 optree_samples.t:50) v ->g
121 # g <0> pushmark s ->h
122 # h <$> const(PV "bar") s ->i
125 checkOptree ( name => '-exec sub {if shift print then,else}',
127 code => sub { if (shift) { print "then" }
128 else { print "else" }
130 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
131 # B::Concise::compile(CODE(0x81a77b4))
132 # 1 <;> nextstate(main 426 optree.t:16) v
134 # 3 <1> rv2av[t2] sKRM/1
136 # 5 <|> cond_expr(other->6) K/1
138 # 7 <$> const[PV "then"] s
142 # b <;> nextstate(main 424 optree.t:17) v
144 # d <$> const[PV "else"] s
147 # 9 <1> leavesub[1 ref] K/REFC,1
149 # 1 <;> nextstate(main 436 optree_samples.t:123) v
151 # 3 <1> rv2av[t1] sKRM/1
153 # 5 <|> cond_expr(other->6) K/1
155 # 7 <$> const(PV "then") s
159 # b <;> nextstate(main 434 optree_samples.t:124) v
161 # d <$> const(PV "else") s
164 # 9 <1> leavesub[1 ref] K/REFC,1
167 checkOptree ( name => '-exec (see above, with my $a = shift)',
169 code => sub { my $a = shift;
170 if ($a) { print "foo" }
173 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
174 # 1 <;> nextstate(main 423 optree.t:16) v
176 # 3 <1> rv2av[t3] sKRM/1
178 # 5 <0> padsv[$a:423,427] sRM*/LVINTRO
179 # 6 <2> sassign vKS/2
180 # 7 <;> nextstate(main 427 optree.t:17) v
181 # 8 <0> padsv[$a:423,427] s
182 # 9 <|> cond_expr(other->a) K/1
184 # b <$> const[PV "foo"] s
188 # f <;> nextstate(main 425 optree.t:18) v
190 # h <$> const[PV "bar"] s
193 # d <1> leavesub[1 ref] K/REFC,1
195 # 1 <;> nextstate(main 437 optree_samples.t:112) v
197 # 3 <1> rv2av[t2] sKRM/1
199 # 5 <0> padsv[$a:437,441] sRM*/LVINTRO
200 # 6 <2> sassign vKS/2
201 # 7 <;> nextstate(main 441 optree_samples.t:113) v
202 # 8 <0> padsv[$a:437,441] s
203 # 9 <|> cond_expr(other->a) K/1
205 # b <$> const(PV "foo") s
209 # f <;> nextstate(main 439 optree_samples.t:114) v
211 # h <$> const(PV "bar") s
214 # d <1> leavesub[1 ref] K/REFC,1
217 checkOptree ( name => '-exec sub { print (shift) ? "foo" : "bar" }',
218 code => sub { print (shift) ? "foo" : "bar" },
220 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
221 # 1 <;> nextstate(main 428 optree.t:31) v
224 # 4 <1> rv2av[t2] sKRM/1
227 # 7 <|> cond_expr(other->8) K/1
228 # 8 <$> const[PV "foo"] s
230 # a <$> const[PV "bar"] s
231 # 9 <1> leavesub[1 ref] K/REFC,1
233 # 1 <;> nextstate(main 442 optree_samples.t:144) v
236 # 4 <1> rv2av[t1] sKRM/1
239 # 7 <|> cond_expr(other->8) K/1
240 # 8 <$> const(PV "foo") s
242 # a <$> const(PV "bar") s
243 # 9 <1> leavesub[1 ref] K/REFC,1
248 checkOptree ( name => '-exec sub { foreach (1..10) {print "foo $_"} }',
249 code => sub { foreach (1..10) {print "foo $_"} },
251 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
252 # 1 <;> nextstate(main 443 optree.t:158) v
254 # 3 <$> const[IV 1] s
255 # 4 <$> const[IV 10] s
257 # 6 <{> enteriter(next->d last->g redo->7) lKS
259 # f <|> and(other->7) K/1
260 # 7 <;> nextstate(main 442 optree.t:158) v
262 # 9 <$> const[PV "foo "] s
264 # b <2> concat[t4] sK/2
268 # g <2> leaveloop K/2
269 # h <1> leavesub[1 ref] K/REFC,1
272 # 1 <;> nextstate(main 444 optree_samples.t:182) v
274 # 3 <$> const(IV 1) s
275 # 4 <$> const(IV 10) s
277 # 6 <{> enteriter(next->d last->g redo->7) lKS
279 # f <|> and(other->7) K/1
280 # 7 <;> nextstate(main 443 optree_samples.t:182) v
282 # 9 <$> const(PV "foo ") s
284 # b <2> concat[t3] sK/2
288 # g <2> leaveloop K/2
289 # h <1> leavesub[1 ref] K/REFC,1
292 checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
293 code => sub { print "foo $_" foreach (1..10) },
295 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
296 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
297 # - <@> lineseq KP ->h
298 # 1 <;> nextstate(main 445 optree.t:167) v ->2
299 # 2 <;> nextstate(main 445 optree.t:167) v ->3
300 # g <2> leaveloop K/2 ->h
301 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
302 # - <0> ex-pushmark s ->3
303 # - <1> ex-list lK ->6
304 # 3 <0> pushmark s ->4
305 # 4 <$> const[IV 1] s ->5
306 # 5 <$> const[IV 10] s ->6
309 # f <|> and(other->8) K/1 ->g
311 # - <@> lineseq sK ->-
313 # 8 <0> pushmark s ->9
314 # - <1> ex-stringify sK/1 ->c
315 # - <0> ex-pushmark s ->9
316 # b <2> concat[t2] sK/2 ->c
317 # 9 <$> const[PV "foo "] s ->a
318 # - <1> ex-rv2sv sK/1 ->b
319 # a <#> gvsv[*_] s ->b
320 # d <0> unstack s ->e
322 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
323 # - <@> lineseq KP ->h
324 # 1 <;> nextstate(main 446 optree_samples.t:192) v ->2
325 # 2 <;> nextstate(main 446 optree_samples.t:192) v ->3
326 # g <2> leaveloop K/2 ->h
327 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
328 # - <0> ex-pushmark s ->3
329 # - <1> ex-list lK ->6
330 # 3 <0> pushmark s ->4
331 # 4 <$> const(IV 1) s ->5
332 # 5 <$> const(IV 10) s ->6
335 # f <|> and(other->8) K/1 ->g
337 # - <@> lineseq sK ->-
339 # 8 <0> pushmark s ->9
340 # - <1> ex-stringify sK/1 ->c
341 # - <0> ex-pushmark s ->9
342 # b <2> concat[t1] sK/2 ->c
343 # 9 <$> const(PV "foo ") s ->a
344 # - <1> ex-rv2sv sK/1 ->b
345 # a <$> gvsv(*_) s ->b
346 # d <0> unstack s ->e
349 checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
350 prog => 'foreach (1..10) {print qq{foo $_}}',
352 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
354 # 2 <;> nextstate(main 2 -e:1) v
356 # 4 <$> const[IV 1] s
357 # 5 <$> const[IV 10] s
359 # 7 <{> enteriter(next->e last->h redo->8) lKS
361 # g <|> and(other->8) vK/1
362 # 8 <;> nextstate(main 1 -e:1) v
364 # a <$> const[PV "foo "] s
366 # c <2> concat[t4] sK/2
370 # h <2> leaveloop vK/2
371 # i <@> leave[1 ref] vKP/REFC
374 # 2 <;> nextstate(main 2 -e:1) v
376 # 4 <$> const(IV 1) s
377 # 5 <$> const(IV 10) s
379 # 7 <{> enteriter(next->e last->h redo->8) lKS
381 # g <|> and(other->8) vK/1
382 # 8 <;> nextstate(main 1 -e:1) v
384 # a <$> const(PV "foo ") s
386 # c <2> concat[t3] sK/2
390 # h <2> leaveloop vK/2
391 # i <@> leave[1 ref] vKP/REFC
395 checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
396 code => sub { print "foo $_" foreach (1..10) },
398 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
399 # B::Concise::compile(CODE(0x8332b20))
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 checkOptree ( name => '-e use constant j => qq{junk}; print j',
441 prog => 'use constant j => qq{junk}; print j',
443 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
445 # 2 <;> nextstate(main 71 -e:1) v
447 # 4 <$> const[PV "junk"] s
449 # 6 <@> leave[1 ref] vKP/REFC
452 # 2 <;> nextstate(main 71 -e:1) v
454 # 4 <$> const(PV "junk") s
456 # 6 <@> leave[1 ref] vKP/REFC
463 #######################################################################
465 checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
466 code => sub { print (shift) ? "foo" : "bar" },
468 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
469 insert threaded reference here
471 insert non-threaded reference here