changeset 1514:3c0803c1acd7

Backpedal on tutorial-motivated urweb-mode changes; add Basis.diffInSeconds and Basis.toSeconds
author Adam Chlipala <adam@chlipala.net>
date Fri, 22 Jul 2011 15:39:38 -0400
parents 5616b2cbdcdb
children 8c65218920cf
files include/urweb.h lib/js/urweb.js lib/ur/basis.urs src/c/urweb.c src/elisp/urweb-mode.el src/settings.sml
diffstat 6 files changed, 29 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/include/urweb.h	Wed Jul 20 08:14:49 2011 -0400
+++ b/include/urweb.h	Fri Jul 22 15:39:38 2011 -0400
@@ -252,6 +252,8 @@
 
 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);
--- a/lib/js/urweb.js	Wed Jul 20 08:14:49 2011 -0400
+++ b/lib/js/urweb.js	Fri Jul 22 15:39:38 2011 -0400
@@ -105,6 +105,14 @@
     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
 
--- a/lib/ur/basis.urs	Wed Jul 20 08:14:49 2011 -0400
+++ b/lib/ur/basis.urs	Fri Jul 22 15:39:38 2011 -0400
@@ -145,6 +145,9 @@
 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
 
--- a/src/c/urweb.c	Wed Jul 20 08:14:49 2011 -0400
+++ b/src/c/urweb.c	Fri Jul 22 15:39:38 2011 -0400
@@ -3664,6 +3664,14 @@
   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;
 
--- a/src/elisp/urweb-mode.el	Wed Jul 20 08:14:49 2011 -0400
+++ b/src/elisp/urweb-mode.el	Fri Jul 22 15:39:38 2011 -0400
@@ -170,10 +170,8 @@
           (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 @@
          ((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)
--- a/src/settings.sml	Wed Jul 20 08:14:49 2011 -0400
+++ b/src/settings.sml	Fri Jul 22 15:39:38 2011 -0400
@@ -252,7 +252,9 @@
 
                           ("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)