diff src/mono_opt.sml @ 253:7f6620853c36

Monoized a WHERE clause with a comparison
author Adam Chlipala <adamc@hcoop.net>
date Sun, 31 Aug 2008 14:27:01 -0400
parents 890a61991263
children d1b679dbbc25
line wrap: on
line diff
--- a/src/mono_opt.sml	Sun Aug 31 13:58:47 2008 -0400
+++ b/src/mono_opt.sml	Sun Aug 31 14:27:01 2008 -0400
@@ -79,6 +79,12 @@
                                                   str ch
                                               else
                                                   "%" ^ hexIt ch)
+
+
+val sqlifyInt = attrifyInt
+val sqlifyFloat = attrifyFloat
+
+fun sqlifyString s = "E'" ^ String.toString s ^ "'"
         
 fun exp e =
     case e of
@@ -203,6 +209,21 @@
       | EWrite (EFfiApp ("Basis", "urlifyBool", [e]), _) =>
         EFfiApp ("Basis", "urlifyBool_w", [e])
 
+      | EFfiApp ("Basis", "sqlifyInt", [(EPrim (Prim.Int n), _)]) =>
+        EPrim (Prim.String (sqlifyInt n))
+      | EFfiApp ("Basis", "sqlifyFloat", [(EPrim (Prim.Float n), _)]) =>
+        EPrim (Prim.String (sqlifyFloat n))
+      | EFfiApp ("Basis", "sqlifyBool", [b as (_, loc)]) =>
+        optExp (ECase (b,
+                       [((PCon (Enum, PConFfi {mod = "Basis", datatyp = "bool", con = "True", arg = NONE}, NONE), loc),
+                         (EPrim (Prim.String "TRUE"), loc)),
+                        ((PCon (Enum, PConFfi {mod = "Basis", datatyp = "bool", con = "False", arg = NONE}, NONE), loc),
+                         (EPrim (Prim.String "FALSE"), loc))],
+                       {disc = (TFfi ("Basis", "bool"), loc),
+                        result = (TFfi ("Basis", "string"), loc)}), loc)
+      | EFfiApp ("Basis", "sqlifyString", [(EPrim (Prim.String n), _)]) =>
+        EPrim (Prim.String (sqlifyString n))
+
       | EWrite (ECase (discE, pes, {disc, ...}), loc) =>
         optExp (ECase (discE,
                        map (fn (p, e) => (p, (EWrite e, loc))) pes,