changeset 2192:fb113569519e

Make daemon mode support sharing of libraries across projects
author Adam Chlipala <adam@chlipala.net>
date Sun, 22 Nov 2015 10:03:35 -0500
parents 849404a3af27
children 1d6e7e3405f6
files src/compiler.sml src/elaborate.sml src/main.mlton.sml src/settings.sig src/settings.sml
diffstat 5 files changed, 71 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/compiler.sml	Sun Nov 01 17:02:16 2015 -0500
+++ b/src/compiler.sml	Sun Nov 22 10:03:35 2015 -0500
@@ -413,11 +413,7 @@
 val lastUrp = ref ""
 
 fun parseUrp' accLibs fname =
-    (if !lastUrp = fname then
-         ()
-     else
-         ModDb.reset ();
-     lastUrp := fname;
+    (lastUrp := fname;
      if not (Posix.FileSys.access (fname ^ ".urp", []) orelse Posix.FileSys.access (fname ^ "/lib.urp", []))
         andalso Posix.FileSys.access (fname ^ ".ur", []) then
          let
--- a/src/elaborate.sml	Sun Nov 01 17:02:16 2015 -0500
+++ b/src/elaborate.sml	Sun Nov 22 10:03:35 2015 -0500
@@ -5019,5 +5019,7 @@
         @ (L'.DStr ("Top", top_n, topSgn, topStr), ErrorMsg.dummySpan)
         :: ds' @ file
     end
+    handle e => (ModDb.revert ();
+                 raise e)
 
 end
--- a/src/main.mlton.sml	Sun Nov 01 17:02:16 2015 -0500
+++ b/src/main.mlton.sml	Sun Nov 22 10:03:35 2015 -0500
@@ -279,19 +279,25 @@
                                           in
                                               case cmd of
                                                   "" =>
-                                                  let
-                                                      val success = (oneRun (rev args))
-                                                          handle ex => (print "unhandled exception:\n";
-                                                                        print (General.exnMessage ex ^ "\n");
-                                                                        OS.Process.failure)
-                                                  in
-                                                      TextIO.flushOut TextIO.stdOut;
-                                                      TextIO.flushOut TextIO.stdErr;
-                                                      send (sock, if OS.Process.isSuccess success then
-                                                                      "\001"
-                                                                  else
-                                                                      "\002")
-                                                  end
+                                                  (case args of
+                                                       ["stop", "daemon"] =>
+                                                       (((Socket.close listen;
+                                                          OS.FileSys.remove socket) handle OS.SysErr _ => ());
+                                                        OS.Process.exit OS.Process.success)
+                                                     | _ =>
+                                                       let
+                                                           val success = (oneRun (rev args))
+                                                               handle ex => (print "unhandled exception:\n";
+                                                                             print (General.exnMessage ex ^ "\n");
+                                                                             OS.Process.failure)
+                                                       in
+                                                           TextIO.flushOut TextIO.stdOut;
+                                                           TextIO.flushOut TextIO.stdErr;
+                                                           send (sock, if OS.Process.isSuccess success then
+                                                                           "\001"
+                                                                       else
+                                                                           "\002")
+                                                       end)
                                                 | _ => loop' (rest, cmd :: args)
                                           end
                                   end handle OS.SysErr _ => ()
@@ -315,6 +321,7 @@
                               Posix.IO.close oldStdout;
                               Posix.IO.close oldStderr;
 
+                              Settings.reset ();
                               MLton.GC.pack ();
                               loop ()
                           end
@@ -324,8 +331,6 @@
                       Socket.listen (listen, 1);
                       loop ()
                   end)
-           | ["daemon", "stop"] =>
-	     (OS.FileSys.remove socket handle OS.SysErr _ => OS.Process.exit OS.Process.success) 
            | args =>
              let
                  val sock = UnixSock.Strm.socket ()
--- a/src/settings.sig	Sun Nov 01 17:02:16 2015 -0500
+++ b/src/settings.sig	Sun Nov 22 10:03:35 2015 -0500
@@ -27,6 +27,10 @@
 
 signature SETTINGS = sig
 
+    (* Call this when compiling a new project, e.g. with the Ur/Web daemon or from the SML/NJ REPL.
+     * Some settings stay, but most are reset, especially files cached for the app to serve. *)
+    val reset : unit -> unit
+
     (* XXX these should be unit -> string too *)
     val configBin : string ref
     val configLib : string ref
--- a/src/settings.sml	Sun Nov 01 17:02:16 2015 -0500
+++ b/src/settings.sml	Sun Nov 22 10:03:35 2015 -0500
@@ -726,11 +726,6 @@
 fun setMinHeap n = if n >= 0 then minHeap := n else raise Fail "Trying to set negative minHeap"
 fun getMinHeap () = !minHeap
 
-structure SS = BinarySetFn(struct
-                           type ord_key = string
-                           val compare = String.compare
-                           end)
-
 val alwaysInline = ref SS.empty
 fun addAlwaysInline s = alwaysInline := SS.add (!alwaysInline, s)
 fun checkAlwaysInline s = SS.member (!alwaysInline, s)
@@ -908,4 +903,48 @@
 
 fun listFiles () = map #2 (SM.listItems (!files))
 
+fun reset () =
+    (urlPrefixFull := "/";
+     urlPrefix := "/";
+     urlPrePrefix := "";
+     timeout := 0;
+     headers := [];
+     scripts := [];
+     clientToServer := clientToServerBase;
+     effectful := effectfulBase;
+     benign := benignBase;
+     client := clientBase;
+     server := serverBase;
+     jsFuncs := jsFuncsBase;
+     rewrites := [];
+     url := [];
+     mime := [];
+     request := [];
+     response := [];
+     env := [];
+     debug := false;
+     dbstring := NONE;
+     exe := NONE;
+     sql := NONE;
+     coreInline := 5;
+     monoInline := 5;
+     staticLinking := false;
+     deadlines := false;
+     sigFile := NONE;
+     safeGet := SS.empty;
+     onError := NONE;
+     limitsList := [];
+     minHeap := 0;
+     alwaysInline := SS.empty;
+     neverInline := SS.empty;
+     noXsrfProtection := SS.empty;
+     timeFormat := "%c";
+     mangle := true;
+     html5 := false;
+     less := false;
+     noMimeFile := false;
+     mimeTypes := NONE;
+     files := SM.empty;
+     filePath := ".")
+
 end