diff src/compiler.sml @ 1089:f1647f16097d

Convenience libifying; allow more NULLs with globals
author Adam Chlipala <adamc@hcoop.net>
date Thu, 24 Dec 2009 15:49:52 -0500
parents 8e240c007442
children e77079953308
line wrap: on
line diff
--- a/src/compiler.sml	Thu Dec 24 10:59:35 2009 -0500
+++ b/src/compiler.sml	Thu Dec 24 15:49:52 2009 -0500
@@ -270,9 +270,13 @@
                           val compare = String.compare
                           end)
 
+val pathmap = ref (M.insert (M.empty, "", Config.libUr))
+
+fun addPath (k, v) = pathmap := M.insert (!pathmap, k, v)
+
 fun parseUrp' accLibs fname =
     let
-        val pathmap = ref (M.insert (M.empty, "", Config.libUr))
+        val pathmap = ref (!pathmap)
         val bigLibs = ref []
 
         fun pu filename =
@@ -304,6 +308,20 @@
                         handle OS.Path.Path => fname
                     end
 
+                fun libify path =
+                    (if Posix.FileSys.access (path ^ ".urp", []) then
+                         path
+                     else
+                         path ^ "/lib")
+                    handle SysErr => path
+
+                fun libify' path =
+                    (if Posix.FileSys.access (relify path ^ ".urp", []) then
+                         path
+                     else
+                         path ^ "/lib")
+                    handle SysErr => path
+
                 val absDir = OS.Path.mkAbsolute {path = dir, relativeTo = OS.FileSys.getDir ()}
 
                 fun relifyA fname =
@@ -559,9 +577,9 @@
                                      end
                                    | _ => ErrorMsg.error "Bad 'deny' syntax")
                               | "library" => if accLibs then
-                                                 libs := pu (relify arg) :: !libs
+                                                 libs := pu (libify (relify arg)) :: !libs
                                              else
-                                                 bigLibs := arg :: !bigLibs
+                                                 bigLibs := libify' arg :: !bigLibs
                               | "path" =>
                                 (case String.fields (fn ch => ch = #"=") arg of
                                      [n, v] => pathmap := M.insert (!pathmap, n, v)