diff src/mono_opt.sml @ 486:8e055bbbd28b

Remove some allocation
author Adam Chlipala <adamc@hcoop.net>
date Sun, 09 Nov 2008 18:19:47 -0500
parents 3f1b9231a37b
children 98f85c1bc867
line wrap: on
line diff
--- a/src/mono_opt.sml	Sun Nov 09 17:27:34 2008 -0500
+++ b/src/mono_opt.sml	Sun Nov 09 18:19:47 2008 -0500
@@ -320,11 +320,39 @@
 
       | EWrite (EQuery {exps, tables, state, query,
                         initial = (EPrim (Prim.String ""), _),
+                        body}, loc) =>
+        let
+            fun passLets (depth, (e', _), lets) =
+                case e' of
+                    EStrcat ((ERel x, _), e'') =>
+                    if x = depth then
+                        let
+                            val body = (optExp (EWrite e'', loc), loc)
+                            val body = foldl (fn ((x, t, e'), e) =>
+                                                 (ELet (x, t, e', e), loc))
+                                             body lets
+                        in
+                            EQuery {exps = exps, tables = tables, query = query,
+                                    state = (TRecord [], loc),
+                                    initial = (ERecord [], loc),
+                                    body = body}
+                        end
+                    else
+                        e
+                  | ELet (x, t, e', e'') =>
+                    passLets (depth + 1, e'', (x, t, e') :: lets)
+                  | _ => e
+        in
+            passLets (0, body, [])
+        end
+
+      (*| EWrite (EQuery {exps, tables, state, query,
+                        initial = (EPrim (Prim.String ""), _),
                         body = (EStrcat ((ERel 0, _), e'), _)}, loc) =>
         EQuery {exps = exps, tables = tables, query = query,
                 state = (TRecord [], loc),
                 initial = (ERecord [], loc),
-                body = (optExp (EWrite e', loc), loc)}
+                body = (optExp (EWrite e', loc), loc)}*)
 
       | EWrite (ELet (x, t, e1, e2), loc) =>
         optExp (ELet (x, t, e1, (EWrite e2, loc)), loc)