summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-10-08 17:23:58 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2011-10-08 17:23:58 -0400
commit8b909d991fe993c711d432cfc9928dc7ffbdbbac (patch)
treeaf5545a16e8c2d7f65737c161285cf78b8ed2d43 /src
parent2b3bec54a0307652646f5ad9deff619b82cb5a91 (diff)
Primitive int/float functions: ceil, float, round, trunc
Diffstat (limited to 'src')
-rw-r--r--src/c/urweb.c17
-rw-r--r--src/monoize.sml7
-rw-r--r--src/settings.sml5
3 files changed, 29 insertions, 0 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 0f1634e9..491fb73d 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -16,6 +16,7 @@
#include <openssl/des.h>
#include <openssl/rand.h>
#include <time.h>
+#include <math.h>
#include <pthread.h>
@@ -3956,3 +3957,19 @@ void uw_cutErrorLocation(char *s) {
uw_Basis_string uw_Basis_fresh(uw_context ctx) {
return uw_Basis_htmlifyInt(ctx, ctx->nextId++);
}
+
+uw_Basis_float uw_Basis_floatFromInt(uw_context ctx, uw_Basis_int n) {
+ return n;
+}
+
+uw_Basis_int uw_Basis_ceil(uw_context ctx, uw_Basis_float n) {
+ return ceil(n);
+}
+
+uw_Basis_int uw_Basis_trunc(uw_context ctx, uw_Basis_float n) {
+ return trunc(n);
+}
+
+uw_Basis_int uw_Basis_round(uw_context ctx, uw_Basis_float n) {
+ return round(n);
+}
diff --git a/src/monoize.sml b/src/monoize.sml
index f6ea7255..417bf044 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -1356,6 +1356,13 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
end
| L.EFfiApp ("Basis", "recv", _) => poly ()
+ | L.EFfiApp ("Basis", "float", [e]) =>
+ let
+ val (e, fm) = monoExp (env, st, fm) e
+ in
+ ((L'.EFfiApp ("Basis", "floatFromInt", [e]), loc), fm)
+ end
+
| L.EFfiApp ("Basis", "sleep", [n]) =>
let
val (n, fm) = monoExp (env, st, fm) n
diff --git a/src/settings.sml b/src/settings.sml
index ab1d7f88..f7bb4027 100644
--- a/src/settings.sml
+++ b/src/settings.sml
@@ -270,6 +270,11 @@ val jsFuncsBase = basisM [("alert", "alert"),
("debug", "alert"),
("naughtyDebug", "alert"),
+ ("floatFromInt", "float"),
+ ("ceil", "ceil"),
+ ("trunc", "trunc"),
+ ("round", "round"),
+
("now", "now"),
("timeToString", "showTime"),
("htmlifyTime", "showTime"),