1# Copyright (C) 2001-2008, Parrot Foundation.
2
3=head1 NAME
4
5examples/benchmarks/arriter.pir - Iterator Benchmark
6
7=head1 SYNOPSIS
8
9    % time ./parrot examples/benchmarks/arriter.pir
10
11=head1 DESCRIPTION
12
13Hand crafted PIR code version of F<examples/benchmarks/arriter.pl> as
14it might come out of a compiler.
15
16=head1 SEE ALSO
17
18F<examples/benchmarks/arriter.pl>,
19F<examples/benchmarks/arriter_o1.pir>.
20
21=cut
22
23.sub arriter :main
24
25# declaration of lexicals
26    $P20 = new 'Hash'
27    .lex "%ha", $P20
28    $P21 = new 'Undef'
29    .lex "$i", $P21
30    $P22 = new 'ResizablePMCArray'
31    .lex "@k", $P22
32    $P23 = new 'ResizablePMCArray'
33    .lex "@nk", $P23
34    $P24 = new 'Undef'
35    .lex "$s", $P24
36
37# same as @k = qw( A B C D E F G H I J );
38    find_lex $P29 , "$i"
39    $P29 = 0
40for_1_start:
41    unless $P29 < 10 goto for_1_end
42        $P26 = new 'Undef'
43        $P26 = 65
44        $P27 = new 'Undef'
45        $P27 = add $P26, $P29
46        $I0 = $P27
47        $S0 = chr $I0
48        find_lex $P28 , "$s"
49        $P28 = new 'Undef'
50        $P28 = $S0
51        push $P22, $P28
52        inc $P29
53        branch for_1_start
54for_1_end:
55
56# set up all 5 element permutations of qw( A B C D E F G H I J )
57    $P29 = new 'Undef'
58    .lex "e", $P29
59    $P29 = 0
60for_2_start:
61    unless $P29 <= 3 goto for_2_end
62        find_lex $P30 , "$i"
63        $P30 = 0
64for_3_start:
65        unless $P30 < 10 goto for_3_end
66            find_lex $P31 , "@k"
67            $P32 = iter $P31
68iter_1_start:
69            unless $P32 goto iter_1_end
70                $P33 = new 'Undef'
71                $P33 = 65
72                $P34 = new 'Undef'
73                add $P34, $P33, $P30        # 65 + $i
74                $I0 = $P34
75                $S0 = chr $I0
76                $P35 = new 'Undef'
77                $P35 = $S0
78                shift $P36, $P32                # $s
79                # $P37 goes into the aggregate and can not be
80                # pulled out of loop
81                $P37 = new 'Undef'
82                concat $P37, $P36, $P35
83                $P38 = find_lex "@nk"
84                push $P38, $P37
85                branch iter_1_start
86iter_1_end:
87        inc $P30
88        branch for_3_start
89for_3_end:
90        $P39 = find_lex "@nk"
91        # XXX why does this not work ?
92        # $P40 = find_lex "@k"
93        # clone $P40, $P39
94        clone $P22, $P39
95        $P39 = 0
96        inc $P29
97        branch for_2_start
98for_2_end:
99
100    # XXX why does this not work ?
101    # $P41 = find_lex "@k"
102    # $I0 = $P22
103    $I0 = $P22
104    print $I0
105    print "\n"
106
107    $P42 = iter $P22
108    $P43 = find_lex "%ha"
109    $I1 = 0
110iter_2_start:
111    unless $P42 goto iter_2_end
112        inc $I1
113        shift $P44, $P42
114        $S0 = $P44
115        $P43[$S0] = 1
116        branch iter_2_start
117iter_2_end:
118
119    print $I1
120    print "\n"
121    $I0 = $P43
122    print $I0
123    print "\n"
124    $I0 = defined $P43["AAAAA"]
125    print $I0
126    $I0 = defined $P43["ABCDE"]
127    print $I0
128    $I0 = defined $P43["BBBBB"]
129    print $I0
130    $I0 = defined $P43["CCCCC"]
131    print $I0
132    $I0 = defined $P43["HHHHH"]
133    print $I0
134    $I0 = defined $P43["IIIII"]
135    print $I0
136    print "\n"
137.end
138
139# Local Variables:
140#   mode: pir
141#   fill-column: 100
142# End:
143# vim: expandtab shiftwidth=4 ft=pir:
144