diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-10-21 10:56:43 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-10-21 10:56:43 -0400 |
commit | ce5158acc101774d5a264ae7154e9e0799e3848c (patch) | |
tree | 0f3b413495a6f55cc12a8d4abf6e0f6fb3b9cdfc /src | |
parent | 007027d1bb5b084352a1fc9e4e4178ee8e9821fe (diff) |
lt, le working for int
Diffstat (limited to 'src')
-rw-r--r-- | src/monoize.sml | 44 | ||||
-rw-r--r-- | src/urweb.grm | 13 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/monoize.sml b/src/monoize.sml index bafde2bc..8c9094b6 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -112,6 +112,14 @@ fun monoType env = ("Mod", (L'.TFun (t, (L'.TFun (t, t), loc)), loc))], loc) end + | L.CApp ((L.CFfi ("Basis", "ord"), _), t) => + let + val t = mt env dtmap t + in + (L'.TRecord [("Lt", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)), + ("Le", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))], + loc) + end | L.CApp ((L.CFfi ("Basis", "show"), _), t) => (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc) | L.CApp ((L.CFfi ("Basis", "read"), _), t) => @@ -496,6 +504,14 @@ fun monoExp (env, st, fm) (all as (e, loc)) = ("Times", times, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)), ("Div", dv, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)), ("Mod", md, (L'.TFun (t, (L'.TFun (t, t), loc)), loc))], loc), fm) + + fun ordTy t = + (L'.TRecord [("Lt", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)), + ("Le", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))], loc) + fun ordEx (t, lt, le) = + ((L'.ERecord [("Lt", lt, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)), + ("Le", le, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))], + loc), fm) in case e of L.EPrim p => ((L'.EPrim p, loc), fm) @@ -652,6 +668,34 @@ fun monoExp (env, st, fm) (all as (e, loc)) = floatBin "/", floatBin "fmod") end + + | L.ECApp ((L.EFfi ("Basis", "lt"), _), t) => + let + val t = monoType env t + in + ((L'.EAbs ("r", ordTy t, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc), + (L'.EField ((L'.ERel 0, loc), "Lt"), loc)), loc), fm) + end + | L.ECApp ((L.EFfi ("Basis", "le"), _), t) => + let + val t = monoType env t + in + ((L'.EAbs ("r", ordTy t, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc), + (L'.EField ((L'.ERel 0, loc), "Le"), loc)), loc), fm) + end + | L.EFfi ("Basis", "ord_int") => + let + fun intBin s = + (L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc), + (L'.TFun ((L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc), + (L'.EAbs ("y", (L'.TFfi ("Basis", "int"), loc), + (L'.TFfi ("Basis", "bool"), loc), + (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc) + in + ordEx ((L'.TFfi ("Basis", "int"), loc), + intBin "<", + intBin "<=") + end | L.ECApp ((L.EFfi ("Basis", "show"), _), t) => let diff --git a/src/urweb.grm b/src/urweb.grm index 183f9afd..f47e26bb 100644 --- a/src/urweb.grm +++ b/src/urweb.grm @@ -697,6 +697,12 @@ eexp : eapps (eapps) | eterm STAR eexp (native_op ("times", eterm, eexp, s (etermleft, eexpright))) | eexp DIVIDE eexp (native_op ("div", eexp1, eexp2, s (eexp1left, eexp2right))) | eexp MOD eexp (native_op ("mod", eexp1, eexp2, s (eexp1left, eexp2right))) + + | eexp LT eexp (native_op ("lt", eexp1, eexp2, s (eexp1left, eexp2right))) + | eexp LE eexp (native_op ("le", eexp1, eexp2, s (eexp1left, eexp2right))) + | eexp GT eexp (native_op ("gt", eexp1, eexp2, s (eexp1left, eexp2right))) + | eexp GE eexp (native_op ("ge", eexp1, eexp2, s (eexp1left, eexp2right))) + | eexp WITH cterm EQ eexp (EWith (eexp1, cterm, eexp2), s (eexp1left, eexp2right)) eargs : earg (earg) @@ -983,6 +989,13 @@ xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata"), s (NO (EFold, pos)) end) | LBRACE eexp RBRACE (eexp) + | LBRACE LBRACK eexp RBRACK RBRACE (let + val loc = s (LBRACEleft, RBRACEright) + val e = (EVar (["Top"], "txt"), loc) + val e = (EApp (e, (EWild, loc)), loc) + in + (EApp (e, eexp), loc) + end) tag : tagHead attrs (let val pos = s (tagHeadleft, attrsright) |