diff src/mono_reduce.sml @ 2110:9e9c915f554c

A new MonoReduce optimization for lifting 'let' out of field projection; JavaScript compilation for exponentiation
author Adam Chlipala <adam@chlipala.net>
date Sun, 01 Feb 2015 12:29:14 -0500
parents 0d48cfb59b29
children ec1614fb97bb
line wrap: on
line diff
--- a/src/mono_reduce.sml	Wed Jan 28 08:47:04 2015 -0500
+++ b/src/mono_reduce.sml	Sun Feb 01 12:29:14 2015 -0500
@@ -818,10 +818,19 @@
                                 search pes
                         end
 
-                      | EField ((ERecord xes, _), x) =>
-                        (case List.find (fn (x', _, _) => x' = x) xes of
-                             SOME (_, e, _) => #1 e
-                           | NONE => e)
+                      | EField (e1, x) =>
+                        let
+                            fun yankLets (e : exp) =
+                                case #1 e of
+                                    ELet (x, t, e1, e2) => (ELet (x, t, e1, yankLets e2), #2 e)
+                                  | ERecord xes =>
+                                    (case List.find (fn (x', _, _) => x' = x) xes of
+                                         SOME (_, e, _) => e
+                                       | NONE => (EField (e, x), #2 e))
+                                  | _ => (EField (e, x), #2 e)
+                        in
+                            #1 (yankLets e1)
+                        end
 
                       | ELet (x1, t1, (ELet (x2, t2, e1, b1), loc), b2) =>
                         let