xref: /openbsd-src/gnu/usr.bin/perl/ext/B/t/optree_samples.t (revision e068048151d29f2562a32185e21a8ba885482260)
1#!perl
2
3BEGIN {
4    unshift @INC, 't';
5    require Config;
6    if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7        print "1..0 # Skip -- Perl configured without B module\n";
8        exit 0;
9    }
10}
11use OptreeCheck;
12plan tests	=> 46;
13
14pass("GENERAL OPTREE EXAMPLES");
15
16pass("IF,THEN,ELSE, ?:");
17
18checkOptree ( name	=> '-basic sub {if shift print then,else}',
19	      bcopts	=> '-basic',
20	      code	=> sub { if (shift) { print "then" }
21				 else       { print "else" }
22			     },
23	      strip_open_hints => 1,
24	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
25# 7  <1> leavesub[1 ref] K/REFC,1 ->(end)
26# -     <@> lineseq KP ->7
27# 1        <;> nextstate(main 665 optree_samples.t:24) v:>,<,% ->2
28# -        <1> null K/1 ->-
29# 3           <|> cond_expr(other->4) K/1 ->8
30# 2              <0> shift s* ->3
31# -              <@> scope K ->-
32# -                 <;> ex-nextstate(main 1594 optree_samples.t:25) v:>,<,% ->4
33# 6                 <@> print sK ->7
34# 4                    <0> pushmark s ->5
35# 5                    <$> const[PV "then"] s ->6
36# d              <@> leave KP ->7
37# 8                 <0> enter ->9
38# 9                 <;> nextstate(main 663 optree_samples.t:25) v:>,<,% ->a
39# c                 <@> print sK ->d
40# a                    <0> pushmark s ->b
41# b                    <$> const[PV "else"] s ->c
42EOT_EOT
43# 7  <1> leavesub[1 ref] K/REFC,1 ->(end)
44# -     <@> lineseq KP ->7
45# 1        <;> nextstate(main 665 optree_samples.t:24) v:>,<,% ->2
46# -        <1> null K/1 ->-
47# 3           <|> cond_expr(other->4) K/1 ->8
48# 2              <0> shift s* ->3
49# -              <@> scope K ->-
50# -                 <;> ex-nextstate(main 1594 optree_samples.t:25) v:>,<,% ->4
51# 6                 <@> print sK ->7
52# 4                    <0> pushmark s ->5
53# 5                    <$> const(PV "then") s ->6
54# d              <@> leave KP ->7
55# 8                 <0> enter ->9
56# 9                 <;> nextstate(main 663 optree_samples.t:25) v:>,<,% ->a
57# c                 <@> print sK ->d
58# a                    <0> pushmark s ->b
59# b                    <$> const(PV "else") s ->c
60EONT_EONT
61
62checkOptree ( name	=> '-basic (see above, with my $a = shift)',
63	      bcopts	=> '-basic',
64	      code	=> sub { my $a = shift;
65				 if ($a) { print "foo" }
66				 else    { print "bar" }
67			     },
68	      strip_open_hints => 1,
69	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
70# a  <1> leavesub[1 ref] K/REFC,1 ->(end)
71# -     <@> lineseq KP ->a
72# 1        <;> nextstate(main 666 optree_samples.t:70) v:>,<,% ->2
73# 3        <1> padsv_store[$a:666,670] vKS/LVINTRO ->4
74# 2           <0> shift s* ->3
75# -           <0> ex-padsv sRM*/LVINTRO ->3
76# 4        <;> nextstate(main 670 optree_samples.t:71) v:>,<,% ->5
77# -        <1> null K/1 ->-
78# 6           <|> cond_expr(other->7) K/1 ->b
79# 5              <0> padsv[$a:666,670] s ->6
80# -              <@> scope K ->-
81# -                 <;> ex-nextstate(main 1510 optree_samples.t:66) v:>,<,% ->7
82# 9                 <@> print sK ->a
83# 7                    <0> pushmark s ->8
84# 8                    <$> const[PV "foo"] s ->9
85# g              <@> leave KP ->a
86# b                 <0> enter ->c
87# c                 <;> nextstate(main 1510 optree_samples.t:66) v:>,<,% ->d
88# f                 <@> print sK ->g
89# d                    <0> pushmark s ->e
90# e                    <$> const[PV "bar"] s ->f
91EOT_EOT
92# a  <1> leavesub[1 ref] K/REFC,1 ->(end)
93# -     <@> lineseq KP ->a
94# 1        <;> nextstate(main 666 optree_samples.t:70) v:>,<,% ->2
95# 3        <1> padsv_store[$a:666,670] vKS/LVINTRO ->4
96# 2           <0> shift s* ->3
97# -           <0> ex-padsv sRM*/LVINTRO ->3
98# 4        <;> nextstate(main 670 optree_samples.t:71) v:>,<,% ->5
99# -        <1> null K/1 ->-
100# 6           <|> cond_expr(other->7) K/1 ->b
101# 5              <0> padsv[$a:666,670] s ->6
102# -              <@> scope K ->-
103# -                 <;> ex-nextstate(main 1510 optree_samples.t:70) v:>,<,% ->7
104# 9                 <@> print sK ->a
105# 7                    <0> pushmark s ->8
106# 8                    <$> const(PV "foo") s ->9
107# g              <@> leave KP ->a
108# b                 <0> enter ->c
109# c                 <;> nextstate(main 668 optree_samples.t:72) v:>,<,% ->d
110# f                 <@> print sK ->g
111# d                    <0> pushmark s ->e
112# e                    <$> const(PV "bar") s ->f
113EONT_EONT
114
115checkOptree ( name	=> '-exec sub {if shift print then,else}',
116	      bcopts	=> '-exec',
117	      code	=> sub { if (shift) { print "then" }
118				 else       { print "else" }
119			     },
120	      strip_open_hints => 1,
121	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
122# 1  <;> nextstate(main 674 optree_samples.t:125) v:>,<,%
123# 2  <0> shift s*
124# 3  <|> cond_expr(other->4) K/1
125# 4      <0> pushmark s
126# 5      <$> const[PV "then"] s
127# 6      <@> print sK
128#            goto 7
129# 8  <0> enter
130# 9  <;> nextstate(main 672 optree_samples.t:126) v:>,<,%
131# a  <0> pushmark s
132# b  <$> const[PV "else"] s
133# c  <@> print sK
134# d  <@> leave KP
135# 7  <1> leavesub[1 ref] K/REFC,1
136EOT_EOT
137# 1  <;> nextstate(main 674 optree_samples.t:129) v:>,<,%
138# 2  <0> shift s*
139# 3  <|> cond_expr(other->4) K/1
140# 4      <0> pushmark s
141# 5      <$> const(PV "then") s
142# 6      <@> print sK
143#            goto 7
144# 8  <0> enter
145# 9  <;> nextstate(main 672 optree_samples.t:130) v:>,<,%
146# a  <0> pushmark s
147# b  <$> const(PV "else") s
148# c  <@> print sK
149# d  <@> leave KP
150# 7  <1> leavesub[1 ref] K/REFC,1
151EONT_EONT
152
153checkOptree ( name	=> '-exec (see above, with my $a = shift)',
154	      bcopts	=> '-exec',
155	      code	=> sub { my $a = shift;
156				 if ($a) { print "foo" }
157				 else    { print "bar" }
158			     },
159	      strip_open_hints => 1,
160	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
161# 1  <;> nextstate(main 675 optree_samples.t:165) v:>,<,%
162# 2  <0> shift s*
163# 3  <1> padsv_store[$a:1522,1529] vKS/LVINTRO
164# 4  <;> nextstate(main 679 optree_samples.t:166) v:>,<,%
165# 5  <0> padsv[$a:675,679] s
166# 6  <|> cond_expr(other->7) K/1
167# 7      <0> pushmark s
168# 8      <$> const[PV "foo"] s
169# 9      <@> print sK
170#            goto a
171# b  <0> enter
172# c  <;> nextstate(main 677 optree_samples.t:167) v:>,<,%
173# d  <0> pushmark s
174# e  <$> const[PV "bar"] s
175# f  <@> print sK
176# g  <@> leave KP
177# a  <1> leavesub[1 ref] K/REFC,1
178EOT_EOT
179# 1  <;> nextstate(main 675 optree_samples.t:171) v:>,<,%
180# 2  <0> shift s*
181# 3  <1> padsv_store[$a:1522,1529] vKS/LVINTRO
182# 4  <;> nextstate(main 679 optree_samples.t:172) v:>,<,%
183# 5  <0> padsv[$a:675,679] s
184# 6  <|> cond_expr(other->7) K/1
185# 7      <0> pushmark s
186# 8      <$> const(PV "foo") s
187# 9      <@> print sK
188#            goto a
189# b  <0> enter
190# c  <;> nextstate(main 677 optree_samples.t:173) v:>,<,%
191# d  <0> pushmark s
192# e  <$> const(PV "bar") s
193# f  <@> print sK
194# g  <@> leave KP
195# a  <1> leavesub[1 ref] K/REFC,1
196EONT_EONT
197
198checkOptree ( name	=> '-exec sub { print (shift) ? "foo" : "bar" }',
199	      code	=> sub { print (shift) ? "foo" : "bar" },
200	      bcopts	=> '-exec',
201	      strip_open_hints => 1,
202	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
203# 1  <;> nextstate(main 680 optree_samples.t:213) v:>,<,%
204# 2  <0> pushmark s
205# 3  <0> shift s*
206# 4  <@> print sK
207# 5  <|> cond_expr(other->6) K/1
208# 6      <$> const[PV "foo"] s
209#            goto 7
210# 8  <$> const[PV "bar"] s
211# 7  <1> leavesub[1 ref] K/REFC,1
212EOT_EOT
213# 1  <;> nextstate(main 680 optree_samples.t:221) v:>,<,%
214# 2  <0> pushmark s
215# 3  <0> shift s*
216# 4  <@> print sK
217# 5  <|> cond_expr(other->6) K/1
218# 6      <$> const(PV "foo") s
219#            goto 7
220# 8  <$> const(PV "bar") s
221# 7  <1> leavesub[1 ref] K/REFC,1
222EONT_EONT
223
224pass ("FOREACH");
225
226checkOptree ( name	=> '-exec sub { foreach (1..10) {print "foo $_"} }',
227	      code	=> sub { foreach (1..10) {print "foo $_"} },
228	      bcopts	=> '-exec',
229	      strip_open_hints => 1,
230	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
231# 1  <;> nextstate(main 443 optree.t:158) v:>,<,%
232# 2  <0> pushmark s
233# 3  <$> const[IV 1] s
234# 4  <$> const[IV 10] s
235# 5  <#> gv[*_] s
236# 6  <{> enteriter(next->c last->f redo->7) KS/DEF
237# d  <0> iter s
238# e  <|> and(other->7) K/1
239# 7      <;> nextstate(main 1659 optree_samples.t:234) v:>,<,%
240# 8      <0> pushmark s
241# 9      <#> gvsv[*_] s
242# a      <+> multiconcat("foo ",4,-1)[t5] sK/STRINGIFY
243# b      <@> print vK
244# c      <0> unstack s
245#            goto d
246# f  <2> leaveloop K/2
247# g  <1> leavesub[1 ref] K/REFC,1
248EOT_EOT
249# 1  <;> nextstate(main 444 optree_samples.t:182) v:>,<,%
250# 2  <0> pushmark s
251# 3  <$> const(IV 1) s
252# 4  <$> const(IV 10) s
253# 5  <$> gv(*_) s
254# 6  <{> enteriter(next->c last->f redo->7) KS/DEF
255# d  <0> iter s
256# e  <|> and(other->7) K/1
257# 7      <;> nextstate(main 443 optree_samples.t:182) v:>,<,%
258# 8      <0> pushmark s
259# 9      <$> gvsv(*_) s
260# a      <+> multiconcat("foo ",4,-1)[t4] sK/STRINGIFY
261# b      <@> print vK
262# c      <0> unstack s
263#            goto d
264# f  <2> leaveloop K/2
265# g  <1> leavesub[1 ref] K/REFC,1
266EONT_EONT
267
268checkOptree ( name	=> '-basic sub { print "foo $_" foreach (1..10) }',
269	      code	=> sub { print "foo $_" foreach (1..10) },
270	      bcopts	=> '-basic',
271	      strip_open_hints => 1,
272	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
273# f  <1> leavesub[1 ref] K/REFC,1 ->(end)
274# -     <@> lineseq KP ->f
275# 1        <;> nextstate(main 445 optree.t:167) v:>,<,% ->2
276# e        <2> leaveloop K/2 ->f
277# 6           <{> enteriter(next->b last->e redo->7) KS/DEF ->c
278# -              <0> ex-pushmark s ->2
279# -              <1> ex-list lK ->5
280# 2                 <0> pushmark s ->3
281# 3                 <$> const[IV 1] s ->4
282# 4                 <$> const[IV 10] s ->5
283# 5              <#> gv[*_] s ->6
284# -           <1> null K/1 ->e
285# d              <|> and(other->7) K/1 ->e
286# c                 <0> iter s ->d
287# -                 <@> lineseq sK ->-
288# a                    <@> print vK ->b
289# 7                       <0> pushmark s ->8
290# 9                       <+> multiconcat("foo ",4,-1)[t3] sK/STRINGIFY ->a
291# -                          <0> ex-pushmark s ->-
292# -                          <0> ex-const s ->8
293# -                          <1> ex-rv2sv sK/1 ->9
294# 8                             <#> gvsv[*_] s ->9
295# b                    <0> unstack s ->c
296EOT_EOT
297# f  <1> leavesub[1 ref] K/REFC,1 ->(end)
298# -     <@> lineseq KP ->f
299# 1        <;> nextstate(main 446 optree_samples.t:192) v:>,<,% ->2
300# e        <2> leaveloop K/2 ->f
301# 6           <{> enteriter(next->b last->e redo->7) KS/DEF ->c
302# -              <0> ex-pushmark s ->2
303# -              <1> ex-list lK ->5
304# 2                 <0> pushmark s ->3
305# 3                 <$> const(IV 1) s ->4
306# 4                 <$> const(IV 10) s ->5
307# 5              <$> gv(*_) s ->6
308# -           <1> null K/1 ->e
309# d              <|> and(other->7) K/1 ->e
310# c                 <0> iter s ->d
311# -                 <@> lineseq sK ->-
312# a                    <@> print vK ->b
313# 7                       <0> pushmark s ->8
314# 9                       <+> multiconcat("foo ",4,-1)[t2] sK/STRINGIFY ->a
315# -                          <0> ex-pushmark s ->-
316# -                          <0> ex-const s ->8
317# -                          <1> ex-rv2sv sK/1 ->9
318# 8                             <$> gvsv(*_) s ->9
319# b                    <0> unstack s ->c
320EONT_EONT
321
322checkOptree ( name	=> '-exec -e foreach (1..10) {print qq{foo $_}}',
323	      prog	=> 'foreach (1..10) {print qq{foo $_}}',
324	      bcopts	=> '-exec',
325	      strip_open_hints => 1,
326	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
327# 1  <0> enter v
328# 2  <;> nextstate(main 2 -e:1) v:>,<,%,{
329# 3  <0> pushmark s
330# 4  <$> const[IV 1] s
331# 5  <$> const[IV 10] s
332# 6  <#> gv[*_] s
333# 7  <{> enteriter(next->d last->g redo->8) vKS/DEF
334# e  <0> iter s
335# f  <|> and(other->8) vK/1
336# 8      <;> nextstate(main 1 -e:1) v:>,<,%
337# 9      <0> pushmark s
338# a      <#> gvsv[*_] s
339# b      <+> multiconcat("foo ",4,-1)[t5] sK/STRINGIFY
340# c      <@> print vK
341# d      <0> unstack v
342#            goto e
343# g  <2> leaveloop vK/2
344# h  <@> leave[1 ref] vKP/REFC
345EOT_EOT
346# 1  <0> enter v
347# 2  <;> nextstate(main 2 -e:1) v:>,<,%,{
348# 3  <0> pushmark s
349# 4  <$> const(IV 1) s
350# 5  <$> const(IV 10) s
351# 6  <$> gv(*_) s
352# 7  <{> enteriter(next->d last->g redo->8) vKS/DEF
353# e  <0> iter s
354# f  <|> and(other->8) vK/1
355# 8      <;> nextstate(main 1 -e:1) v:>,<,%
356# 9      <0> pushmark s
357# a      <$> gvsv(*_) s
358# b      <+> multiconcat("foo ",4,-1)[t4] sK/STRINGIFY
359# c      <@> print vK
360# d      <0> unstack v
361#            goto e
362# g  <2> leaveloop vK/2
363# h  <@> leave[1 ref] vKP/REFC
364EONT_EONT
365
366checkOptree ( name	=> '-exec sub { print "foo $_" foreach (1..10) }',
367	      code	=> sub { print "foo $_" foreach (1..10) },
368	      bcopts	=> '-exec',
369	      strip_open_hints => 1,
370	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
371# 1  <;> nextstate(main 445 optree.t:167) v:>,<,%
372# 2  <0> pushmark s
373# 3  <$> const[IV 1] s
374# 4  <$> const[IV 10] s
375# 5  <#> gv[*_] s
376# 6  <{> enteriter(next->b last->e redo->7) KS/DEF
377# c  <0> iter s
378# d  <|> and(other->7) K/1
379# 7      <0> pushmark s
380# 8      <#> gvsv[*_] s
381# 9      <+> multiconcat("foo ",4,-1)[t3] sK/STRINGIFY
382# a      <@> print vK
383# b      <0> unstack s
384#            goto c
385# e  <2> leaveloop K/2
386# f  <1> leavesub[1 ref] K/REFC,1
387EOT_EOT
388# 1  <;> nextstate(main 447 optree_samples.t:252) v:>,<,%
389# 2  <0> pushmark s
390# 3  <$> const(IV 1) s
391# 4  <$> const(IV 10) s
392# 5  <$> gv(*_) s
393# 6  <{> enteriter(next->b last->e redo->7) KS/DEF
394# c  <0> iter s
395# d  <|> and(other->7) K/1
396# 7      <0> pushmark s
397# 8      <$> gvsv(*_) s
398# 9      <+> multiconcat("foo ",4,-1)[t2] sK/STRINGIFY
399# a      <@> print vK
400# b      <0> unstack s
401#            goto c
402# e  <2> leaveloop K/2
403# f  <1> leavesub[1 ref] K/REFC,1
404EONT_EONT
405
406pass("GREP: SAMPLES FROM PERLDOC -F GREP");
407
408checkOptree ( name	=> '@foo = grep(!/^\#/, @bar)',
409	      code	=> '@foo = grep(!/^\#/, @bar)',
410	      bcopts	=> '-exec',
411	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
412# 1  <;> nextstate(main 496 (eval 20):1) v:{
413# 2  <0> pushmark s
414# 3  <0> pushmark s
415# 4  <#> gv[*bar] s
416# 5  <1> rv2av[t4] lKM/1
417# 6  <@> grepstart lK
418# 7  <|> grepwhile(other->8)[t5] lK
419# 8      </> match(/"^#"/) s
420# 9      <1> not sK/1
421#            goto 7
422# a  <0> pushmark s
423# b  <#> gv[*foo] s
424# c  <1> rv2av[t2] lKRM*/1
425# d  <2> aassign[t6] KS/COM_AGG
426# e  <1> leavesub[1 ref] K/REFC,1
427EOT_EOT
428# 1  <;> nextstate(main 496 (eval 20):1) v:{
429# 2  <0> pushmark s
430# 3  <0> pushmark s
431# 4  <$> gv(*bar) s
432# 5  <1> rv2av[t2] lKM/1
433# 6  <@> grepstart lK
434# 7  <|> grepwhile(other->8)[t3] lK
435# 8      </> match(/"^\\#"/) s
436# 9      <1> not sK/1
437#            goto 7
438# a  <0> pushmark s
439# b  <$> gv(*foo) s
440# c  <1> rv2av[t1] lKRM*/1
441# d  <2> aassign[t4] KS/COM_AGG
442# e  <1> leavesub[1 ref] K/REFC,1
443EONT_EONT
444
445
446pass("MAP: SAMPLES FROM PERLDOC -F MAP");
447
448checkOptree ( name	=> '%h = map { getkey($_) => $_ } @a',
449	      code	=> '%h = map { getkey($_) => $_ } @a',
450	      bcopts	=> '-exec',
451	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
452# 1  <;> nextstate(main 501 (eval 22):1) v:{
453# 2  <0> pushmark s
454# 3  <0> pushmark s
455# 4  <#> gv[*a] s
456# 5  <1> rv2av[t8] lKM/1
457# 6  <@> mapstart lK
458# 7  <|> mapwhile(other->8)[t9] lK
459# 8      <0> enter l
460# 9      <;> nextstate(main 500 (eval 22):1) v:{
461# a      <0> pushmark s
462# b      <#> gvsv[*_] s
463# c      <#> gv[*getkey] s/EARLYCV
464# d      <1> entersub[t5] lKS/TARG
465# e      <#> gvsv[*_] s
466# f      <@> leave lKP
467#            goto 7
468# g  <0> pushmark s
469# h  <#> gv[*h] s
470# i  <1> rv2hv[t2] lKRM*
471# j  <2> aassign[t10] KS/COM_AGG
472# k  <1> leavesub[1 ref] K/REFC,1
473EOT_EOT
474# 1  <;> nextstate(main 501 (eval 22):1) v:{
475# 2  <0> pushmark s
476# 3  <0> pushmark s
477# 4  <$> gv(*a) s
478# 5  <1> rv2av[t3] lKM/1
479# 6  <@> mapstart lK
480# 7  <|> mapwhile(other->8)[t4] lK
481# 8      <0> enter l
482# 9      <;> nextstate(main 500 (eval 22):1) v:{
483# a      <0> pushmark s
484# b      <$> gvsv(*_) s
485# c      <$> gv(*getkey) s/EARLYCV
486# d      <1> entersub[t2] lKS/TARG
487# e      <$> gvsv(*_) s
488# f      <@> leave lKP
489#            goto 7
490# g  <0> pushmark s
491# h  <$> gv(*h) s
492# i  <1> rv2hv[t1] lKRM*
493# j  <2> aassign[t5] KS/COM_AGG
494# k  <1> leavesub[1 ref] K/REFC,1
495EONT_EONT
496
497checkOptree ( name	=> '%h=(); for $_(@a){$h{getkey($_)} = $_}',
498	      code	=> '%h=(); for $_(@a){$h{getkey($_)} = $_}',
499	      bcopts	=> '-exec',
500	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
501# 1  <;> nextstate(main 505 (eval 24):1) v
502# 2  <0> pushmark s
503# 3  <0> pushmark s
504# 4  <#> gv[*h] s
505# 5  <1> rv2hv[t2] lKRM*
506# 6  <2> aassign[t3] vKS
507# 7  <;> nextstate(main 506 (eval 24):1) v:{
508# 8  <0> pushmark sM
509# 9  <#> gv[*a] s
510# a  <1> rv2av[t6] sKRM/1
511# b  <#> gv[*_] s
512# c  <1> rv2gv sKRM/1
513# d  <{> enteriter(next->o last->r redo->e) KS/DEF
514# p  <0> iter s
515# q  <|> and(other->e) K/1
516# e      <;> nextstate(main 505 (eval 24):1) v:{
517# f      <#> gvsv[*_] s
518# g      <#> gv[*h] s
519# h      <1> rv2hv sKR
520# i      <0> pushmark s
521# j      <#> gvsv[*_] s
522# k      <#> gv[*getkey] s/EARLYCV
523# l      <1> entersub[t10] sKS/TARG
524# m      <2> helem sKRM*/2
525# n      <2> sassign vKS/2
526# o      <0> unstack s
527#            goto p
528# r  <2> leaveloop KP/2
529# s  <1> leavesub[1 ref] K/REFC,1
530EOT_EOT
531# 1  <;> nextstate(main 505 (eval 24):1) v
532# 2  <0> pushmark s
533# 3  <0> pushmark s
534# 4  <$> gv(*h) s
535# 5  <1> rv2hv[t1] lKRM*
536# 6  <2> aassign[t2] vKS
537# 7  <;> nextstate(main 506 (eval 24):1) v:{
538# 8  <0> pushmark sM
539# 9  <$> gv(*a) s
540# a  <1> rv2av[t3] sKRM/1
541# b  <$> gv(*_) s
542# c  <1> rv2gv sKRM/1
543# d  <{> enteriter(next->o last->r redo->e) KS/DEF
544# p  <0> iter s
545# q  <|> and(other->e) K/1
546# e      <;> nextstate(main 505 (eval 24):1) v:{
547# f      <$> gvsv(*_) s
548# g      <$> gv(*h) s
549# h      <1> rv2hv sKR
550# i      <0> pushmark s
551# j      <$> gvsv(*_) s
552# k      <$> gv(*getkey) s/EARLYCV
553# l      <1> entersub[t4] sKS/TARG
554# m      <2> helem sKRM*/2
555# n      <2> sassign vKS/2
556# o      <0> unstack s
557#            goto p
558# r  <2> leaveloop KP/2
559# s  <1> leavesub[1 ref] K/REFC,1
560EONT_EONT
561
562checkOptree ( name	=> 'map $_+42, 10..20',
563	      code	=> 'map $_+42, 10..20',
564	      bcopts	=> '-exec',
565	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
566# 1  <;> nextstate(main 497 (eval 20):1) v
567# 2  <0> pushmark s
568# 3  <$> const[AV ARRAY] s
569# 4  <1> rv2av lKPM/1
570# 5  <@> mapstart K
571# 6  <|> mapwhile(other->7)[t5] K
572# 7      <#> gvsv[*_] s
573# 8      <$> const[IV 42] s
574# 9      <2> add[t2] sK/2
575#            goto 6
576# a  <1> leavesub[1 ref] K/REFC,1
577EOT_EOT
578# 1  <;> nextstate(main 511 (eval 26):1) v
579# 2  <0> pushmark s
580# 3  <$> const(AV ARRAY) s
581# 4  <1> rv2av lKPM/1
582# 5  <@> mapstart K
583# 6  <|> mapwhile(other->7)[t4] K
584# 7      <$> gvsv(*_) s
585# 8      <$> const(IV 42) s
586# 9      <2> add[t1] sK/2
587#            goto 6
588# a  <1> leavesub[1 ref] K/REFC,1
589EONT_EONT
590
591pass("CONSTANTS");
592
593checkOptree ( name	=> '-e use constant j => qq{junk}; print j',
594	      prog	=> 'use constant j => qq{junk}; print j',
595	      bcopts	=> '-exec',
596	      strip_open_hints => 1,
597	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
598# 1  <0> enter v
599# 2  <;> nextstate(main 71 -e:1) v:>,<,%,{
600# 3  <0> pushmark s
601# 4  <$> const[PV "junk"] s*/FOLD
602# 5  <@> print vK
603# 6  <@> leave[1 ref] vKP/REFC
604EOT_EOT
605# 1  <0> enter v
606# 2  <;> nextstate(main 71 -e:1) v:>,<,%,{
607# 3  <0> pushmark s
608# 4  <$> const(PV "junk") s*/FOLD
609# 5  <@> print vK
610# 6  <@> leave[1 ref] vKP/REFC
611EONT_EONT
612
613pass("rpeep - return \$x at end of sub");
614
615checkOptree ( name	=> '-exec sub { return 1 }',
616	      code	=> sub { return 1 },
617	      bcopts	=> '-exec',
618	      strip_open_hints => 1,
619	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
620# 1  <;> nextstate(main 1 -e:1) v:>,<,%
621# 2  <$> const[IV 1] s
622# 3  <1> leavesub[1 ref] K/REFC,1
623EOT_EOT
624# 1  <;> nextstate(main 1 -e:1) v:>,<,%
625# 2  <$> const(IV 1) s
626# 3  <1> leavesub[1 ref] K/REFC,1
627EONT_EONT
628
629pass("rpeep - if ($a || $b)");
630
631checkOptree ( name	=> 'if ($a || $b) { } return 1',
632	      code	=> 'if ($a || $b) { } return 1',
633	      bcopts	=> '-exec',
634	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
635# 1  <;> nextstate(main 997 (eval 15):1) v
636# 2  <#> gvsv[*a] s
637# 3  <|> or(other->4) sK/1
638# 4      <#> gvsv[*b] s
639# 5      <|> and(other->6) vK/1
640# 6  <0> stub v
641# 7  <;> nextstate(main 997 (eval 15):1) v
642# 8  <$> const[IV 1] s
643# 9  <1> leavesub[1 ref] K/REFC,1
644EOT_EOT
645# 1  <;> nextstate(main 997 (eval 15):1) v
646# 2  <$> gvsv(*a) s
647# 3  <|> or(other->4) sK/1
648# 4      <$> gvsv(*b) s
649# 5      <|> and(other->6) vK/1
650# 6  <0> stub v
651# 7  <;> nextstate(main 3 (eval 3):1) v
652# 8  <$> const(IV 1) s
653# 9  <1> leavesub[1 ref] K/REFC,1
654EONT_EONT
655
656pass("rpeep - unless ($a && $b)");
657
658checkOptree ( name	=> 'unless ($a && $b) { } return 1',
659	      code	=> 'unless ($a && $b) { } return 1',
660	      bcopts	=> '-exec',
661	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
662# 1  <;> nextstate(main 997 (eval 15):1) v
663# 2  <#> gvsv[*a] s
664# 3  <|> and(other->4) sK/1
665# 4      <#> gvsv[*b] s
666# 5      <|> or(other->6) vK/1
667# 6  <0> stub v
668# 7  <;> nextstate(main 997 (eval 15):1) v
669# 8  <$> const[IV 1] s
670# 9  <1> leavesub[1 ref] K/REFC,1
671EOT_EOT
672# 1  <;> nextstate(main 997 (eval 15):1) v
673# 2  <$> gvsv(*a) s
674# 3  <|> and(other->4) sK/1
675# 4      <$> gvsv(*b) s
676# 5      <|> or(other->6) vK/1
677# 6  <0> stub v
678# 7  <;> nextstate(main 3 (eval 3):1) v
679# 8  <$> const(IV 1) s
680# 9  <1> leavesub[1 ref] K/REFC,1
681EONT_EONT
682
683pass("rpeep - my $a; my @b; my %c; print 'f'");
684
685checkOptree ( name	=> 'my $a; my @b; my %c; return 1',
686	      code	=> 'my $a; my @b; my %c; return 1',
687	      bcopts	=> '-exec',
688	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
689# 1  <;> nextstate(main 991 (eval 17):1) v
690# 2  <0> padrange[$a:991,994; @b:992,994; %c:993,994] vM/LVINTRO,range=3
691# 3  <;> nextstate(main 994 (eval 17):1) v:{
692# 4  <$> const[IV 1] s
693# 5  <1> leavesub[1 ref] K/REFC,1
694EOT_EOT
695# 1  <;> nextstate(main 991 (eval 17):1) v
696# 2  <0> padrange[$a:991,994; @b:992,994; %c:993,994] vM/LVINTRO,range=3
697# 3  <;> nextstate(main 994 (eval 17):1) v:{
698# 4  <$> const(IV 1) s
699# 5  <1> leavesub[1 ref] K/REFC,1
700EONT_EONT
701
702__END__
703
704#######################################################################
705
706checkOptree ( name	=> '-exec sub a { print (shift) ? "foo" : "bar" }',
707	      code	=> sub { print (shift) ? "foo" : "bar" },
708	      bcopts	=> '-exec',
709	      expect	=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
710   insert threaded reference here
711EOT_EOT
712   insert non-threaded reference here
713EONT_EONT
714
715