1 grammar TclExpr::PIR::Grammar is TGE::Grammar;
3 transform result (ROOT) {
5 .return tree.get('pir', node, $S0)
8 transform pir (PAST::Expr) {
10 pir = new 'CodeString'
14 $P0 = tree.get('pir', value)
21 label = pir.unique('expr_is_string')
23 pir.emit(<<'END_PIR', ret, label)
25 toNumber = get_root_global ['_tcl'], 'toNumber'
35 transform pir (PAST::Program) {
37 pir = new 'CodeString'
40 .local pmc colons, split, epoch
41 colons = get_root_global ['_tcl'], 'colons'
42 split = get_root_global ['parrot'; 'PGE::Util'], 'split'
43 epoch = get_root_global ['_tcl'], 'epoch'
46 .local pmc iter, child
47 iter = node.'child_iter'()
51 $P0 = tree.'get'('pir', child)
61 transform pir (PAST::Val) {
66 pir = new 'CodeString'
67 ret = pir.unique('$P')
69 pir.emit(" %0 = new '%1'", ret, class)
71 if class == "TclFloat" goto assign_float
72 if class == "TclString" goto assign_string
75 $I0 = index $S0, '.' # RT#40690: '.' hack due to
76 if $I0 >= 0 goto assign_val # parrotbug #38896
78 if $I0 >= 0 goto assign_val
80 if $I0 >= 0 goto assign_val
86 pir.emit(' assign %0, %1', ret, $S0)
93 transform pir (PAST::Var) {
95 pir = new 'CodeString'
96 ret = pir.unique('$P')
103 $I0 = exists node['index']
106 pir.emit(<<'END_PIR', ret, name)
108 readVar = get_root_global ['_tcl'], 'readVar'
115 index = node['index']
117 $P0 = tree.get('pir', index)
120 pir.emit(<<'END_PIR', ret, name, $S0)
122 readVar = get_root_global ['_tcl'], 'readVar'
131 transform pir (PAST::Op) {
132 .local pmc args,iter,pir
133 .local pmc return_register
135 pir = new 'CodeString'
137 iter = node.'child_iter'()
139 unless iter goto iter_done
141 $P0 = tree.get('pir', $P1)
142 return_register = $P1['ret']
143 push args, return_register
149 retval = pir.unique('$P')
151 pir .= " = get_hll_global '"
159 $S0 = join ", ", args
166 transform pir (PAST::MathFunc) {
167 .local pmc args,iter,pir
168 .local pmc return_register
170 pir = new 'CodeString'
172 iter = node.'child_iter'()
174 unless iter goto iter_done
176 $P0 = tree.get('pir', $P1)
177 return_register = $P1['ret']
178 push args, return_register
184 retval = pir.unique('$P')
185 $S0 = node['mathfunc']
186 pir.emit("%0 = get_hll_global ['tcl'; 'mathfunc'], '&%1'", retval, $S0)
191 $S0 = join ", ", args
198 transform pir (PAST::StaticCommand) {
199 .local pmc args, children, iter, pir
202 pir = new 'CodeString'
204 children = node.'get_children'()
205 iter = new 'Iterator', children
212 unless iter goto iter_done
214 $P0 = tree.get('pir', $P1)
219 if $S0 == 'PAST::Expand' goto iter_loop
220 unless $S0 == 'PAST::Var' goto iter_loop
221 pir.emit(" %0 = clone %0", reg)
225 retval = pir.unique('$P')
227 .local string invalid_, done_, exec_
228 invalid_ = pir.unique('invalid_')
229 done_ = pir.unique('done_')
230 exec_ = pir.unique('exec_')
237 $S0 = join ", ", args
238 $I0 = index name, "::"
239 if $I0 == -1 goto no_ns
241 .local pmc split, colons
242 split = get_root_global ['parrot'; 'PGE::Util'], 'split'
243 colons = get_root_global ['_tcl'], 'colons'
244 $P0 = split(colons, name)
248 $S1 = pir.escape($S1)
251 if $S2 == "" goto root_ns
253 ns = join "'; '", $P0
258 root_ = pir.unique('root_')
259 pir.emit(<<'END_PIR', retval, ns, $S1, root_, exec_)
260 %0 = get_global %1 %2
270 if $I0 == 0 goto root_ns_emit
272 ns = join "'; '", $P0
277 pir.emit(<<'END_PIR', retval, ns, $S1, invalid_, exec_)
278 %0 = get_hll_global %1 %2
286 $S1 = pir.escape($S1)
287 pir.emit(<<'END_PIR', retval, $S1, invalid_)
293 $S3 = pir.escape(name)
294 pir.emit(<<'END_PIR', retval, $S3, $S0, invalid_, done_)
298 die 'invalid command name %1'
305 transform pir (PAST::DynamicCommand) {
306 .local pmc args, children, iter, pir, reg
308 pir = new 'CodeString'
310 children = node.'get_children'()
311 iter = new 'Iterator', children
313 unless iter goto iter_done
315 $P0 = tree.get('pir', $P1)
319 pir.emit("%0 = clone %0", reg)
322 .local pmc retval, name
323 retval = pir.unique('$P')
326 $S1 = pir.unique('invalid_')
327 $S2 = pir.unique('done_')
331 $S0 = join ", ", args
332 $S4 = pir.unique('curr_namespace')
333 $S5 = pir.unique('root_namespace')
334 pir.emit(<<'END_PIR', retval, name, $S0, $S1, $S2, $S4, $S5)
336 $P0 = split(colons, $S0)
346 %0 = get_hll_namespace $P0
354 %0 = get_namespace $P0
358 if null %0 goto %6 # try the root namespace if it's not in the current
362 die 'invalid command name %1'
369 transform pir (PAST::Expand) {
370 .local pmc pir, value
371 pir = new 'CodeString'
372 value = node['value']
374 $S0 = tree.get('pir', value)
378 $S1 = pir.'unique'('$P')
379 $S2 = pir.'unique'('loop_')
380 $S3 = pir.'unique'('end_')
381 pir.emit(<<'END_PIR', $S0)
383 toList = get_root_global ['_tcl'], 'toList'
392 transform pir (PAST::Cond) {
393 .local pmc args, pir, ret, label
394 .local pmc children, cond, then, else
395 .local string cond_result, then_result, else_result
397 pir = new 'CodeString'
398 pir.emit(' .local pmc toBoolean')
399 pir.emit(' toBoolean = get_root_global ["_tcl"], "toBoolean"')
401 # This node has 3 children. generate PIR so that:
402 # if node1 then node2 else node3
404 # pick a unique register to store our result in.
405 ret = pir.unique('$P')
407 # pick a unique number for our labels..
408 label = pir.unique('label_')
410 children = node.'get_children'()
413 $S0 = tree.get('pir', cond)
415 cond_result = cond['ret']
417 pir.emit(" %0 = toBoolean(%0)", cond_result)
418 pir.emit(" unless %0 goto else_%1", cond_result, label)
421 $S0 = tree.get('pir', then)
423 then_result = then['ret']
425 pir.emit(' %0 = %1', ret, then_result)
426 pir.emit(" goto end_if_%0", label)
428 #set the result register to the answer from this section
430 #then jump to custom end label..
432 pir.emit(" else_%0:",label)
435 $S0 = tree.get('pir', else)
437 else_result = else['ret']
439 pir.emit(' %0 = %1', ret, else_result)
441 #set the result register to the answer from this section
443 pir.emit(" end_if_%0:",label)