From c723667d402b730edc4059cb132587977893b42a Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Fri, 22 Jul 2011 15:39:38 -0400 Subject: Backpedal on tutorial-motivated urweb-mode changes; add Basis.diffInSeconds and Basis.toSeconds --- include/urweb.h | 2 ++ lib/js/urweb.js | 8 ++++++++ lib/ur/basis.urs | 3 +++ src/c/urweb.c | 8 ++++++++ src/elisp/urweb-mode.el | 10 +++++----- src/settings.sml | 4 +++- 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/include/urweb.h b/include/urweb.h index 1b10583f..b5692a6d 100644 --- a/include/urweb.h +++ b/include/urweb.h @@ -252,6 +252,8 @@ __attribute__((noreturn)) void uw_redirect(uw_context, uw_Basis_string url); uw_Basis_time uw_Basis_now(uw_context); uw_Basis_time uw_Basis_addSeconds(uw_context, uw_Basis_time, uw_Basis_int); +uw_Basis_int uw_Basis_diffInSeconds(uw_context, uw_Basis_time, uw_Basis_time); +uw_Basis_int uw_Basis_toSeconds(uw_context, uw_Basis_time); extern const uw_Basis_time uw_Basis_minTime; void uw_register_transactional(uw_context, void *data, uw_callback commit, uw_callback rollback, uw_callback_with_retry free); diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 76ad76fa..9834fde6 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -105,6 +105,14 @@ function now() { return (new Date()).getTime() * 1000; } +function diffInSeconds(tm1, tm2) { + return Math.round((tm2 - tm1) / 1000000); +} + +function toSeconds(tm) { + return Math.round(tm / 1000000); +} + // Error handling diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs index b60610cd..cabac068 100644 --- a/lib/ur/basis.urs +++ b/lib/ur/basis.urs @@ -145,6 +145,9 @@ val current : t ::: Type -> signal t -> transaction t val now : transaction time val minTime : time val addSeconds : time -> int -> time +val toSeconds : time -> int +val diffInSeconds : time -> time -> int +(* Earlier time first *) val timef : string -> time -> string (* Uses strftime() format string *) val readUtc : string -> option time diff --git a/src/c/urweb.c b/src/c/urweb.c index 4d2de1dd..641c6c83 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -3664,6 +3664,14 @@ uw_Basis_time uw_Basis_addSeconds(uw_context ctx, uw_Basis_time tm, uw_Basis_int return tm; } +uw_Basis_int uw_Basis_diffInSeconds(uw_context ctx, uw_Basis_time tm1, uw_Basis_time tm2) { + return difftime(tm2.seconds, tm1.seconds); +} + +uw_Basis_int uw_Basis_toSeconds(uw_context ctx, uw_Basis_time tm) { + return tm.seconds; +} + void *uw_get_global(uw_context ctx, char *name) { int i; diff --git a/src/elisp/urweb-mode.el b/src/elisp/urweb-mode.el index 9138dafb..c9fe5f19 100644 --- a/src/elisp/urweb-mode.el +++ b/src/elisp/urweb-mode.el @@ -170,10 +170,8 @@ See doc for the variable `urweb-mode-info'." (finished nil) (answer nil) ) - (while (and (not finished) (re-search-backward "[<>{}]|\\*\)" nil t)) + (while (and (not finished) (re-search-backward "[<>{}]" nil t)) (cond - ((looking-at "*)") - (search-backward "(*")) ((looking-at "{") (if (> depth 0) (decf depth) @@ -183,11 +181,13 @@ See doc for the variable `urweb-mode-info'." ((save-excursion (backward-char 1) (or (looking-at "=>") (looking-at "->") (looking-at "<>"))) - (setq finished t)) + nil) ((or (looking-at "< ") (looking-at "<=")) - (setq finished t)) + nil) ((looking-at "<") (setq finished t)) + ((save-excursion (backward-char 1) (looking-at " >")) + nil) ((looking-at ">") (cond ((> depth 0) diff --git a/src/settings.sml b/src/settings.sml index 57ab956a..c9030eac 100644 --- a/src/settings.sml +++ b/src/settings.sml @@ -252,7 +252,9 @@ val jsFuncsBase = basisM [("alert", "alert"), ("now", "now"), ("timeToString", "showTime"), - ("htmlifyTime", "showTime")] + ("htmlifyTime", "showTime"), + ("toSeconds", "toSeconds"), + ("diffInSeconds", "diffInSeconds")] val jsFuncs = ref jsFuncsBase fun setJsFuncs ls = jsFuncs := foldl (fn ((k, v), m) => M.insert (m, k, v)) jsFuncsBase ls fun jsFunc x = M.find (!jsFuncs, x) -- cgit v1.2.3