5 @INC = ('../lib', '../ext/B/t');
12 pass("GENERAL OPTREE EXAMPLES");
14 pass("IF,THEN,ELSE, ?:");
16 checkOptree ( name => '-basic sub {if shift print then,else}',
18 code => sub { if (shift) { print "then" }
21 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
22 # B::Concise::compile(CODE(0x81a77b4))
23 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
24 # - <@> lineseq KP ->9
25 # 1 <;> nextstate(main 426 optree.t:16) v ->2
27 # 5 <|> cond_expr(other->6) K/1 ->a
28 # 4 <1> shift sK/1 ->5
29 # 3 <1> rv2av[t2] sKRM/1 ->4
32 # - <0> ex-nextstate v ->6
34 # 6 <0> pushmark s ->7
35 # 7 <$> const[PV "then"] s ->8
38 # b <;> nextstate(main 424 optree.t:17) v ->c
40 # c <0> pushmark s ->d
41 # d <$> const[PV "else"] s ->e
43 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
44 # - <@> lineseq KP ->9
45 # 1 <;> nextstate(main 427 optree_samples.t:18) v ->2
47 # 5 <|> cond_expr(other->6) K/1 ->a
48 # 4 <1> shift sK/1 ->5
49 # 3 <1> rv2av[t1] sKRM/1 ->4
52 # - <0> ex-nextstate v ->6
54 # 6 <0> pushmark s ->7
55 # 7 <$> const(PV "then") s ->8
58 # b <;> nextstate(main 425 optree_samples.t:19) v ->c
60 # c <0> pushmark s ->d
61 # d <$> const(PV "else") s ->e
64 checkOptree ( name => '-basic (see above, with my $a = shift)',
66 code => sub { my $a = shift;
67 if ($a) { print "foo" }
70 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
71 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
72 # - <@> lineseq KP ->d
73 # 1 <;> nextstate(main 431 optree.t:68) v ->2
74 # 6 <2> sassign vKS/2 ->7
75 # 4 <1> shift sK/1 ->5
76 # 3 <1> rv2av[t3] sKRM/1 ->4
78 # 5 <0> padsv[$a:431,435] sRM*/LVINTRO ->6
79 # 7 <;> nextstate(main 435 optree.t:69) v ->8
81 # 9 <|> cond_expr(other->a) K/1 ->e
82 # 8 <0> padsv[$a:431,435] s ->9
84 # - <0> ex-nextstate v ->a
86 # a <0> pushmark s ->b
87 # b <$> const[PV "foo"] s ->c
90 # f <;> nextstate(main 433 optree.t:70) v ->g
92 # g <0> pushmark s ->h
93 # h <$> const[PV "bar"] s ->i
95 # 1 <;> nextstate(main 45 optree.t:23) v
96 # 2 <0> padsv[$a:45,46] M/LVINTRO
97 # 3 <1> leavesub[1 ref] K/REFC,1
98 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
99 # - <@> lineseq KP ->d
100 # 1 <;> nextstate(main 428 optree_samples.t:48) v ->2
101 # 6 <2> sassign vKS/2 ->7
102 # 4 <1> shift sK/1 ->5
103 # 3 <1> rv2av[t2] sKRM/1 ->4
105 # 5 <0> padsv[$a:428,432] sRM*/LVINTRO ->6
106 # 7 <;> nextstate(main 432 optree_samples.t:49) v ->8
108 # 9 <|> cond_expr(other->a) K/1 ->e
109 # 8 <0> padsv[$a:428,432] s ->9
111 # - <0> ex-nextstate v ->a
113 # a <0> pushmark s ->b
114 # b <$> const(PV "foo") s ->c
117 # f <;> nextstate(main 430 optree_samples.t:50) v ->g
119 # g <0> pushmark s ->h
120 # h <$> const(PV "bar") s ->i
123 checkOptree ( name => '-exec sub {if shift print then,else}',
125 code => sub { if (shift) { print "then" }
126 else { print "else" }
128 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
129 # B::Concise::compile(CODE(0x81a77b4))
130 # 1 <;> nextstate(main 426 optree.t:16) v
132 # 3 <1> rv2av[t2] sKRM/1
134 # 5 <|> cond_expr(other->6) K/1
136 # 7 <$> const[PV "then"] s
140 # b <;> nextstate(main 424 optree.t:17) v
142 # d <$> const[PV "else"] s
145 # 9 <1> leavesub[1 ref] K/REFC,1
147 # 1 <;> nextstate(main 436 optree_samples.t:123) v
149 # 3 <1> rv2av[t1] sKRM/1
151 # 5 <|> cond_expr(other->6) K/1
153 # 7 <$> const(PV "then") s
157 # b <;> nextstate(main 434 optree_samples.t:124) v
159 # d <$> const(PV "else") s
162 # 9 <1> leavesub[1 ref] K/REFC,1
165 checkOptree ( name => '-exec (see above, with my $a = shift)',
167 code => sub { my $a = shift;
168 if ($a) { print "foo" }
171 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
172 # 1 <;> nextstate(main 423 optree.t:16) v
174 # 3 <1> rv2av[t3] sKRM/1
176 # 5 <0> padsv[$a:423,427] sRM*/LVINTRO
177 # 6 <2> sassign vKS/2
178 # 7 <;> nextstate(main 427 optree.t:17) v
179 # 8 <0> padsv[$a:423,427] s
180 # 9 <|> cond_expr(other->a) K/1
182 # b <$> const[PV "foo"] s
186 # f <;> nextstate(main 425 optree.t:18) v
188 # h <$> const[PV "bar"] s
191 # d <1> leavesub[1 ref] K/REFC,1
193 # 1 <;> nextstate(main 437 optree_samples.t:112) v
195 # 3 <1> rv2av[t2] sKRM/1
197 # 5 <0> padsv[$a:437,441] sRM*/LVINTRO
198 # 6 <2> sassign vKS/2
199 # 7 <;> nextstate(main 441 optree_samples.t:113) v
200 # 8 <0> padsv[$a:437,441] s
201 # 9 <|> cond_expr(other->a) K/1
203 # b <$> const(PV "foo") s
207 # f <;> nextstate(main 439 optree_samples.t:114) v
209 # h <$> const(PV "bar") s
212 # d <1> leavesub[1 ref] K/REFC,1
215 checkOptree ( name => '-exec sub { print (shift) ? "foo" : "bar" }',
216 code => sub { print (shift) ? "foo" : "bar" },
218 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
219 # 1 <;> nextstate(main 428 optree.t:31) v
222 # 4 <1> rv2av[t2] sKRM/1
225 # 7 <|> cond_expr(other->8) K/1
226 # 8 <$> const[PV "foo"] s
228 # a <$> const[PV "bar"] s
229 # 9 <1> leavesub[1 ref] K/REFC,1
231 # 1 <;> nextstate(main 442 optree_samples.t:144) v
234 # 4 <1> rv2av[t1] sKRM/1
237 # 7 <|> cond_expr(other->8) K/1
238 # 8 <$> const(PV "foo") s
240 # a <$> const(PV "bar") s
241 # 9 <1> leavesub[1 ref] K/REFC,1
246 checkOptree ( name => '-exec sub { foreach (1..10) {print "foo $_"} }',
247 code => sub { foreach (1..10) {print "foo $_"} },
249 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
250 # 1 <;> nextstate(main 443 optree.t:158) v
252 # 3 <$> const[IV 1] s
253 # 4 <$> const[IV 10] s
255 # 6 <{> enteriter(next->d last->g redo->7) lKS
257 # f <|> and(other->7) K/1
258 # 7 <;> nextstate(main 442 optree.t:158) v
260 # 9 <$> const[PV "foo "] s
262 # b <2> concat[t4] sK/2
266 # g <2> leaveloop K/2
267 # h <1> leavesub[1 ref] K/REFC,1
270 # 1 <;> nextstate(main 444 optree_samples.t:182) v
272 # 3 <$> const(IV 1) s
273 # 4 <$> const(IV 10) s
275 # 6 <{> enteriter(next->d last->g redo->7) lKS
277 # f <|> and(other->7) K/1
278 # 7 <;> nextstate(main 443 optree_samples.t:182) v
280 # 9 <$> const(PV "foo ") s
282 # b <2> concat[t3] sK/2
286 # g <2> leaveloop K/2
287 # h <1> leavesub[1 ref] K/REFC,1
290 checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
291 code => sub { print "foo $_" foreach (1..10) },
293 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
294 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
295 # - <@> lineseq KP ->h
296 # 1 <;> nextstate(main 445 optree.t:167) v ->2
297 # 2 <;> nextstate(main 445 optree.t:167) v ->3
298 # g <2> leaveloop K/2 ->h
299 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
300 # - <0> ex-pushmark s ->3
301 # - <1> ex-list lK ->6
302 # 3 <0> pushmark s ->4
303 # 4 <$> const[IV 1] s ->5
304 # 5 <$> const[IV 10] s ->6
307 # f <|> and(other->8) K/1 ->g
309 # - <@> lineseq sK ->-
311 # 8 <0> pushmark s ->9
312 # - <1> ex-stringify sK/1 ->c
313 # - <0> ex-pushmark s ->9
314 # b <2> concat[t2] sK/2 ->c
315 # 9 <$> const[PV "foo "] s ->a
316 # - <1> ex-rv2sv sK/1 ->b
317 # a <#> gvsv[*_] s ->b
318 # d <0> unstack s ->e
320 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
321 # - <@> lineseq KP ->h
322 # 1 <;> nextstate(main 446 optree_samples.t:192) v ->2
323 # 2 <;> nextstate(main 446 optree_samples.t:192) v ->3
324 # g <2> leaveloop K/2 ->h
325 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
326 # - <0> ex-pushmark s ->3
327 # - <1> ex-list lK ->6
328 # 3 <0> pushmark s ->4
329 # 4 <$> const(IV 1) s ->5
330 # 5 <$> const(IV 10) s ->6
333 # f <|> and(other->8) K/1 ->g
335 # - <@> lineseq sK ->-
337 # 8 <0> pushmark s ->9
338 # - <1> ex-stringify sK/1 ->c
339 # - <0> ex-pushmark s ->9
340 # b <2> concat[t1] sK/2 ->c
341 # 9 <$> const(PV "foo ") s ->a
342 # - <1> ex-rv2sv sK/1 ->b
343 # a <$> gvsv(*_) s ->b
344 # d <0> unstack s ->e
347 checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
348 prog => 'foreach (1..10) {print qq{foo $_}}',
350 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
352 # 2 <;> nextstate(main 2 -e:1) v
354 # 4 <$> const[IV 1] s
355 # 5 <$> const[IV 10] s
357 # 7 <{> enteriter(next->e last->h redo->8) lKS
359 # g <|> and(other->8) vK/1
360 # 8 <;> nextstate(main 1 -e:1) v
362 # a <$> const[PV "foo "] s
364 # c <2> concat[t4] sK/2
368 # h <2> leaveloop vK/2
369 # i <@> leave[1 ref] vKP/REFC
372 # 2 <;> nextstate(main 2 -e:1) v
374 # 4 <$> const(IV 1) s
375 # 5 <$> const(IV 10) s
377 # 7 <{> enteriter(next->e last->h redo->8) lKS
379 # g <|> and(other->8) vK/1
380 # 8 <;> nextstate(main 1 -e:1) v
382 # a <$> const(PV "foo ") s
384 # c <2> concat[t3] sK/2
388 # h <2> leaveloop vK/2
389 # i <@> leave[1 ref] vKP/REFC
393 checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
394 code => sub { print "foo $_" foreach (1..10) },
396 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
397 # B::Concise::compile(CODE(0x8332b20))
399 # 1 <;> nextstate(main 445 optree.t:167) v
400 # 2 <;> nextstate(main 445 optree.t:167) v
402 # 4 <$> const[IV 1] s
403 # 5 <$> const[IV 10] s
405 # 7 <{> enteriter(next->d last->g redo->8) lKS
407 # f <|> and(other->8) K/1
409 # 9 <$> const[PV "foo "] s
411 # b <2> concat[t2] sK/2
415 # g <2> leaveloop K/2
416 # h <1> leavesub[1 ref] K/REFC,1
418 # 1 <;> nextstate(main 447 optree_samples.t:252) v
419 # 2 <;> nextstate(main 447 optree_samples.t:252) v
421 # 4 <$> const(IV 1) s
422 # 5 <$> const(IV 10) s
424 # 7 <{> enteriter(next->d last->g redo->8) lKS
426 # f <|> and(other->8) K/1
428 # 9 <$> const(PV "foo ") s
430 # b <2> concat[t1] sK/2
434 # g <2> leaveloop K/2
435 # h <1> leavesub[1 ref] K/REFC,1
438 checkOptree ( name => '-e use constant j => qq{junk}; print j',
439 prog => 'use constant j => qq{junk}; print j',
441 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
443 # 2 <;> nextstate(main 71 -e:1) v
445 # 4 <$> const[PV "junk"] s
447 # 6 <@> leave[1 ref] vKP/REFC
450 # 2 <;> nextstate(main 71 -e:1) v
452 # 4 <$> const(PV "junk") s
454 # 6 <@> leave[1 ref] vKP/REFC
459 #######################################################################
461 checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
462 code => sub { print (shift) ? "foo" : "bar" },
464 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
465 insert threaded reference here
467 insert non-threaded reference here