summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-08-31 14:27:01 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-08-31 14:27:01 -0400
commitd43dc372d0dbc90031696d8503c05654e6605f84 (patch)
treef618f19e33e6620c75232ab227f786859d261f15 /src
parent769dd2e60357a97baee02b9595340a3c0ee79fb8 (diff)
Monoized a WHERE clause with a comparison
Diffstat (limited to 'src')
-rw-r--r--src/mono_opt.sml21
-rw-r--r--src/mono_reduce.sml4
-rw-r--r--src/monoize.sml74
3 files changed, 96 insertions, 3 deletions
diff --git a/src/mono_opt.sml b/src/mono_opt.sml
index 4b417217..1430dfe2 100644
--- a/src/mono_opt.sml
+++ b/src/mono_opt.sml
@@ -79,6 +79,12 @@ val urlifyString = String.translate (fn #" " => "+"
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 @@ fun exp e =
| 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,
diff --git a/src/mono_reduce.sml b/src/mono_reduce.sml
index 1941f0cc..06cc8bbf 100644
--- a/src/mono_reduce.sml
+++ b/src/mono_reduce.sml
@@ -181,8 +181,8 @@ fun exp env e =
(ELet (x1, t1, b1,
liftExpInExp 1 b2), loc)), loc)
in
- Print.prefaces "ELet commute" [("e", MonoPrint.p_exp env (e, loc)),
- ("e'", MonoPrint.p_exp env e')];
+ (*Print.prefaces "ELet commute" [("e", MonoPrint.p_exp env (e, loc)),
+ ("e'", MonoPrint.p_exp env e')];*)
#1 (reduceExp env e')
end
| EApp ((ELet (x, t, e, b), loc), e') =>
diff --git a/src/monoize.sml b/src/monoize.sml
index abbd4f40..e908b162 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -612,7 +612,9 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
xts)) stables),
sc " FROM ",
strcatComma loc (map (fn (x, _) => strcat loc [(L'.EField (gf "From", x), loc),
- sc (" AS " ^ x)]) tables)
+ sc (" AS " ^ x)]) tables),
+ sc " WHERE ",
+ gf "Where"
]), loc),
fm)
| _ => poly ()
@@ -635,6 +637,23 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
(L'.ERel 0, loc)), loc), fm)
end
+ | L.EFfi ("Basis", "sql_int") =>
+ ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "string"), loc),
+ (L'.EFfiApp ("Basis", "sqlifyInt", [(L'.ERel 0, loc)]), loc)), loc),
+ fm)
+ | L.EFfi ("Basis", "sql_float") =>
+ ((L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "string"), loc),
+ (L'.EFfiApp ("Basis", "sqlifyFloat", [(L'.ERel 0, loc)]), loc)), loc),
+ fm)
+ | L.EFfi ("Basis", "sql_bool") =>
+ ((L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "string"), loc),
+ (L'.EFfiApp ("Basis", "sqlifyBool", [(L'.ERel 0, loc)]), loc)), loc),
+ fm)
+ | L.EFfi ("Basis", "sql_string") =>
+ ((L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "string"), loc),
+ (L'.EFfiApp ("Basis", "sqlifyString", [(L'.ERel 0, loc)]), loc)), loc),
+ fm)
+
| L.ECApp ((L.EFfi ("Basis", "sql_subset"), _), _) =>
((L'.ERecord [], loc), fm)
| L.ECApp ((L.EFfi ("Basis", "sql_subset_all"), _), _) =>
@@ -647,6 +666,59 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
((L'.EPrim (Prim.String ""), loc), fm)
| L.EFfi ("Basis", "sql_no_offset") =>
((L'.EPrim (Prim.String ""), loc), fm)
+
+ | L.EFfi ("Basis", "sql_eq") =>
+ ((L'.EPrim (Prim.String "="), loc), fm)
+ | L.EFfi ("Basis", "sql_ne") =>
+ ((L'.EPrim (Prim.String "<>"), loc), fm)
+ | L.EFfi ("Basis", "sql_lt") =>
+ ((L'.EPrim (Prim.String "<"), loc), fm)
+ | L.EFfi ("Basis", "sql_le") =>
+ ((L'.EPrim (Prim.String "<="), loc), fm)
+ | L.EFfi ("Basis", "sql_gt") =>
+ ((L'.EPrim (Prim.String ">"), loc), fm)
+ | L.EFfi ("Basis", "sql_ge") =>
+ ((L'.EPrim (Prim.String ">="), loc), fm)
+
+ | L.ECApp (
+ (L.ECApp (
+ (L.ECApp (
+ (L.ECApp (
+ (L.EFfi ("Basis", "sql_comparison"), _),
+ _), _),
+ _), _),
+ _), _),
+ _) =>
+ let
+ val s = (L'.TFfi ("Basis", "string"), loc)
+ fun sc s = (L'.EPrim (Prim.String s), loc)
+ in
+ ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
+ (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
+ (L'.EAbs ("e2", s, s,
+ strcat loc [(L'.ERel 1, loc),
+ sc " ",
+ (L'.ERel 2, loc),
+ sc " ",
+ (L'.ERel 0, loc)]), loc)), loc)), loc),
+ fm)
+ end
+
+ | L.ECApp (
+ (L.ECApp (
+ (L.ECApp (
+ (L.ECApp (
+ (L.ECApp (
+ (L.ECApp (
+ (L.ECApp (
+ (L.EFfi ("Basis", "sql_field"), _),
+ _), _),
+ _), _),
+ _), _),
+ _), _),
+ _), _),
+ (L.CName tab, _)), _),
+ (L.CName field, _)) => ((L'.EPrim (Prim.String (tab ^ "." ^ field)), loc), fm)
| L.EApp (
(L.ECApp (