Author: pmichaud
Date: Mon Aug 18 05:16:00 2008
New Revision: 30297
Modified:
trunk/compilers/pct/src/POST/Compiler.pir
Log:
[pct]: Correct order-of-sub generation for POST.
This update causes POST to generate Parrot subs in the
order in which they appear in the tree (previously sibling
subs would occur in reverse sequence in the output, which
could break :load/:init ordering).
Modified: trunk/compilers/pct/src/POST/Compiler.pir
==============================================================================
--- trunk/compilers/pct/src/POST/Compiler.pir (original)
+++ trunk/compilers/pct/src/POST/Compiler.pir Mon Aug 18 05:16:00 2008
@@ -18,11 +18,14 @@
.sub '__onload' :load :init
.local pmc p6meta, cproto
p6meta = new 'P6metaclass'
- cproto = p6meta.'new_class'('POST::Compiler',
'parent'=>'PCT::HLLCompiler', 'attr'=>'$!code')
+ cproto = p6meta.'new_class'('POST::Compiler', 'parent'=>'PCT::HLLCompiler')
cproto.'language'('POST')
$P1 = split ' ', 'pir evalpmc'
cproto.'stages'($P1)
+ $P0 = new 'ResizablePMCArray'
+ set_global '@!subcode', $P0
+
$P0 = new 'String'
set_global '$?NAMESPACE', $P0
.return ()
@@ -37,9 +40,10 @@
newself = new 'POST::Compiler'
## start with empty code
- .local pmc code
+ .local pmc subcode, code
+ subcode = get_global '@!subcode'
code = new 'CodeString'
- newself.'code'(code)
+ push subcode, code
## if the root node isn't a Sub, wrap it
$I0 = isa post, 'POST::Sub'
@@ -52,26 +56,8 @@
newself.'pir'(post)
## and return whatever code was generated
- .return newself.'code'()
-.end
-
-
-=item code([str])
-
-Get/set the code generated by this compiler.
-
-=cut
-
-.sub 'code' :method
- .param pmc code :optional
- .param int has_code :opt_flag
-
- if has_code goto set_code
- code = getattribute self, '$!code'
- .return (code)
- set_code:
- setattribute self, '$!code', code
- .return (code)
+ $P0 = pop subcode
+ .return ($P0)
.end
@@ -209,6 +195,11 @@
.sub 'pir' :method :multi(_, ['POST::Sub'])
.param pmc node
+ .local pmc subcode
+ subcode = get_global '@!subcode'
+ $P0 = new 'CodeString'
+ push subcode, $P0
+
.local pmc code
code = new 'CodeString'
@@ -242,16 +233,12 @@
unless outerpost goto pirflags_done
## FIXME: RT#47956
## PIR doesn't compile properly if :outer points to a sub
- ## with :init/:load flags on it.
+ ## with :init flags on it.
$I0 = index pirflags, ':init'
if $I0 >= 0 goto pirflags_done
- $I0 = index pirflags, ':load'
- if $I0 >= 0 goto pirflags_done
$S0 = outerpost.'pirflags'()
$I0 = index $S0, ':init'
if $I0 >= 0 goto pirflags_done
- $I0 = index $S0, ':load'
- if $I0 >= 0 goto pirflags_done
outername = outerpost.'lexid'()
$S0 = code.'escape'(outername)
pirflags = concat pirflags, ' :outer('
@@ -302,9 +289,10 @@
code.'emit'(".end\n\n")
subpir_done:
- $P0 = self.'code'()
+ $P0 = pop subcode
code .= $P0
- self.'code'(code)
+ $P0 = subcode[-1]
+ $P0 .= code
set_global '$?NAMESPACE', outerns
@@ -312,6 +300,7 @@
.return (code)
.end
+
.sub 'hll_pir' :method
.param pmc node
.param pmc options :slurpy :named