Skip to content

Commit

Permalink
[pct]: Add a "childorder" property to PAST::Node
Browse files Browse the repository at this point in the history
Allows child nodes to be evaluated in reverse sequence.

Originally 5d77384
Author:	pmichaud <pmichaud@pobox.com>
  • Loading branch information
Benabik committed Jun 13, 2011
1 parent c4d0cf0 commit 5587459
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
19 changes: 15 additions & 4 deletions compilers/pct/src/PAST/Compiler.pm
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand All @@ -412,25 +418,29 @@ 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, ')'
goto named_done
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
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions compilers/pct/src/PAST/Node.pm
Expand Up @@ -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<order> 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
Expand Down

0 comments on commit 5587459

Please sign in to comment.