aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2011-12-10 07:18:59 +0000
committerdos-reis <gdr@axiomatics.org>2011-12-10 07:18:59 +0000
commit1bee5e2ddcac5cd3a168f5f70a754fd8bee34021 (patch)
tree3a6d385afa6f92a5531fe9a23083da00097de2e4 /src
parentbea6fd10ab4671135cd7961e7eca5d6334a7131f (diff)
downloadopen-axiom-1bee5e2ddcac5cd3a168f5f70a754fd8bee34021.tar.gz
* interp/g-opt.boot (mkDefault): New.
(coagulateWhenSeries): Likewise. (packWhen!): Likewise. Use them. (optimize!): Call it. Tidy.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/interp/g-opt.boot28
2 files changed, 32 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 382baf88..70f23a99 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2011-12-10 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
+ * interp/g-opt.boot (mkDefault): New.
+ (coagulateWhenSeries): Likewise.
+ (packWhen!): Likewise. Use them.
+ (optimize!): Call it. Tidy.
+
2011-12-09 Gabriel Dos Reis <gdr@cs.tamu.edu>
* interp/lisp-backend.boot (loopVarInit): Generate VM forms, not Lisp.
diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot
index 9b09860a..1ba56076 100644
--- a/src/interp/g-opt.boot
+++ b/src/interp/g-opt.boot
@@ -263,6 +263,27 @@ transformIF! x == walkWith!(x,function f) where
resetTo(x,['%when,[p,s1],['%otherwise,s2]])
x
+++ Subroutine of packWhen!
+mkDefault(g,l) ==
+ l = nil => ['CONDERR]
+ mkScope(g,mkSeq l)
+
+coagulateWhenSeries(x,tag) ==
+ x is ['%seq,:.] => f(x.args,tag) where
+ f(l,tag) ==
+ cl := nil
+ while l is [s,:.] and (cl' := g(s,tag)) repeat
+ cl := [:cl,:cl']
+ l := rest l
+ cl = nil => nil
+ [cl,l]
+ g(s,tag) ==
+ -- return list of reduced clauses if they all exit from same scope.
+ s is ['%when,:.] =>
+ [[p,y] for x in s.args while x is [p,['%leave,=tag,y]] or leave nil]
+ nil
+ nil
+
++ Transform nested-to-tower.
packWhen! x == walkWith!(x,function f) where
f x ==
@@ -270,9 +291,10 @@ packWhen! x == walkWith!(x,function f) where
resetTo(x,f ['%when,[['%and,p1,p2],s]])
x is ['%when,:cl,['%otherwise,y]] and y is ['%when,:.] =>
resetTo(x,f ['%when,:cl,:y.args])
- x is ['%scope,g,['%seq,['%when,[p,['%leave,=g,y]]],['%leave,=g,z]]]
- and hasNoLeave?(p,g) =>
- resetTo(x,f ['%when,[p,y],['%otherwise,mkScope(g,z)]])
+ x is ['%scope,g,['%seq,['%when,[p,['%leave,=g,y]]],['%leave,=g,z]]] =>
+ resetTo(x,f ['%when,[p,y],['%otherwise,f mkScope(g,z)]])
+ x is ['%scope,g,y] and coagulateWhenSeries(y,g) is [u,v] =>
+ resetTo(x,f ['%when,:u,['%otherwise,f mkDefault(g,v)]])
x
++ Transform an intermediate form (output of the elaborator) to