aboutsummaryrefslogtreecommitdiff
path: root/src/interp/g-opt.boot
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2011-12-18 20:11:04 +0000
committerdos-reis <gdr@axiomatics.org>2011-12-18 20:11:04 +0000
commitd6ff41eb503996363dd676485e138a2f322de601 (patch)
tree82d1ce6d046f9b39aa1e31ef6c096d4c287b609b /src/interp/g-opt.boot
parentd286893196d08cbe61ff2c80f470d8c0a7f606cf (diff)
downloadopen-axiom-d6ff41eb503996363dd676485e138a2f322de601.tar.gz
* interp/g-opt.boot (unnestWhen!): New.
(packWhen!): Simplify. (optimize!): Run before changeVariableDefinitionToStore.
Diffstat (limited to 'src/interp/g-opt.boot')
-rw-r--r--src/interp/g-opt.boot31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot
index 75d358da..089e2718 100644
--- a/src/interp/g-opt.boot
+++ b/src/interp/g-opt.boot
@@ -299,6 +299,28 @@ coagulateWhenSeries(x,tag) ==
exitScope?(x,g) ==
x is ['%leave,=g,:.] or x is ['%return,:.]
+unnestWhen! x == f x where
+ f x ==
+ x is ['%scope,tag,y] =>
+ y is ['%seq,:stmts] =>
+ repeat
+ stmts = nil => leave nil
+ s := f first stmts
+ s is ['%when,[p,u],['%otherwise,v]] and exitScope?(u,tag) =>
+ stmts.first := ['%when,[p,u]]
+ stmts.rest := spliceSeqArgs [f v,:rest stmts]
+ stmts.first := s
+ stmts := rest stmts
+ x
+ y is ['%when,[p,u:=['%leave,=tag,.]],['%otherwise,v]] =>
+ reset(x,f mkScope(tag,mkSeq [['%when,[p,u]],f v]))
+ second(x.args) := f y
+ x
+ do
+ abstraction? x => x.absBody := f x.absBody
+ x is ['%leave,.,y] => second(x.args) := f y
+ x
+
++ Transform nested-to-tower.
packWhen! x == walkWith!(x,function f) where
f x ==
@@ -309,13 +331,6 @@ packWhen! x == walkWith!(x,function f) where
x is ['%leave,g,['%when,[p,['%leave,=g,s]]]] =>
resetTo(x,['%leave,g,['%when,[p,s]]])
x is ['%scope,g,y] and y is ['%seq,:stmts] =>
- repeat
- stmts = nil => leave nil
- s := first stmts
- s is ['%when,[p,u],['%otherwise,v]] and exitScope?(u,g) =>
- stmts.first := ['%when,[p,u]]
- stmts.rest := [v,:rest stmts]
- stmts := rest stmts
y.args is [['%when,[p,['%leave,=g,u]]],['%leave,=g,v]] =>
resetTo(x,f ['%when,[p,u],['%otherwise,f mkScope(g,v)]])
y.args is [['%when,[p,u:=['%return,:.]]],['%leave,=g,v]] =>
@@ -382,7 +397,7 @@ removeScope! x == prefixWalk!(x,function f) where
++ a lower intermediate form, applying several transformations
++ generaly intended to improve quality and efficiency.
optimize! x ==
- x := spliceSeq! packWhen! transformIF! removeLeave! cleanLoop! x
+ x := unnestWhen! spliceSeq! packWhen! transformIF! removeLeave! cleanLoop! x
changeVariableDefinitionToStore(x,nil)
simplifyVMForm removeScope! cancelScopeLeave! spliceSeq! packWhen!
inlineLocals! groupTranscients! cancelScopeLeave!