summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/basis.urs7
-rw-r--r--src/monoize.sml44
-rw-r--r--src/urweb.grm13
-rw-r--r--tests/num.ur6
-rw-r--r--tests/ord.ur3
-rw-r--r--tests/ord.urp3
6 files changed, 73 insertions, 3 deletions
diff --git a/lib/basis.urs b/lib/basis.urs
index f2a08a86..5aba5526 100644
--- a/lib/basis.urs
+++ b/lib/basis.urs
@@ -28,6 +28,13 @@ val mod : t ::: Type -> num t -> t -> t -> t
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 --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)
diff --git a/tests/num.ur b/tests/num.ur
index 015f227c..0fa2ffdd 100644
--- a/tests/num.ur
+++ b/tests/num.ur
@@ -1,5 +1,5 @@
fun main () : transaction page = return <xml><body>
- {txt _ (-1)}, {txt _ (1 + 1)}, {txt _ (9 - 3)}, {txt _ (9 * 3)}, {txt _ (9 / 3)}, {txt _ (9 % 3)}<br/>
- {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)}<br/>
+ {[ -1 ]}, {[ 1 + 1 ]}, {[ 9 - 3 ]}, {[ 9 * 3 ]}, {[ 9 / 3 ]}, {[ 9 % 3 ]}<br/>
+ {[ -1.1 ]}, {[ 1.0 + 1.1 ]}, {[ 9.1 - 3.0 ]}, {[ 9.1 * 3.0 ]},
+ {[ 9.1 / 3.0 ]}, {[ 9.1 % 3.0 ]}<br/>
</body></xml>
diff --git a/tests/ord.ur b/tests/ord.ur
new file mode 100644
index 00000000..4bca682b
--- /dev/null
+++ b/tests/ord.ur
@@ -0,0 +1,3 @@
+fun main () : transaction page = return <xml><body>
+ {[ 1 < 1 ]}, {[ 1 < 2 ]}, {[ 1 <= 1 ]}, {[ 2 <= 1 ]}
+</body></xml>
diff --git a/tests/ord.urp b/tests/ord.urp
new file mode 100644
index 00000000..b44219b4
--- /dev/null
+++ b/tests/ord.urp
@@ -0,0 +1,3 @@
+debug
+
+ord