5 POST - Parrot opcode syntax tree
9 This file implements the various opcode syntax tree nodes
10 for compiling programs in Parrot.
16 .sub '__onload' :load :init
17 .local pmc p6meta, base
19 ## create POST classes
20 p6meta = new 'P6metaclass'
21 base = p6meta.'new_class'('POST::Node', 'parent'=>'PCT::Node')
22 p6meta.'new_class'('POST::Op', 'parent'=>base)
23 p6meta.'new_class'('POST::Ops', 'parent'=>base)
24 p6meta.'new_class'('POST::Label', 'parent'=>base)
25 p6meta.'new_class'('POST::Sub', 'parent'=>base)
27 $P0 = new 'ResizableStringArray'
28 $P0[0] = " .param pmc %0\n"
29 $P0[1] = " .param pmc %0 :optional\n .param int has_%0 :opt_flag\n"
30 $P0[2] = " .param pmc %0 :slurpy\n"
31 $P0[4] = " .param pmc %0 :named(%1)\n"
32 $P0[5] = " .param pmc %0 :optional :named(%1)\n .param int has_%0 :opt_flag\n"
33 $P0[6] = " .param pmc %0 :slurpy :named\n"
34 $P0[8] = " .param pmc %0 :call_sig\n"
35 set_hll_global ['POST';'Sub'], '%!paramfmt', $P0
40 =head1 POST Node types
44 C<POST::Node> is the base class for all POST nodes. It's derived from class
45 C<PCT::Node> (see F<compilers/pct/src/PCT/Node.pir>).
51 .namespace [ 'POST';'Node' ]
55 Get or set the result value of this node. If the result value
56 is set to another POST node, then that node's result is used
57 as the result of the current node.
62 .param pmc value :optional
63 .param int has_value :opt_flag
65 if has_value == 1 goto set_value
66 value = self['result']
67 if null value goto result_null
68 $I0 = isa value, ['POST';'Node']
69 if $I0 goto result_node
72 .tailcall value.'result'()
76 self['result'] = value
83 Returns the result of the current node as a string.
87 .sub 'get_string' :vtable :method
93 =item push_pirop(pirop [,arglist :slurpy] [,adverbs :slurpy :named])
95 Shortcut for creating and adding a new POST::Op node with opcode
96 C<pirop> and any supplied arguments or options. Returns the
101 .sub 'push_pirop' :method
103 .param pmc arglist :slurpy
104 .param pmc adverbs :slurpy :named
105 adverbs['pirop'] = pirop
106 $P0 = get_hll_global ['POST'], 'Op'
107 $P1 = $P0.'new'(arglist :flat, adverbs :flat :named)
115 Return C<str> as a PIR constant string. (Deprecated in favor of
116 C<POST::Compiler.escape>.)
120 .sub 'escape' :method
122 $P0 = get_hll_global ['PAST'], 'Compiler'
123 str = $P0.'escape'(str)
131 C<POST::Op> nodes represents any PIR opcodes.
135 =item pirop([opcode])
137 Get/set the opcode type for this node.
141 .namespace [ 'POST';'Op' ]
144 .param pmc value :optional
145 .param int has_value :opt_flag
146 .tailcall self.'attr'('pirop', value, has_value)
149 .sub 'inline' :method
150 .param pmc value :optional
151 .param int has_value :opt_flag
152 .tailcall self.'attr'('inline', value, has_value)
156 .namespace [ 'POST';'Label' ]
158 .sub 'result' :method
159 .param pmc value :optional
160 .param int has_value :opt_flag
161 if has_value goto set_value
162 value = self['result']
163 unless null value goto end
166 value = self.'unique'(name)
168 self['result'] = value
174 .namespace [ 'POST';'Sub' ]
176 .sub 'blocktype' :method
177 .param pmc value :optional
178 .param int has_value :opt_flag
179 .tailcall self.'attr'('blocktype', value, has_value)
183 .sub 'namespace' :method
184 .param pmc value :optional
185 .param int has_value :opt_flag
186 .tailcall self.'attr'('namespace', value, has_value)
191 .param pmc value :optional
192 .param int has_value :opt_flag
193 .tailcall self.'attr'('hll', value, has_value)
198 .param pmc value :optional
199 .param int has_value :opt_flag
200 .tailcall self.'attr'('outer', value, has_value)
204 .param pmc value :optional
205 .param int has_value :opt_flag
206 .tailcall self.'attr'('multi', value, has_value)
211 .param pmc value :optional
212 .param int has_value :opt_flag
213 if has_value goto getset_value
214 $I0 = exists self['subid']
215 if $I0 goto getset_value
216 value = self.'unique'('post')
219 .tailcall self.'attr'('subid', value, has_value)
223 .sub 'pirflags' :method
224 .param pmc value :optional
225 .param int has_value :opt_flag
226 .tailcall self.'attr'('pirflags', value, has_value)
230 .sub 'compiler' :method
231 .param pmc value :optional
232 .param int has_value :opt_flag
233 .tailcall self.'attr'('compiler', value, has_value)
237 .sub 'compiler_args' :method
238 .param pmc value :optional
239 .param int has_value :opt_flag
240 .tailcall self.'attr'('compiler_args', value, has_value)
244 .sub 'add_param' :method
246 .param pmc adverbs :slurpy :named
248 .local int optional, slurpy, call_sig
250 optional = adverbs['optional']
251 slurpy = adverbs['slurpy']
252 named = adverbs['named']
253 call_sig = adverbs['call_sig']
256 paramseq = isne optional, 0
257 unless slurpy goto slurpy_done
260 unless named goto named_done
263 unless call_sig goto call_sig_done
268 paramlist = self['paramlist']
269 unless null paramlist goto have_paramlist
270 paramlist = new 'ResizablePMCArray'
271 self['paramlist'] = paramlist
275 code = paramlist[paramseq]
276 unless null code goto have_code
277 code = new 'StringBuilder'
278 paramlist[paramseq] = code
282 paramfmt = get_hll_global ['POST';'Sub'], '%!paramfmt'
283 $S0 = paramfmt[paramseq]
284 named = self.'escape'(named)
285 code.'append_format'($S0, pname, named)
291 .sub 'add_directive' :method
294 dlist = self['directives']
295 $I0 = index dlist, line
296 unless $I0 < 0 goto done
297 dlist = concat dlist, line
298 dlist = concat dlist, "\n"
299 self['directives'] = dlist
309 Patrick Michaud <pmichaud@pobox.com> is the author and maintainer.
310 Please send patches and suggestions to the Parrot porters or
311 Perl 6 compilers mailing lists.
315 2007-11-21 Significant refactor as part of Parrot Compiler Toolkit
319 Copyright (C) 2006-2008, Parrot Foundation.
327 # vim: expandtab shiftwidth=4 ft=pir: