diff src/mono_reduce.sml @ 829:20fe00fd81da

Substring functions; fix a nasty MonoReduce pattern match substitution bug
author Adam Chlipala <adamc@hcoop.net>
date Sat, 30 May 2009 13:29:00 -0400
parents 497c7dbcc695
children e8594cfa3236
line wrap: on
line diff
--- a/src/mono_reduce.sml	Sat May 30 09:59:10 2009 -0400
+++ b/src/mono_reduce.sml	Sat May 30 13:29:00 2009 -0400
@@ -85,6 +85,11 @@
 
 val liftExpInExp = Monoize.liftExpInExp
 
+fun multiLift n e =
+    case n of
+        0 => e
+      | _ => multiLift (n - 1) (liftExpInExp 0 e)
+
 val subExpInExp' =
     U.Exp.mapB {typ = fn t => t,
                 exp = fn (xn, rep) => fn e =>
@@ -419,11 +424,16 @@
                                       | Maybe => push ()
                                       | Yes subs =>
                                         let
-                                            val body = foldr (fn (e, body) => subExpInExp (0, e) body) body subs
+                                            val (body, remaining) =
+                                                foldl (fn (e, (body, remaining)) =>
+                                                          (subExpInExp (0, multiLift remaining e) body, remaining - 1))
+                                                      (body, length subs - 1) subs
                                             val r = reduceExp env body
                                         in
+                                            (*Print.preface ("subs", Print.p_list (MonoPrint.p_exp env) subs);*)
                                             (*Print.prefaces "ECase"
-                                                           [("body", MonoPrint.p_exp env' body),
+                                                           [("old", MonoPrint.p_exp env body),
+                                                            ("body", MonoPrint.p_exp env body),
                                                             ("r", MonoPrint.p_exp env r)];*)
                                             #1 r
                                         end
@@ -533,7 +543,8 @@
 
                       | _ => e
             in
-                (*Print.prefaces "exp'" [("r", MonoPrint.p_exp env (r, ErrorMsg.dummySpan))];*)
+                (*Print.prefaces "exp'" [("e", MonoPrint.p_exp env (e, ErrorMsg.dummySpan)),
+                                       ("r", MonoPrint.p_exp env (r, ErrorMsg.dummySpan))];*)
                 r
             end