aboutsummaryrefslogtreecommitdiff
path: root/src/interp/g-opt.boot
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2011-12-07 19:21:43 +0000
committerdos-reis <gdr@axiomatics.org>2011-12-07 19:21:43 +0000
commit1328fa0128ebf17c274b230eb724df195be8a915 (patch)
tree2a53dfa079ea5d5e6c1517a37b6804e8140e0b0f /src/interp/g-opt.boot
parent8ad29118c62e5c14c8ced03bf6337d4bc794f59c (diff)
downloadopen-axiom-1328fa0128ebf17c274b230eb724df195be8a915.tar.gz
* interp/g-opt.boot (removeSeq!): New.
(inlineLocals!): Likewise. (optimizeFunctionDef): Use them. (optSeq): Tidy. * interp/buildom.boot (seteltRecordFun): Tidy. * interp/clam.boot (compHash): Likewise.
Diffstat (limited to 'src/interp/g-opt.boot')
-rw-r--r--src/interp/g-opt.boot43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot
index 1bf11beb..05708d68 100644
--- a/src/interp/g-opt.boot
+++ b/src/interp/g-opt.boot
@@ -214,6 +214,44 @@ 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
+ f x ==
+ x is ['%seq,:.] =>
+ x.args := g x.args
+ x.args is [y] => resetTo(x,y)
+ x
+ x
+ g xs ==
+ xs = nil => nil
+ x := first xs
+ x is "/throwAway" => g rest xs -- skip garbages
+ x is ['%seq,:.] => -- splice sub-sequences
+ ys := g x.args =>
+ lastNode(ys).rest := g rest xs
+ ys
+ g rest xs -- skip empty statements
+ rest xs = nil => xs
+ xs.rest := g rest xs
+ xs
+
+inlineLocals! x == walkWith!(x,function f) where
+ f x ==
+ x is ['%bind,inits,:.] =>
+ kept := nil
+ while inits is [u,:inits] repeat
+ [y,z] := u
+ 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) =>
+ x.absBody := substitute!(z,y,x.absBody)
+ kept := [u,:kept]
+ kept = nil => resetTo(x,x.absBody)
+ x.absParms := reverse! kept
+ x
+ x
+
optimizeFunctionDef(def) ==
if $reportOptimization then
sayBrightlyI bright '"Original LISP code:"
@@ -221,7 +259,8 @@ optimizeFunctionDef(def) ==
expr := copyTree second def
changeVariableDefinitionToStore(expr.absBody,expr.absParms)
- expr := simplifyVMForm reduceXLAM! groupTranscients! expr
+ expr := simplifyVMForm removeSeq! inlineLocals!
+ groupTranscients! reduceXLAM! expr
if $reportOptimization then
sayBrightlyI bright '"Intermediate VM code:"
@@ -481,8 +520,6 @@ optSeq ['%seq,:l] ==
null l => nil
l is [["%LET",g,x],:r] and replaceableTemporary?(g,r) =>
getRidOfTemps substitute(x,g,r)
- first l is "/throwAway" => getRidOfTemps rest l
- --this gets rid of unwanted labels generated by declarations in %seq
[first l,:getRidOfTemps rest l]
seqToCOND l ==
transform:= [[a,b] for x in l while (x is ['%when,[a,['%exit,b]]])]