# HG changeset patch # User Adam Chlipala # Date 1224600022 14400 # Node ID 519366a76603226d28312960fab829e8e1940661 # Parent acaf9d19fbb721c2cdd68c0e1144268aa0f389d9 num_float diff -r acaf9d19fbb7 -r 519366a76603 lib/basis.urs --- a/lib/basis.urs Tue Oct 21 10:34:07 2008 -0400 +++ b/lib/basis.urs Tue Oct 21 10:40:22 2008 -0400 @@ -26,6 +26,7 @@ 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 -r acaf9d19fbb7 -r 519366a76603 src/cjr_print.sml --- a/src/cjr_print.sml Tue Oct 21 10:34:07 2008 -0400 +++ b/src/cjr_print.sml Tue Oct 21 10:40:22 2008 -0400 @@ -617,6 +617,7 @@ | 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 @@ newline, string "#include ", newline, + string "#include ", + newline, string "#include ", newline, newline, diff -r acaf9d19fbb7 -r 519366a76603 src/compiler.sml --- a/src/compiler.sml Tue Oct 21 10:34:07 2008 -0400 +++ b/src/compiler.sml Tue Oct 21 10:40:22 2008 -0400 @@ -512,7 +512,7 @@ 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 -r acaf9d19fbb7 -r 519366a76603 src/monoize.sml --- a/src/monoize.sml Tue Oct 21 10:34:07 2008 -0400 +++ b/src/monoize.sml Tue Oct 21 10:40:22 2008 -0400 @@ -633,6 +633,25 @@ 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 -r acaf9d19fbb7 -r 519366a76603 tests/num.ur --- a/tests/num.ur Tue Oct 21 10:34:07 2008 -0400 +++ b/tests/num.ur Tue Oct 21 10:40:22 2008 -0400 @@ -1,3 +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)}, {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)}