1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
#!perl
BEGIN {
if ($ENV{PERL_CORE}){
chdir('t') if -d 't';
@INC = ('.', '../lib', '../ext/B/t');
} else {
unshift @INC, 't';
push @INC, "../../t";
}
require Config;
if (($Config::Config{'extensions'} !~ /\bB\b/) ){
print "1..0 # Skip -- Perl configured without B module\n";
exit 0;
}
# require 'test.pl'; # now done by OptreeCheck
}
use OptreeCheck;
use Config;
plan tests => 22;
SKIP: {
skip "no perlio in this build", 22 unless $Config::Config{useperlio};
pass("OPTIMIZER TESTS - VAR INITIALIZATION");
checkOptree ( name => 'sub {my $a}',
bcopts => '-exec',
code => sub {my $a},
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 1 <;> nextstate(main 45 optree.t:23) v
# 2 <0> padsv[$a:45,46] M/LVINTRO
# 3 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 45 optree.t:23) v
# 2 <0> padsv[$a:45,46] M/LVINTRO
# 3 <1> leavesub[1 ref] K/REFC,1
EONT_EONT
checkOptree ( name => '-exec sub {my $a}',
bcopts => '-exec',
code => sub {my $a},
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 1 <;> nextstate(main 49 optree.t:52) v
# 2 <0> padsv[$a:49,50] M/LVINTRO
# 3 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 49 optree.t:45) v
# 2 <0> padsv[$a:49,50] M/LVINTRO
# 3 <1> leavesub[1 ref] K/REFC,1
EONT_EONT
checkOptree ( name => 'sub {our $a}',
bcopts => '-exec',
code => sub {our $a},
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main 21 optree.t:47) v
2 <#> gvsv[*a] s/OURINTR
3 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 51 optree.t:56) v
# 2 <$> gvsv(*a) s/OURINTR
# 3 <1> leavesub[1 ref] K/REFC,1
EONT_EONT
checkOptree ( name => 'sub {local $a}',
bcopts => '-exec',
code => sub {local $a},
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main 23 optree.t:57) v
2 <#> gvsv[*a] s/LVINTRO
3 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 53 optree.t:67) v
# 2 <$> gvsv(*a) s/LVINTRO
# 3 <1> leavesub[1 ref] K/REFC,1
EONT_EONT
checkOptree ( name => 'my $a',
prog => 'my $a',
bcopts => '-basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 4 <@> leave[1 ref] vKP/REFC ->(end)
# 1 <0> enter ->2
# 2 <;> nextstate(main 1 -e:1) v ->3
# 3 <0> padsv[$a:1,2] vM/LVINTRO ->4
EOT_EOT
# 4 <@> leave[1 ref] vKP/REFC ->(end)
# 1 <0> enter ->2
# 2 <;> nextstate(main 1 -e:1) v ->3
# 3 <0> padsv[$a:1,2] vM/LVINTRO ->4
EONT_EONT
checkOptree ( name => 'our $a',
prog => 'our $a',
bcopts => '-basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
4 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
- <1> ex-rv2sv vK/17 ->4
3 <#> gvsv[*a] s/OURINTR ->4
EOT_EOT
# 4 <@> leave[1 ref] vKP/REFC ->(end)
# 1 <0> enter ->2
# 2 <;> nextstate(main 1 -e:1) v ->3
# - <1> ex-rv2sv vK/17 ->4
# 3 <$> gvsv(*a) s/OURINTR ->4
EONT_EONT
checkOptree ( name => 'local $a',
prog => 'local $a',
errs => ['Name "main::a" used only once: possible typo at -e line 1.'],
bcopts => '-basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
4 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
- <1> ex-rv2sv vKM/129 ->4
3 <#> gvsv[*a] s/LVINTRO ->4
EOT_EOT
# 4 <@> leave[1 ref] vKP/REFC ->(end)
# 1 <0> enter ->2
# 2 <;> nextstate(main 1 -e:1) v ->3
# - <1> ex-rv2sv vKM/129 ->4
# 3 <$> gvsv(*a) s/LVINTRO ->4
EONT_EONT
pass("MY, OUR, LOCAL, BOTH SUB AND MAIN, = undef");
checkOptree ( name => 'sub {my $a=undef}',
code => sub {my $a=undef},
bcopts => '-basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
3 <1> leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq KP ->3
1 <;> nextstate(main 24 optree.t:99) v ->2
2 <0> padsv[$a:24,25] sRM*/LVINTRO ->3
EOT_EOT
# 3 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->3
# 1 <;> nextstate(main 54 optree.t:149) v ->2
# 2 <0> padsv[$a:54,55] sRM*/LVINTRO ->3
EONT_EONT
checkOptree ( name => 'sub {our $a=undef}',
code => sub {our $a=undef},
note => 'the global must be reset',
bcopts => '-basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
5 <1> leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq KP ->5
1 <;> nextstate(main 26 optree.t:109) v ->2
4 <2> sassign sKS/2 ->5
2 <0> undef s ->3
- <1> ex-rv2sv sKRM*/17 ->4
3 <#> gvsv[*a] s/OURINTR ->4
EOT_EOT
# 5 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->5
# 1 <;> nextstate(main 446 optree_varinit.t:137) v ->2
# 4 <2> sassign sKS/2 ->5
# 2 <0> undef s ->3
# - <1> ex-rv2sv sKRM*/17 ->4
# 3 <$> gvsv(*a) s/OURINTR ->4
EONT_EONT
checkOptree ( name => 'sub {local $a=undef}',
code => sub {local $a=undef},
note => 'local not used enough to bother',
bcopts => '-basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
5 <1> leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq KP ->5
1 <;> nextstate(main 28 optree.t:122) v ->2
4 <2> sassign sKS/2 ->5
2 <0> undef s ->3
- <1> ex-rv2sv sKRM*/129 ->4
3 <#> gvsv[*a] s/LVINTRO ->4
EOT_EOT
# 5 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->5
# 1 <;> nextstate(main 58 optree.t:141) v ->2
# 4 <2> sassign sKS/2 ->5
# 2 <0> undef s ->3
# - <1> ex-rv2sv sKRM*/129 ->4
# 3 <$> gvsv(*a) s/LVINTRO ->4
EONT_EONT
checkOptree ( name => 'my $a=undef',
prog => 'my $a=undef',
bcopts => '-basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
4 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
3 <0> padsv[$a:1,2] vRM*/LVINTRO ->4
EOT_EOT
# 4 <@> leave[1 ref] vKP/REFC ->(end)
# 1 <0> enter ->2
# 2 <;> nextstate(main 1 -e:1) v ->3
# 3 <0> padsv[$a:1,2] vRM*/LVINTRO ->4
EONT_EONT
checkOptree ( name => 'our $a=undef',
prog => 'our $a=undef',
note => 'global must be reassigned',
bcopts => '-basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
6 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
5 <2> sassign vKS/2 ->6
3 <0> undef s ->4
- <1> ex-rv2sv sKRM*/17 ->5
4 <#> gvsv[*a] s/OURINTR ->5
EOT_EOT
# 6 <@> leave[1 ref] vKP/REFC ->(end)
# 1 <0> enter ->2
# 2 <;> nextstate(main 1 -e:1) v ->3
# 5 <2> sassign vKS/2 ->6
# 3 <0> undef s ->4
# - <1> ex-rv2sv sKRM*/17 ->5
# 4 <$> gvsv(*a) s/OURINTR ->5
EONT_EONT
checkOptree ( name => 'local $a=undef',
prog => 'local $a=undef',
errs => ['Name "main::a" used only once: possible typo at -e line 1.'],
note => 'locals are rare, probly not worth doing',
bcopts => '-basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
6 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
5 <2> sassign vKS/2 ->6
3 <0> undef s ->4
- <1> ex-rv2sv sKRM*/129 ->5
4 <#> gvsv[*a] s/LVINTRO ->5
EOT_EOT
# 6 <@> leave[1 ref] vKP/REFC ->(end)
# 1 <0> enter ->2
# 2 <;> nextstate(main 1 -e:1) v ->3
# 5 <2> sassign vKS/2 ->6
# 3 <0> undef s ->4
# - <1> ex-rv2sv sKRM*/129 ->5
# 4 <$> gvsv(*a) s/LVINTRO ->5
EONT_EONT
checkOptree ( name => 'sub {my $a=()}',
code => sub {my $a=()},
bcopts => '-exec',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main -439 optree.t:105) v
2 <0> stub sP
3 <0> padsv[$a:-439,-438] sRM*/LVINTRO
4 <2> sassign sKS/2
5 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 438 optree_varinit.t:247) v
# 2 <0> stub sP
# 3 <0> padsv[$a:438,439] sRM*/LVINTRO
# 4 <2> sassign sKS/2
# 5 <1> leavesub[1 ref] K/REFC,1
EONT_EONT
checkOptree ( name => 'sub {our $a=()}',
code => sub {our $a=()},
#todo => 'probly not worth doing',
bcopts => '-exec',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main 31 optree.t:177) v
2 <0> stub sP
3 <#> gvsv[*a] s/OURINTR
4 <2> sassign sKS/2
5 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 440 optree_varinit.t:262) v
# 2 <0> stub sP
# 3 <$> gvsv(*a) s/OURINTR
# 4 <2> sassign sKS/2
# 5 <1> leavesub[1 ref] K/REFC,1
EONT_EONT
checkOptree ( name => 'sub {local $a=()}',
code => sub {local $a=()},
#todo => 'probly not worth doing',
bcopts => '-exec',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main 33 optree.t:190) v
2 <0> stub sP
3 <#> gvsv[*a] s/LVINTRO
4 <2> sassign sKS/2
5 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 63 optree.t:225) v
# 2 <0> stub sP
# 3 <$> gvsv(*a) s/LVINTRO
# 4 <2> sassign sKS/2
# 5 <1> leavesub[1 ref] K/REFC,1
EONT_EONT
checkOptree ( name => 'my $a=()',
prog => 'my $a=()',
bcopts => '-exec',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <0> enter
2 <;> nextstate(main 1 -e:1) v
3 <0> stub sP
4 <0> padsv[$a:1,2] sRM*/LVINTRO
5 <2> sassign vKS/2
6 <@> leave[1 ref] vKP/REFC
EOT_EOT
# 1 <0> enter
# 2 <;> nextstate(main 1 -e:1) v
# 3 <0> stub sP
# 4 <0> padsv[$a:1,2] sRM*/LVINTRO
# 5 <2> sassign vKS/2
# 6 <@> leave[1 ref] vKP/REFC
EONT_EONT
checkOptree ( name => 'our $a=()',
prog => 'our $a=()',
#todo => 'probly not worth doing',
bcopts => '-exec',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <0> enter
2 <;> nextstate(main 1 -e:1) v
3 <0> stub sP
4 <#> gvsv[*a] s/OURINTR
5 <2> sassign vKS/2
6 <@> leave[1 ref] vKP/REFC
EOT_EOT
# 1 <0> enter
# 2 <;> nextstate(main 1 -e:1) v
# 3 <0> stub sP
# 4 <$> gvsv(*a) s/OURINTR
# 5 <2> sassign vKS/2
# 6 <@> leave[1 ref] vKP/REFC
EONT_EONT
checkOptree ( name => 'local $a=()',
prog => 'local $a=()',
errs => ['Name "main::a" used only once: possible typo at -e line 1.'],
#todo => 'probly not worth doing',
bcopts => '-exec',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <0> enter
2 <;> nextstate(main 1 -e:1) v
3 <0> stub sP
4 <#> gvsv[*a] s/LVINTRO
5 <2> sassign vKS/2
6 <@> leave[1 ref] vKP/REFC
EOT_EOT
# 1 <0> enter
# 2 <;> nextstate(main 1 -e:1) v
# 3 <0> stub sP
# 4 <$> gvsv(*a) s/LVINTRO
# 5 <2> sassign vKS/2
# 6 <@> leave[1 ref] vKP/REFC
EONT_EONT
checkOptree ( name => 'my ($a,$b)=()',
prog => 'my ($a,$b)=()',
#todo => 'probly not worth doing',
bcopts => '-exec',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 1 <0> enter
# 2 <;> nextstate(main 1 -e:1) v
# 3 <0> pushmark s
# 4 <0> pushmark sRM*/128
# 5 <0> padsv[$a:1,2] lRM*/LVINTRO
# 6 <0> padsv[$b:1,2] lRM*/LVINTRO
# 7 <2> aassign[t3] vKS
# 8 <@> leave[1 ref] vKP/REFC
EOT_EOT
# 1 <0> enter
# 2 <;> nextstate(main 1 -e:1) v
# 3 <0> pushmark s
# 4 <0> pushmark sRM*/128
# 5 <0> padsv[$a:1,2] lRM*/LVINTRO
# 6 <0> padsv[$b:1,2] lRM*/LVINTRO
# 7 <2> aassign[t3] vKS
# 8 <@> leave[1 ref] vKP/REFC
EONT_EONT
} #skip
__END__
|