1 # Copyright (C) 2006-2008, The Perl Foundation.
6 src/lua51.pir -- The compiler for Lua 5.1
10 This compiler extends C<PCT::HLLCompiler>
11 (see F<compilers/pct/src/PCT/HLLCompiler.pir>)
13 This compiler defines the following stages:
17 =item * parse F<languages/lua/src/lua51.pg>
19 =item * PAST F<languages/lua/src/PASTGrammar.tg>
21 =item * POST F<languages/lua/src/POSTGrammar.tg>
25 Used by F<languages/lua/lua.pir>.
31 .sub '__onload' :anon :load :init
32 load_bytecode 'PCT.pbc'
33 load_bytecode 'PGE/Text.pbc'
35 new $P0, 'P6metaclass'
36 $P0.'new_class'('Lua::Compiler', 'parent'=>'PCT::HLLCompiler', 'attr'=>'$ostgrammar')
38 new $P0, 'Lua::Compiler'
40 $P0.'parsegrammar'('Lua::Grammar')
41 $P0.'astgrammar'('Lua::PAST::Grammar')
42 $P0.'ostgrammar'('Lua::POST::Grammar')
44 $P0.'commandline_prompt'('> ')
48 .namespace [ 'Lua::Compiler' ]
50 =head2 Overloaded methods
54 =item C<ostgrammar([string grammar])>
56 Accessor for the 'ostgrammar' attribute.
60 .sub 'ostgrammar' :method
61 .param string value :optional
62 .param int has_value :opt_flag
63 .return self.'attr'('$ostgrammar', value, has_value)
67 =item C<post(source [, adverbs :slurpy :named])>
69 Transform C<source> using the compiler's C<ostgrammar>
70 according to any options given by C<adverbs>, and return the
79 .param pmc adverbs :slurpy :named
80 .local string ostgrammar_name
81 .local pmc ostgrammar, ostbuilder
82 ostgrammar_name = self.'ostgrammar'()
83 unless ostgrammar_name goto default_ostgrammar
84 ostgrammar = new ostgrammar_name
85 ostbuilder = ostgrammar.'apply'(source)
86 .return ostbuilder.'get'('post')
90 .return $P0.'compile'(source, adverbs :flat :named)
94 .namespace [ 'Lua::PAST::Grammar' ]
100 =item C<internal_error>
102 used in F<languages/lua/src/PASTGrammar.tg>
108 $S0 = "ERROR_INTERNAL (PAST): " . msg
115 .namespace [ 'Lua::POST::Grammar' ]
117 =item C<internal_error>
119 used in F<languages/lua/src/POSTGrammar.tg>
125 $S0 = "ERROR_INTERNAL (POST): " . msg
132 .namespace [ 'POST::Node' ]
134 .sub 'has_call_in_last_op' :method
135 $I0 = isa self, 'POST::Ops'
141 $I0 = isa $P1, 'POST::Op'
144 unless $S0 == 'call' goto L1
151 .namespace [ 'Lua::POST::Sub' ]
153 .sub '__onload' :anon :load :init
154 new $P0, 'P6metaclass'
155 $P0.'new_class'('Lua::POST::Sub', 'parent'=>'POST::Sub')
158 .sub 'ops_const' :method
159 .param pmc value :optional
160 .param int has_value :opt_flag
161 .return self.'attr'('ops_const', value, has_value)
164 .sub 'ops_subr' :method
165 .param pmc value :optional
166 .param int has_value :opt_flag
167 .return self.'attr'('ops_subr', value, has_value)
170 .sub 'storage_const' :method
171 .param pmc value :optional
172 .param int has_value :opt_flag
173 .return self.'attr'('storage_const', value, has_value)
176 .sub 'storage_lex' :method
177 .param pmc value :optional
178 .param int has_value :opt_flag
179 .return self.'attr'('storage_lex', value, has_value)
183 .namespace [ 'Lua::POST::Chunk' ]
185 .sub '__onload' :anon :load :init
186 new $P0, 'P6metaclass'
187 $P0.'new_class'('Lua::POST::Chunk', 'parent'=>'Lua::POST::Sub')
190 .sub 'prologue' :method
191 .param pmc value :optional
192 .param int has_value :opt_flag
193 .return self.'attr'('prologue', value, has_value)
197 .namespace [ 'POST::Compiler' ]
199 .sub 'pir' :method :multi(_, ['Lua::POST::Chunk'])
202 code = self.'pir_children'(node)
203 $S0 = node.'prologue'()
205 new code, 'CodeString'
215 .namespace [ 'Lua::Symbtab' ]
217 .sub '__onload' :anon :load :init
218 $P0 = subclass 'ResizablePMCArray', 'Lua::Symbtab'
221 set_global '$nb', $P0
224 .sub 'insert' :method
227 $I0 = exists $P0[name]
230 $P1 = get_global '$nb'
239 .sub 'lookup' :method
242 new iter, 'Iterator', self
246 $I0 = exists $P0[name]
254 .sub 'push_scope' :method
257 $P1 = get_global '$nb'
261 .sub 'pop_scope' :method
265 .include 'languages/lua/src/grammar51.pir'
266 .include 'languages/lua/src/lua51_gen.pir'
267 .include 'languages/lua/src/PASTGrammar_gen.pir'
268 .include 'languages/lua/src/POSTGrammar_gen.pir'
274 Klaas-Jan Stol <parrotcode@gmail.com>
285 # vim: expandtab shiftwidth=4 ft=pir: