tagged release 0.7.1
[parrot.git] / compilers / nqp / bootstrap / nqp.pir
blob7bddfc3c4a6c46cfae05765796b971740a9017a2
1 =head1 TITLE
3 nqp.pir - A nqp compiler.
5 =head2 Description
7 This is the base file for the nqp compiler.
9 This file includes the parsing and grammar rules from
10 the src/ directory, loads the relevant PGE libraries,
11 and registers the compiler under the name 'nqp'.
13 =head2 Functions
15 =over 4
17 =item onload()
19 Creates the nqp compiler using a C<PCT::HLLCompiler>
20 object.
22 =cut
24 .namespace [ 'NQP::Compiler' ]
26 .loadlib 'nqp_group'
28 .sub 'onload' :anon :load :init
29     load_bytecode 'PCT.pbc'
31     $P0 = get_hll_global ['PCT'], 'HLLCompiler'
32     $P1 = $P0.'new'()
33     $P1.'language'('NQP')
34     $P1.'parsegrammar'('NQP::Grammar')
35     $P1.'parseactions'('NQP::Grammar::Actions')
36 .end
38 =item main(args :slurpy)  :main
40 Start compilation by passing any command line C<args>
41 to the nqp compiler.
43 =cut
45 .sub 'main' :main
46     .param pmc args
48     $P0 = compreg 'NQP'
49     $P1 = $P0.'command_line'(args)
50 .end
52 .include 'src/builtins.pir'
53 .include 'src/Grammar_gen.pir'
54 .include 'bootstrap/gen_actions.pir'
57 .namespace []
59 .sub 'initlist' :anon :load :init
60     subclass $P0, 'ResizablePMCArray', 'List'
61     $P0 = new 'List'
62     set_hll_global ['NQP';'Grammar';'Actions'], '@?BLOCK', $P0
63 .end
66 .namespace [ 'List' ]
68 .sub 'unshift' :method
69     .param pmc obj
70     unshift self, obj
71 .end
73 .sub 'shift' :method
74     shift $P0, self
75     .return ($P0)
76 .end
78 .sub 'push' :method
79     .param pmc obj
80     push self, obj
81 .end
84 #.namespace [ 'NQP::Grammar::Actions' ]
86 #.sub 'package_declarator_helper'
87 #    .param pmc match
88 #    .param pmc key
89 #    .local pmc past
90 #    $P0 = match[key]
91 #    past = $P0.'get_scalar'()
92 #    $P1 = match['name']
93 #    $P1 = $P1['ident']
94 #    past.'namespace'($P1)
95 #    past.'blocktype'('declaration')
96 #    past.'pirflags'(':init :load')
97 #    past.'lexical'(0)
98 #    $S0 = match['sym']
99 #    if $S0 != 'class' goto class_done
100 #    .local string inline
101 #    inline = <<'        INLINE'
102 #        $P0 = get_hll_global 'Protomaker'
103 #        $P1 = split '::', '%s'
104 #        push_eh subclass_done
105 #        $P2 = $P0.'new_subclass'('Protoobject', $P1)
106 #        pop_eh
107 #      subclass_done:
108 #        INLINE
109 #    $S0 = match['name']
110 #    $I0 = index inline, '%s'
111 #    substr inline, $I0, 2, $S0
112 #    $P0 = get_hll_global ['PAST'], 'Op'
113 #    $P1 = $P0.'new'('inline'=>inline, 'pasttype'=>'inline')
114 #    $P2 = past[0]
115 #    $P2.'push'($P1)
116 #  class_done:
117 #    match.'result_object'(past)
118 #.end
122 .sub '__onload' :init :load
124     ##  initialize optable with inline PIR
125     .local pmc optable
126     optable = get_hll_global [ 'NQP::Grammar' ], '$optable'
127     optable['prefix:~'; 'inline'] = <<"        END"
128         ##  inline prefix:~
129         $S0 = %0
130         %r = new 'String'
131         %r = $S0
132         END
134     optable['prefix:+'; 'inline'] = <<"        END"
135         ##  inline prefix:+
136         $N0 = %0
137         %r = new 'Float'
138         %r = $N0
139         END
141     optable['infix:=='; 'inline'] = <<"        END"
142         ##  inline infix:==
143         $I0 = cmp_num %0, %1
144         $I0 = iseq $I0, 0
145         %r = new 'Integer'
146         %r = $I0
147         END
149     optable['infix:!='; 'inline'] = <<"        END"
150         ##  inline infix:!=
151         $I0 = cmp_num %0, %1
152         $I0 = isne $I0, 0
153         %r = new 'Integer'
154         %r = $I0
155         END
157     optable['infix:eq'; 'inline'] = <<"        END"
158         ##  inline infix:eq
159         $S0 = %0
160         $S1 = %1
161         $I0 = iseq $S0, $S1
162         %r = new 'Integer'
163         %r = $I0
164         END
166     optable['infix:ne'; 'inline'] = <<"        END"
167         ##  inline infix:ne
168         $S0 = %0
169         $S1 = %1
170         $I0 = isne $S0, $S1
171         %r = new 'Integer'
172         %r = $I0
173         END
175     optable['infix:=:='; 'inline'] = <<"        END"
176         ##  inline infix:=:=
177         $I0 = issame %0, %1
178         %r = new 'Integer'
179         %r = $I0
180         END
182     optable['prefix:!'; 'inline'] = <<"        END"
183         ##  inline prefix:!
184         $I0 = isfalse %0
185         %r = new 'Integer'
186         %r = $I0
187         END
189     optable['prefix:?'; 'inline'] = <<"        END"
190         ##  inline prefix:?
191         $I0 = istrue %0
192         %r = new 'Integer'
193         %r = $I0
194         END
196     .return ()
197 .end
200 =back
202 =cut
204 # Local Variables:
205 #   mode: pir
206 #   fill-column: 100
207 # End:
208 # vim: expandtab shiftwidth=4 ft=pir: