aboutsummaryrefslogtreecommitdiff
path: root/src/interp/g-opt.boot
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2011-12-13 12:24:26 +0000
committerdos-reis <gdr@axiomatics.org>2011-12-13 12:24:26 +0000
commitbf49bd60354641b393c53e10b40862199fd31151 (patch)
tree7978cb5b60d70931bdbca5eb49387d83931ef72b /src/interp/g-opt.boot
parent2b67e7c6078a1fe400bcac82fd5b071cee643f8f (diff)
downloadopen-axiom-bf49bd60354641b393c53e10b40862199fd31151.tar.gz
* interp/g-opt.boot (removeJunk!): Rename from removeSeq!
(cancelScopeLeave!): New. (inlineLocals!): Tidy. (optimize!): Run cancelScopeLeave! right after removeJunk!.
Diffstat (limited to 'src/interp/g-opt.boot')
-rw-r--r--src/interp/g-opt.boot25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot
index 20b1b962..851e7eb6 100644
--- a/src/interp/g-opt.boot
+++ b/src/interp/g-opt.boot
@@ -214,9 +214,12 @@ reduceXLAM! x == walkWith!(x,function f) where
resetTo(x,doInlineCall(args,y.absParms,copyTree y.absBody))
x
-++ Splice in all %seq subforms, remove throw away expressions,
-++ and remove unnecessary %seq boxes around singleton expressions.
-removeSeq! x == walkWith!(x,function f) where
+++ Remove throw-away expressions, inline one-time temporaries
+++ abstracting conditionals (generated by the parser) and remove
+++ unnecessary %seq boxes around singleton expressions.
+++ NOTES: this transformation must be run before any grouping
+++ of intermediate result bindings.
+removeJunk! x == walkWith!(x,function f) where
f x ==
x is ['%seq,:.] =>
x.args := g x.args
@@ -227,6 +230,8 @@ removeSeq! x == walkWith!(x,function f) where
xs = nil => nil
x := first xs
x is "/throwAway" => g rest xs -- skip garbages
+ x is ['%LET,y,u] and gensym? y and numOfOccurencesOf(y,rest xs) = 1 =>
+ g substitute!(u,y,rest xs)
x is ['%seq,:.] => -- splice sub-sequences
ys := x.args =>
lastNode(ys).rest := rest xs
@@ -239,12 +244,12 @@ removeSeq! x == walkWith!(x,function f) where
inlineLocals! x == walkWith!(x,function f) where
f x ==
- x is ['%bind,[[y,a]],z] and gensym? y and numOfOccurencesOf(y,z) = 1 =>
- resetTo(x,f substitute!(a,y,z))
x is ['%bind,inits,:.] =>
kept := nil
while inits is [u,:inits] repeat
[y,z] := u
+ gensym? y and numOfOccurencesOf(y,x.absBody) = 1 =>
+ x.absBody := substitute!(z,y,x.absBody)
usedSymbol?(y,z) or usedSymbol?(y,inits) => kept := [u,:kept]
or/[usedSymbol?(v,z) for [v,.] in kept] => kept := [u,:kept]
canInlineVarDefinition(y,z,x.absBody) =>
@@ -314,6 +319,14 @@ spliceSeq! x == walkWith!(x,function f) where
x.args := spliceSeqArgs x.args
x
+++ Remove superfluous cancel/scope pairs exposed by running
+++ removeJunk!.
+cancelScopeLeave! x == walkWith!(x,function f) where
+ f x ==
+ x is ['%scope,g,['%leave,=g,y]] and hasNoLeave?(y,g) =>
+ resetTo(x,f y)
+ x
+
++ Transform an intermediate form (output of the elaborator) to
++ a lower intermediate form, applying several transformations
++ generaly intended to improve quality and efficiency.
@@ -321,7 +334,7 @@ optimize! x ==
x := spliceSeq! packWhen! transformIF! x
changeVariableDefinitionToStore(x,nil)
simplifyVMForm spliceSeq! packWhen! inlineLocals!
- groupTranscients! removeSeq! reduceXLAM! x
+ groupTranscients! cancelScopeLeave! removeJunk! reduceXLAM! x
++ A non-mutating version of `optimize!'.
optimize x ==