3 POST - Parrot opcode syntax tree
7 This file implements the various opcode syntax tree nodes
8 for compiling programs in Parrot.
14 .sub '__onload' :load :init
15 .local pmc p6meta, base
17 ## create POST classes
18 p6meta = new 'P6metaclass'
19 base = p6meta.'new_class'('POST::Node', 'parent'=>'PCT::Node')
20 p6meta.'new_class'('POST::Op', 'parent'=>base)
21 p6meta.'new_class'('POST::Ops', 'parent'=>base)
22 p6meta.'new_class'('POST::Label', 'parent'=>base)
23 p6meta.'new_class'('POST::Sub', 'parent'=>base)
25 $P0 = new 'ResizableStringArray'
26 $P0[0] = " .param pmc %0"
27 $P0[1] = " .param pmc %0 :optional\n .param int has_%0 :opt_flag"
28 $P0[2] = " .param pmc %0 :slurpy"
29 $P0[4] = " .param pmc %0 :named(%1)"
30 $P0[5] = " .param pmc %0 :optional :named(%1)\n .param int has_%0 :opt_flag"
31 $P0[6] = " .param pmc %0 :slurpy :named"
32 set_hll_global ['POST::Sub'], '%!paramfmt', $P0
37 =head1 POST Node types
41 C<POST::Node> is the base class for all POST nodes. It's derived from class
42 C<PCT::Node> (see F<compilers/pct/src/PCT/Node.pir>).
52 .namespace [ 'POST::Node' ]
56 Get or set the result value of this node. If the result value
57 is set to another POST node, then that node's result is used
58 as the result of the current node.
63 .param pmc value :optional
64 .param int has_value :opt_flag
66 if has_value == 1 goto set_value
67 value = self['result']
68 if null value goto result_null
69 $I0 = isa value, 'POST::Node'
70 if $I0 goto result_node
73 .return value.'result'()
77 self['result'] = value
82 =item get_string() # vtable method
84 Returns the result of the current node as a string.
88 .sub 'get_string' :vtable :method
94 =item push_pirop(pirop [,arglist :slurpy] [,adverbs :slurpy :named])
96 Shortcut for creating and adding a new POST::Op node with opcode
97 C<pirop> and any supplied arguments or options. Returns the
102 .sub 'push_pirop' :method
104 .param pmc arglist :slurpy
105 .param pmc adverbs :slurpy :named
106 adverbs['pirop'] = pirop
107 $P0 = get_hll_global ['POST'], 'Op'
108 $P1 = $P0.'new'(arglist :flat, adverbs :flat :named)
116 Return C<str> as a PIR constant string.
120 .sub 'escape' :method
122 $P0 = new 'CodeString'
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 .return self.'attr'('pirop', value, has_value)
149 .sub 'inline' :method
150 .param pmc value :optional
151 .param int has_value :opt_flag
152 .return 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 .return self.'attr'('blocktype', value, has_value)
183 .sub 'namespace' :method
184 .param pmc value :optional
185 .param int has_value :opt_flag
186 .return self.'attr'('namespace', value, has_value)
191 .param pmc value :optional
192 .param int has_value :opt_flag
193 .return self.'attr'('outer', value, has_value)
198 .param pmc value :optional
199 .param int has_value :opt_flag
200 .return self.'attr'('lexid', value, has_value)
204 .sub 'pirflags' :method
205 .param pmc value :optional
206 .param int has_value :opt_flag
207 .return self.'attr'('pirflags', value, has_value)
211 .sub 'compiler' :method
212 .param pmc value :optional
213 .param int has_value :opt_flag
214 .return self.'attr'('compiler', value, has_value)
218 .sub 'compiler_args' :method
219 .param pmc value :optional
220 .param int has_value :opt_flag
221 .return self.'attr'('compiler_args', value, has_value)
225 .sub 'add_param' :method
227 .param pmc adverbs :slurpy :named
229 .local int optional, slurpy
231 optional = adverbs['optional']
232 slurpy = adverbs['slurpy']
233 named = adverbs['named']
236 paramseq = isne optional, 0
237 unless slurpy goto slurpy_done
240 unless named goto named_done
245 paramlist = self['paramlist']
246 unless null paramlist goto have_paramlist
247 paramlist = new 'ResizablePMCArray'
248 self['paramlist'] = paramlist
252 code = paramlist[paramseq]
253 unless null code goto have_code
254 code = new 'CodeString'
255 paramlist[paramseq] = code
259 paramfmt = get_hll_global ['POST::Sub'], '%!paramfmt'
260 $S0 = paramfmt[paramseq]
261 named = code.'escape'(named)
262 code.'emit'($S0, pname, named)
271 Patrick Michaud <pmichaud@pobox.com> is the author and maintainer.
272 Please send patches and suggestions to the Parrot porters or
273 Perl 6 compilers mailing lists.
277 2007-11-21 Significant refactor as part of Parrot Compiler Toolkit
281 Copyright (C) 2006-2008, The Perl Foundation.
289 # vim: expandtab shiftwidth=4 ft=pir: