6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
10 if (!$Config::Config{useperlio}) {
11 print "1..0 # Skip -- need perlio to walk the optree\n";
14 # require q(test.pl); # now done by OptreeCheck
22 Code test snippets here are adapted from `perldoc -f map`
24 Due to a bleadperl optimization (Dave Mitchell, circa may 04), the
25 (map|grep)(start|while) opcodes have different flags in 5.9, their
26 private flags /1, /2 are gone in blead (for the cases covered)
28 When the optree stuff was integrated into 5.8.6, these tests failed,
29 and were todo'd. Theyre now done, by version-specific tweaking in
30 mkCheckRex(), therefore the skip is removed too.
35 # examples shamelessly snatched from perldoc -f map
41 # chunk: # translates a list of numbers to the corresponding characters.
42 @chars = map(chr, @nums);
46 checkOptree(note => q{},
48 code => q{@chars = map(chr, @nums); },
49 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
50 # 1 <;> nextstate(main 475 (eval 10):1) v
54 # 5 <1> rv2av[t7] lKM/1
56 # 7 <|> mapwhile(other->8)[t8] lK
62 # c <1> rv2av[t2] lKRM*/1
63 # d <2> aassign[t9] KS/COMMON
64 # e <1> leavesub[1 ref] K/REFC,1
66 # 1 <;> nextstate(main 559 (eval 15):1) v
70 # 5 <1> rv2av[t4] lKM/1
72 # 7 <|> mapwhile(other->8)[t5] lK
78 # c <1> rv2av[t1] lKRM*/1
79 # d <2> aassign[t6] KS/COMMON
80 # e <1> leavesub[1 ref] K/REFC,1
86 # chunk: %hash = map { getkey($_) => $_ } @array;
90 checkOptree(note => q{},
92 code => q{%hash = map { getkey($_) => $_ } @array; },
93 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
94 # 1 <;> nextstate(main 476 (eval 10):1) v:{
98 # 5 <1> rv2av[t8] lKM/1
100 # 7 <|> mapwhile(other->8)[t9] lK
102 # 9 <;> nextstate(main 475 (eval 10):1) v:{
106 # d <#> gv[*getkey] s/EARLYCV
107 # e <1> entersub[t5] lKS/TARG,1
114 # k <1> rv2hv[t2] lKRM*/1
115 # l <2> aassign[t10] KS/COMMON
116 # m <1> leavesub[1 ref] K/REFC,1
118 # 1 <;> nextstate(main 560 (eval 15):1) v:{
122 # 5 <1> rv2av[t3] lKM/1
124 # 7 <|> mapwhile(other->8)[t4] lK
126 # 9 <;> nextstate(main 559 (eval 15):1) v:{
130 # d <$> gv(*getkey) s/EARLYCV
131 # e <1> entersub[t2] lKS/TARG,1
138 # k <1> rv2hv[t1] lKRM*/1
139 # l <2> aassign[t5] KS/COMMON
140 # m <1> leavesub[1 ref] K/REFC,1
148 foreach $_ (@array) {
149 $hash{getkey($_)} = $_;
155 checkOptree(note => q{},
157 code => q{{ %hash = (); foreach $_ (@array) { $hash{getkey($_)} = $_; } } },
158 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
159 # 1 <;> nextstate(main 478 (eval 10):1) v:{
160 # 2 <{> enterloop(next->u last->u redo->3)
161 # 3 <;> nextstate(main 475 (eval 10):1) v
165 # 7 <1> rv2hv[t2] lKRM*/1
166 # 8 <2> aassign[t3] vKS
167 # 9 <;> nextstate(main 476 (eval 10):1) v:{
170 # c <1> rv2av[t6] sKRM/1
173 # f <{> enteriter(next->q last->t redo->g) lKS/8
175 # s <|> and(other->g) K/1
176 # g <;> nextstate(main 475 (eval 10):1) v:{
182 # m <#> gv[*getkey] s/EARLYCV
183 # n <1> entersub[t10] sKS/TARG,1
184 # o <2> helem sKRM*/2
185 # p <2> sassign vKS/2
188 # t <2> leaveloop KP/2
189 # u <2> leaveloop K/2
190 # v <1> leavesub[1 ref] K/REFC,1
192 # 1 <;> nextstate(main 562 (eval 15):1) v:{
193 # 2 <{> enterloop(next->u last->u redo->3)
194 # 3 <;> nextstate(main 559 (eval 15):1) v
198 # 7 <1> rv2hv[t1] lKRM*/1
199 # 8 <2> aassign[t2] vKS
200 # 9 <;> nextstate(main 560 (eval 15):1) v:{
203 # c <1> rv2av[t3] sKRM/1
206 # f <{> enteriter(next->q last->t redo->g) lKS/8
208 # s <|> and(other->g) K/1
209 # g <;> nextstate(main 559 (eval 15):1) v:{
215 # m <$> gv(*getkey) s/EARLYCV
216 # n <1> entersub[t4] sKS/TARG,1
217 # o <2> helem sKRM*/2
218 # p <2> sassign vKS/2
221 # t <2> leaveloop KP/2
222 # u <2> leaveloop K/2
223 # v <1> leavesub[1 ref] K/REFC,1
229 # chunk: #%hash = map { "\L$_", 1 } @array; # perl guesses EXPR. wrong
230 %hash = map { +"\L$_", 1 } @array; # perl guesses BLOCK. right
234 checkOptree(note => q{},
236 code => q{%hash = map { +"\L$_", 1 } @array; },
237 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
238 # 1 <;> nextstate(main 476 (eval 10):1) v
242 # 5 <1> rv2av[t7] lKM/1
244 # 7 <|> mapwhile(other->8)[t9] lK
248 # b <@> stringify[t5] sK/1
249 # c <$> const[IV 1] s
255 # g <1> rv2hv[t2] lKRM*/1
256 # h <2> aassign[t10] KS/COMMON
257 # i <1> leavesub[1 ref] K/REFC,1
259 # 1 <;> nextstate(main 560 (eval 15):1) v
263 # 5 <1> rv2av[t4] lKM/1
265 # 7 <|> mapwhile(other->8)[t5] lK
269 # b <@> stringify[t3] sK/1
270 # c <$> const(IV 1) s
276 # g <1> rv2hv[t1] lKRM*/1
277 # h <2> aassign[t6] KS/COMMON
278 # i <1> leavesub[1 ref] K/REFC,1
284 # chunk: %hash = map { ("\L$_", 1) } @array; # this also works
288 checkOptree(note => q{},
290 code => q{%hash = map { ("\L$_", 1) } @array; },
291 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
292 # 1 <;> nextstate(main 476 (eval 10):1) v
296 # 5 <1> rv2av[t7] lKM/1
298 # 7 <|> mapwhile(other->8)[t9] lK
302 # b <@> stringify[t5] sK/1
303 # c <$> const[IV 1] s
309 # g <1> rv2hv[t2] lKRM*/1
310 # h <2> aassign[t10] KS/COMMON
311 # i <1> leavesub[1 ref] K/REFC,1
313 # 1 <;> nextstate(main 560 (eval 15):1) v
317 # 5 <1> rv2av[t4] lKM/1
319 # 7 <|> mapwhile(other->8)[t5] lK
323 # b <@> stringify[t3] sK/1
324 # c <$> const(IV 1) s
330 # g <1> rv2hv[t1] lKRM*/1
331 # h <2> aassign[t6] KS/COMMON
332 # i <1> leavesub[1 ref] K/REFC,1
338 # chunk: %hash = map { lc($_), 1 } @array; # as does this.
342 checkOptree(note => q{},
344 code => q{%hash = map { lc($_), 1 } @array; },
345 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
346 # 1 <;> nextstate(main 476 (eval 10):1) v
350 # 5 <1> rv2av[t6] lKM/1
352 # 7 <|> mapwhile(other->8)[t8] lK
356 # b <$> const[IV 1] s
362 # f <1> rv2hv[t2] lKRM*/1
363 # g <2> aassign[t9] KS/COMMON
364 # h <1> leavesub[1 ref] K/REFC,1
366 # 1 <;> nextstate(main 589 (eval 26):1) v
370 # 5 <1> rv2av[t3] lKM/1
372 # 7 <|> mapwhile(other->8)[t4] lK
376 # b <$> const(IV 1) s
382 # f <1> rv2hv[t1] lKRM*/1
383 # g <2> aassign[t5] KS/COMMON
384 # h <1> leavesub[1 ref] K/REFC,1
390 # chunk: %hash = map +( lc($_), 1 ), @array; # this is EXPR and works!
394 checkOptree(note => q{},
396 code => q{%hash = map +( lc($_), 1 ), @array; },
397 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
398 # 1 <;> nextstate(main 475 (eval 10):1) v
402 # 5 <1> rv2av[t6] lKM/1
404 # 7 <|> mapwhile(other->8)[t7] lK
408 # b <$> const[IV 1] s
413 # f <1> rv2hv[t2] lKRM*/1
414 # g <2> aassign[t8] KS/COMMON
415 # h <1> leavesub[1 ref] K/REFC,1
417 # 1 <;> nextstate(main 593 (eval 28):1) v
421 # 5 <1> rv2av[t3] lKM/1
423 # 7 <|> mapwhile(other->8)[t4] lK
427 # b <$> const(IV 1) s
432 # f <1> rv2hv[t1] lKRM*/1
433 # g <2> aassign[t5] KS/COMMON
434 # h <1> leavesub[1 ref] K/REFC,1
440 # chunk: %hash = map ( lc($_), 1 ), @array; # evaluates to (1, @array)
444 checkOptree(note => q{},
446 code => q{%hash = map ( lc($_), 1 ), @array; },
447 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
448 # 1 <;> nextstate(main 475 (eval 10):1) v
452 # 5 <$> const[IV 1] sM
454 # 7 <|> mapwhile(other->8)[t5] lK
460 # c <1> rv2hv[t2] lKRM*/1
461 # d <2> aassign[t6] KS/COMMON
463 # f <1> rv2av[t8] K/1
465 # h <1> leavesub[1 ref] K/REFC,1
467 # 1 <;> nextstate(main 597 (eval 30):1) v
471 # 5 <$> const(IV 1) sM
473 # 7 <|> mapwhile(other->8)[t3] lK
479 # c <1> rv2hv[t1] lKRM*/1
480 # d <2> aassign[t4] KS/COMMON
482 # f <1> rv2av[t5] K/1
484 # h <1> leavesub[1 ref] K/REFC,1
490 # chunk: @hashes = map +{ lc($_), 1 }, @array # EXPR, so needs , at end
494 checkOptree(note => q{},
496 code => q{@hashes = map +{ lc($_), 1 }, @array },
497 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
498 # 1 <;> nextstate(main 475 (eval 10):1) v
502 # 5 <1> rv2av[t6] lKM/1
504 # 7 <|> mapwhile(other->8)[t7] lK
508 # b <$> const[IV 1] s
509 # c <@> anonhash sK*/1
512 # e <#> gv[*hashes] s
513 # f <1> rv2av[t2] lKRM*/1
514 # g <2> aassign[t8] KS/COMMON
515 # h <1> leavesub[1 ref] K/REFC,1
517 # 1 <;> nextstate(main 601 (eval 32):1) v
521 # 5 <1> rv2av[t3] lKM/1
523 # 7 <|> mapwhile(other->8)[t4] lK
527 # b <$> const(IV 1) s
528 # c <@> anonhash sK*/1
531 # e <$> gv(*hashes) s
532 # f <1> rv2av[t1] lKRM*/1
533 # g <2> aassign[t5] KS/COMMON
534 # h <1> leavesub[1 ref] K/REFC,1