aboutsummaryrefslogtreecommitdiff
path: root/src/interp/g-opt.boot
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2011-12-15 00:18:30 +0000
committerdos-reis <gdr@axiomatics.org>2011-12-15 00:18:30 +0000
commitb2d2dace94f9316206cd83ebde5606d9ce4ff31a (patch)
tree1797d3645f4f455eb178f0ffe4d560948926d449 /src/interp/g-opt.boot
parent838ceddb3d0ea500a4eee199b14638810e3a36f3 (diff)
downloadopen-axiom-b2d2dace94f9316206cd83ebde5606d9ce4ff31a.tar.gz
* interp/g-opt.boot (exitScope?): New.
(packWhen!): Use it. (coagulateWhenSeries): Tidy. (cancelScopeLeave!): Likewise.
Diffstat (limited to 'src/interp/g-opt.boot')
-rw-r--r--src/interp/g-opt.boot17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot
index 64dfbd9b..5aa43f69 100644
--- a/src/interp/g-opt.boot
+++ b/src/interp/g-opt.boot
@@ -285,10 +285,20 @@ coagulateWhenSeries(x,tag) ==
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]
+ [u for x in s.args while (u := h(x,tag) or leave nil)]
+ where h(x,tag) ==
+ x is [p,['%leave,=tag,y]] => [p,y]
+ x is [p,['%return,:.]] => x
+ nil
nil
nil
+++ Return true if the expression `x' exist the scope with tag `g'
+++ by normal local transfer or by exiting the enclosing function
+++ with a `return' statement.
+exitScope?(x,g) ==
+ x is ['%leave,=g,:.] or x is ['%return,:.]
+
++ Transform nested-to-tower.
packWhen! x == walkWith!(x,function f) where
f x ==
@@ -296,12 +306,14 @@ packWhen! x == walkWith!(x,function f) where
repeat
stmts = nil => leave nil
s := first stmts
- s is ['%when,[p,u:=['%leave,=g,.]],['%otherwise,v]] =>
+ 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]] =>
+ resetTo(x,f ['%when,[p,u],['%otherwise,f mkScope(g,v)]])
coagulateWhenSeries(y,g) is [u,v] =>
resetTo(x,f ['%when,:u,['%otherwise,f mkDefault(g,v)]])
x
@@ -323,6 +335,7 @@ 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 is ['%scope,g,u:=['%return,.,y]] => resetTo(x,u)
x
removeLeave! x == walkWith!(x,function f) where