diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-10-21 10:40:22 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-10-21 10:40:22 -0400 |
commit | 007027d1bb5b084352a1fc9e4e4178ee8e9821fe (patch) | |
tree | d74ba8993884143248dc1c3e9bb69d44d597d212 | |
parent | 29a7ea8ff27061917f6e5352f9d1eb8ccad7c680 (diff) |
num_float
-rw-r--r-- | lib/basis.urs | 1 | ||||
-rw-r--r-- | src/cjr_print.sml | 3 | ||||
-rw-r--r-- | src/compiler.sml | 2 | ||||
-rw-r--r-- | src/monoize.sml | 19 | ||||
-rw-r--r-- | tests/num.ur | 4 |
5 files changed, 27 insertions, 2 deletions
diff --git a/lib/basis.urs b/lib/basis.urs index 18cd4c37..f2a08a86 100644 --- a/lib/basis.urs +++ b/lib/basis.urs @@ -26,6 +26,7 @@ val times : t ::: Type -> num t -> t -> t -> t val div : t ::: Type -> num t -> t -> t -> t val mod : t ::: Type -> num t -> t -> t -> t val num_int : num int +val num_float : num float (** String operations *) diff --git a/src/cjr_print.sml b/src/cjr_print.sml index e0441425..3e96b1a6 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -617,6 +617,7 @@ fun p_exp' par env (e, loc) = | EBinop (s, e1, e2) => if Char.isAlpha (String.sub (s, size s - 1)) then box [string s, + string "(", p_exp env e1, string ",", space, @@ -2054,6 +2055,8 @@ fun p_file env (ds, ps) = newline, string "#include <string.h>", newline, + string "#include <math.h>", + newline, string "#include <postgresql/libpq-fe.h>", newline, newline, diff --git a/src/compiler.sml b/src/compiler.sml index 717f5ae1..a98f121b 100644 --- a/src/compiler.sml +++ b/src/compiler.sml @@ -512,7 +512,7 @@ fun compileC {cname, oname, ename} = val driver_o = clibFile "driver.o" val compile = "gcc -Wstrict-prototypes -Werror -O3 -I include -c " ^ cname ^ " -o " ^ oname - val link = "gcc -Werror -O3 -pthread -lpq " ^ urweb_o ^ " " ^ oname ^ " " ^ driver_o ^ " -o " ^ ename + val link = "gcc -Werror -O3 -lm -pthread -lpq " ^ urweb_o ^ " " ^ oname ^ " " ^ driver_o ^ " -o " ^ ename in if not (OS.Process.isSuccess (OS.Process.system compile)) then print "C compilation failed\n" diff --git a/src/monoize.sml b/src/monoize.sml index c00695d6..bafde2bc 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -633,6 +633,25 @@ fun monoExp (env, st, fm) (all as (e, loc)) = intBin "/", intBin "%") end + | L.EFfi ("Basis", "num_float") => + let + fun floatBin s = + (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc), + (L'.TFun ((L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "float"), loc)), loc), + (L'.EAbs ("y", (L'.TFfi ("Basis", "float"), loc), + (L'.TFfi ("Basis", "float"), loc), + (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc) + in + numEx ((L'.TFfi ("Basis", "float"), loc), + (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc), + (L'.TFfi ("Basis", "float"), loc), + (L'.EUnop ("-", (L'.ERel 0, loc)), loc)), loc), + floatBin "+", + floatBin "-", + floatBin "*", + floatBin "/", + floatBin "fmod") + end | L.ECApp ((L.EFfi ("Basis", "show"), _), t) => let diff --git a/tests/num.ur b/tests/num.ur index 6dab5ac3..015f227c 100644 --- a/tests/num.ur +++ b/tests/num.ur @@ -1,3 +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)} + {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/> </body></xml> |