# HG changeset patch # User Adam Chlipala # Date 1224601003 14400 # Node ID fe8f75f7e1306d87c5350f69a873b0225dd0002c # Parent 519366a76603226d28312960fab829e8e1940661 lt, le working for int diff -r 519366a76603 -r fe8f75f7e130 lib/basis.urs --- a/lib/basis.urs Tue Oct 21 10:40:22 2008 -0400 +++ b/lib/basis.urs Tue Oct 21 10:56:43 2008 -0400 @@ -28,6 +28,13 @@ val num_int : num int val num_float : num float +class ord +val lt : t ::: Type -> ord t -> t -> t -> bool +val le : t ::: Type -> ord t -> t -> t -> bool +val gt : t ::: Type -> ord t -> t -> t -> bool +val ge : t ::: Type -> ord t -> t -> t -> bool +val ord_int : ord int + (** String operations *) diff -r 519366a76603 -r fe8f75f7e130 src/monoize.sml --- a/src/monoize.sml Tue Oct 21 10:40:22 2008 -0400 +++ b/src/monoize.sml Tue Oct 21 10:56:43 2008 -0400 @@ -112,6 +112,14 @@ ("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 @@ ("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 @@ 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 -r 519366a76603 -r fe8f75f7e130 src/urweb.grm --- a/src/urweb.grm Tue Oct 21 10:40:22 2008 -0400 +++ b/src/urweb.grm Tue Oct 21 10:56:43 2008 -0400 @@ -697,6 +697,12 @@ | 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 @@ (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) diff -r 519366a76603 -r fe8f75f7e130 tests/num.ur --- a/tests/num.ur Tue Oct 21 10:40:22 2008 -0400 +++ b/tests/num.ur Tue Oct 21 10:56:43 2008 -0400 @@ -1,5 +1,5 @@ fun main () : transaction page = return - {txt _ (-1)}, {txt _ (1 + 1)}, {txt _ (9 - 3)}, {txt _ (9 * 3)}, {txt _ (9 / 3)}, {txt _ (9 % 3)}
- {txt _ (-1.1)}, {txt _ (1.0 + 1.1)}, {txt _ (9.1 - 3.0)}, {txt _ (9.1 * 3.0)}, - {txt _ (9.1 / 3.0)}, {txt _ (9.1 % 3.0)}
+ {[ -1 ]}, {[ 1 + 1 ]}, {[ 9 - 3 ]}, {[ 9 * 3 ]}, {[ 9 / 3 ]}, {[ 9 % 3 ]}
+ {[ -1.1 ]}, {[ 1.0 + 1.1 ]}, {[ 9.1 - 3.0 ]}, {[ 9.1 * 3.0 ]}, + {[ 9.1 / 3.0 ]}, {[ 9.1 % 3.0 ]}
diff -r 519366a76603 -r fe8f75f7e130 tests/ord.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/ord.ur Tue Oct 21 10:56:43 2008 -0400 @@ -0,0 +1,3 @@ +fun main () : transaction page = return + {[ 1 < 1 ]}, {[ 1 < 2 ]}, {[ 1 <= 1 ]}, {[ 2 <= 1 ]} + diff -r 519366a76603 -r fe8f75f7e130 tests/ord.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/ord.urp Tue Oct 21 10:56:43 2008 -0400 @@ -0,0 +1,3 @@ +debug + +ord