From 5587459a9aa8dd595273fca61c64ccaf149dae94 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Mon, 13 Jun 2011 11:08:39 -0400 Subject: [PATCH] [pct]: Add a "childorder" property to PAST::Node Allows child nodes to be evaluated in reverse sequence. Originally 5d77384daf090fd361e913abc5e07b7e70426bd1 Author: pmichaud --- compilers/pct/src/PAST/Compiler.pm | 19 +++++++++++++++---- compilers/pct/src/PAST/Node.pm | 10 ++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/compilers/pct/src/PAST/Compiler.pm b/compilers/pct/src/PAST/Compiler.pm index 7b691eb05b..5bf30ba638 100644 --- a/compilers/pct/src/PAST/Compiler.pm +++ b/compilers/pct/src/PAST/Compiler.pm @@ -368,6 +368,13 @@ method post_children($node, *%options) { $P0 = get_hll_global ['POST'], 'Ops' ops = $P0.'new'('node'=>node) + .local string pushop + pushop = 'push' + $S0 = node.'childorder'() + if $S0 != 'right' goto have_pushop + pushop = 'unshift' + have_pushop: + ## get any conversion types .local string signature signature = options['signature'] @@ -400,7 +407,6 @@ method post_children($node, *%options) { cpast = shift iter cpost = self.'as_post'(cpast, 'rtype'=>rtype) cpost = self.'coerce'(cpost, rtype) - ops.'push'(cpost) $I0 = isa cpast, ['PAST';'Node'] unless $I0 goto cpost_pos .local pmc isflat @@ -412,8 +418,9 @@ method post_children($node, *%options) { $S0 = cpost if isflat goto flat_named npost = self.'as_post'(npast, 'rtype'=>'~') + cpost = ops.'new'(cpost) + cpost.'push'(npost) $S1 = npost - ops.'push'(npost) $S0 = concat $S0, ' :named(' $S0 = concat $S0, $S1 $S0 = concat $S0, ')' @@ -421,16 +428,19 @@ method post_children($node, *%options) { flat_named: $S0 = concat $S0, ' :named :flat' named_done: + ops.pushop(cpost) push namedargs, $S0 goto iter_rtype iter_pos: if isflat goto flat_pos cpost_pos: + ops.pushop(cpost) push posargs, cpost goto iter_rtype flat_pos: $S0 = cpost $S0 = concat $S0, ' :flat' + ops.pushop(cpost) push posargs, $S0 iter_rtype: unless sigidx < sigmax goto iter_loop @@ -452,14 +462,15 @@ method post_children($node, *%options) { rtype = substr signature, sigidx, 1 kpost = self.'as_post'(kpast, 'rtype'=>rtype) kpost = self.'coerce'(kpost, rtype) - ops.'push'(kpost) - ops.'push'(cpost) # now construct the keyed PMC $S0 = cpost $S0 = concat $S0, '[' $S1 = kpost $S0 = concat $S0, $S1 $S0 = concat $S0, ']' + kpost = ops.'new'(kpost) + kpost.'push'(cpost) + ops.pushop(kpost) push posargs, $S0 goto iter_rtype iter_end: diff --git a/compilers/pct/src/PAST/Node.pm b/compilers/pct/src/PAST/Node.pm index 9d551c0d51..5db932bb30 100644 --- a/compilers/pct/src/PAST/Node.pm +++ b/compilers/pct/src/PAST/Node.pm @@ -70,6 +70,16 @@ method lvalue($value?) { self.attr('lvalue', $value, pir::defined($value)); } +=item childorder([order]) +Get/set the order in which children nodes should be evaluated +(via Compiler::post_children). If C is 'right' then +children are evaluated last-to-first, otherwise they're +evaluated first-to-last. + +method childorder($value?) { + self.attr('childorder', $value, pir::defined($value)); +} + =begin head1 AUTHOR