From c19e54f03e3230811e6c86998568ce63ccbc42c9 Mon Sep 17 00:00:00 2001
From: dos-reis <gdr@axiomatics.org>
Date: Sat, 24 Jul 2010 01:50:09 +0000
Subject: 	* interp/compiler.boot (compMatchAlternative): Don't generate 
 LET-expressions. 	* interp/g-opt.boot (optBind): Tidy.

---
 src/ChangeLog               |  6 ++++++
 src/boot/strap/tokens.clisp |  1 +
 src/boot/tokens.boot        |  3 ++-
 src/interp/compiler.boot    |  3 +--
 src/interp/g-opt.boot       | 16 ++++++++++++----
 5 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index de27a6a5..832d9d5a 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2010-07-23  Gabriel Dos Reis  <gdr@cs.tamu.edu>
+
+	* interp/compiler.boot (compMatchAlternative): Don't generate
+	LET-expressions. 
+	* interp/g-opt.boot (optBind): Tidy.
+
 2010-07-23  Gabriel Dos Reis  <gdr@cs.tamu.edu>
 
 	* interp/g-opt.boot (optBind): Check for dependencies in
diff --git a/src/boot/strap/tokens.clisp b/src/boot/strap/tokens.clisp
index 5b02904d..94923a97 100644
--- a/src/boot/strap/tokens.clisp
+++ b/src/boot/strap/tokens.clisp
@@ -229,6 +229,7 @@
                   (LIST '|setPart| 'SETELT) (LIST '|setUnion| 'UNION)
                   (LIST '|strconc| 'CONCAT) (LIST '|string?| 'STRINGP)
                   (LIST '|substitute| 'SUBST)
+                  (LIST '|substitute!| 'NSUBST)
                   (LIST '|symbol?| 'SYMBOLP) (LIST '|take| 'TAKE)
                   (LIST '|third| 'CADDR) (LIST '|true| 'T)
                   (LIST '|upperCase?| 'UPPER-CASE-P)
diff --git a/src/boot/tokens.boot b/src/boot/tokens.boot
index e5160acd..1424c6cd 100644
--- a/src/boot/tokens.boot
+++ b/src/boot/tokens.boot
@@ -280,7 +280,8 @@ for i in [ _
   ["setUnion",   "UNION"]  , _
   ["strconc",  "CONCAT"]  , _
   ["string?",  "STRINGP"]  ,_
-  ["substitute", "SUBST"]  , _
+  ["substitute",  "SUBST"]  , _
+  ["substitute!", "NSUBST"]  , _
   ["symbol?",  "SYMBOLP"]  , _
   ["take",        "TAKE"]  , 
   ["third",      "CADDR"] , _
diff --git a/src/interp/compiler.boot b/src/interp/compiler.boot
index 4999b870..85f796bc 100644
--- a/src/interp/compiler.boot
+++ b/src/interp/compiler.boot
@@ -2169,8 +2169,7 @@ compMatchAlternative(sn,sm,pat,stmt,m,e) ==
             stackAndThrow('"could not compile %1b under mode %2pb",[stmt,m])
   body :=
     null inits => stmtT.expr
-    atom sn => ["LET",inits,stmtT.expr]
-    ["%bind",inits,stmtT.expr]
+    ['%bind,inits,stmtT.expr]
   [[guard,body],stmtT.mode,stmtT.env,eF]
 
 ++ Analyze and generate code for `is case'-pattern where the
diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot
index a42dc1ac..ccde3eb8 100644
--- a/src/interp/g-opt.boot
+++ b/src/interp/g-opt.boot
@@ -590,10 +590,18 @@ optLET_* form ==
   optLET form
 
 optBind form ==
-  form isnt ['%bind,inits,body] => form  -- inline only simple expressions
-  inits = nil => body                    -- no local variable, OK.
-  inits isnt [[var,expr]] => form        -- too many local variables
-  canInlineVarDefinition(var,expr,body) => substitute(expr,var,body)
+  form isnt ['%bind,inits,.] => form           -- accept only simple bodies
+  ok := true
+  while ok and inits ~= nil repeat
+    [var,expr] := first inits
+    usedSymbol?(var,rest inits) => ok := false -- no dependency, please.
+    body := third form
+    canInlineVarDefinition(var,expr,body) and isSimpleVMForm expr =>
+      third(form) := substitute_!(expr,var,body)
+      inits := rest inits
+    ok := false
+  null inits => third form                        -- no local var left
+  second(form) := inits
   form
 
 optLIST form ==
-- 
cgit v1.2.3