[MLton-commit] r6186

Vesa Karvonen vesak at mlton.org
Tue Nov 20 00:22:33 PST 2007


Changed to allow both absolute and relative paths.  Added predefined
variable MLTON_LIB.  Changed to allow overriding predefined variables
using environment variables.

----------------------------------------------------------------------

U   mltonlib/trunk/org/mlton/vesak/use-lib/unstable/Make.sh
U   mltonlib/trunk/org/mlton/vesak/use-lib/unstable/detail/use-lib.sml
U   mltonlib/trunk/org/mlton/vesak/use-lib/unstable/public/use-lib.sig

----------------------------------------------------------------------

Modified: mltonlib/trunk/org/mlton/vesak/use-lib/unstable/Make.sh
===================================================================
--- mltonlib/trunk/org/mlton/vesak/use-lib/unstable/Make.sh	2007-11-20 07:37:06 UTC (rev 6185)
+++ mltonlib/trunk/org/mlton/vesak/use-lib/unstable/Make.sh	2007-11-20 08:22:32 UTC (rev 6186)
@@ -7,6 +7,8 @@
 
 set -e
 
+MLTON_LIB=`cd ../../../../.. && pwd`
+
 sources="public/use-lib.sig detail/use-lib.sml public/export.sml"
 
 function gen {
@@ -24,11 +26,12 @@
         grep -v '^ *(\?\*' $workarounds >> .tmp
     fi
 
-    cat $sources                                \
-  | grep -v '^ *(\?\*'                          \
-  | sed -e "s/\\\${SML_COMPILER}/\"$1\"/g"      \
-        -e "s/\\\${SILENT}/$(echo -n $2)/g"     \
-        -e "s/\\\${VERBOSE}/$(echo -n $3)/g"    \
+    cat $sources                                  \
+  | grep -v '^ *(\?\*'                            \
+  | sed -e "s|\\\${SML_COMPILER}|\"$1\"|g"        \
+        -e "s|\\\${MLTON_LIB}|\"${MLTON_LIB}\"|g" \
+        -e "s|\\\${SILENT}|$(echo -n $2)|g"       \
+        -e "s|\\\${VERBOSE}|$(echo -n $3)|g"      \
   >> .tmp
 
     if test ! -f $1.use ; then

Modified: mltonlib/trunk/org/mlton/vesak/use-lib/unstable/detail/use-lib.sml
===================================================================
--- mltonlib/trunk/org/mlton/vesak/use-lib/unstable/detail/use-lib.sml	2007-11-20 07:37:06 UTC (rev 6185)
+++ mltonlib/trunk/org/mlton/vesak/use-lib/unstable/detail/use-lib.sml	2007-11-20 08:22:32 UTC (rev 6186)
@@ -12,15 +12,16 @@
    fun error strs = raise Fail (concat strs)
 
    structure Var = struct
-      val vars = ref [("SML_COMPILER", ${SML_COMPILER})]
+      val vars = ref [("SML_COMPILER", ${SML_COMPILER}),
+                      ("MLTON_LIB",    ${MLTON_LIB})]
 
       fun get var =
-          case List.find (fn (i, _) => i = var) (!vars)
-           of SOME (_, v) => v
-            | NONE =>
-              case OS.Process.getEnv var
-               of NONE   => error ["Undefined variable: ", var]
-                | SOME v => v
+          case OS.Process.getEnv var
+           of SOME v => v
+            | NONE   =>
+              case List.find (fn (i, _) => i = var) (!vars)
+               of SOME (_, v) => v
+                | NONE        => error ["Undefined variable: ", var]
 
       fun expand path = let
          fun outside os =
@@ -57,8 +58,11 @@
       fun clear () = (libStack := [] ; useQueue := [])
    end
 
-   fun useLoading loading path = let
+   fun use' loading dir path = let
       val path = Var.expand path
+      val path = if OS.Path.isRelative path
+                 then OS.Path.concat (dir, path)
+                 else path
       val () = if OS.FileSys.access (path, [OS.FileSys.A_READ])
                then ()
                else error ["File ", path, " is unreadable from ",
@@ -91,10 +95,7 @@
             in
                pushLib ()
              ; after (fn () =>
-                         (app (fn file =>
-                                  useLoading
-                                     loading
-                                     (OS.Path.concat (dir, file))) paths
+                         (app (use' loading dir) paths
                         ; loaded := path :: !loaded),
                       fn () =>
                          (popLib ()
@@ -103,7 +104,7 @@
       end
    end
 
-   val use = useLoading []
+   fun use path = use' [] (OS.FileSys.getDir ()) path
 
    val use = fn path => use path handle e => (clear () ; raise e)
    val lib = fn paths => lib paths handle e => (clear () ; raise e)

Modified: mltonlib/trunk/org/mlton/vesak/use-lib/unstable/public/use-lib.sig
===================================================================
--- mltonlib/trunk/org/mlton/vesak/use-lib/unstable/public/use-lib.sig	2007-11-20 07:37:06 UTC (rev 6185)
+++ mltonlib/trunk/org/mlton/vesak/use-lib/unstable/public/use-lib.sig	2007-11-20 08:22:32 UTC (rev 6186)
@@ -17,8 +17,10 @@
  * at most once.
  *
  * Paths given to the {lib} and {use} functions may contain references to
- * environment variables, e.g. "${VARIABLE}".  The predefined variable
- * "${SML_COMPILER}" gives the mnemonic name of the SML compiler.
+ * environment variables, e.g. "${VARIABLE}".  The predefined variables
+ * "${SML_COMPILER}" and "${MLTON_LIB}" give the mnemonic name of the SML
+ * compiler and the absolute location of the root of the mltonlib tree,
+ * respectively.
  *
  * For example, suppose you have the file "foo.sig" containing the code:
  *




More information about the MLton-commit mailing list