Move ambient environment defaults into Env.env
[hcoop/domtool2.git] / src / order.sml
index 599c62a..117a0ea 100644 (file)
@@ -1,5 +1,6 @@
 (* HCoop Domtool (http://hcoop.sourceforge.net/)
  * Copyright (c) 2006, Adam Chlipala
+ * Copyright (c) 2014 Clinton Ebadi <clinton@unknownlamer.org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -134,6 +135,11 @@ fun declNeeded G (d, _, _) =
                                   NONE => expNeeded G e
                                 | SOME t => unionCTE ((typNeeded G t, SS.empty),
                                                       expNeeded G e))
+      | DEnv (name, to, e) => (Env.bindInitialDynEnvVal G (name, dt, (Ast.ESkip, ErrorMsg.dummyLoc)),
+                              case to of
+                                  NONE => expNeeded G e
+                                | SOME t => unionCTE ((typNeeded G t, SS.empty),
+                                                      expNeeded G e))
       | DContext name => (Env.bindContext G name, empty)
 
 fun fileSig (_, ds, eo) =
@@ -300,6 +306,25 @@ fun order basisOpt fnames =
            order basisOpt (List.filter (fn fname => not (SS.member (!naughtyFiles, fname))) fnames)
     end
 
+val order = fn basisOpt => fn fnames =>
+                             let
+                                 val (providers, fnames) = order basisOpt fnames
+
+                                 val (hasLib, fnames) = foldl (fn (fname, (hasLib, fnames)) =>
+                                                                  if OS.Path.file fname = "lib.dtl" then
+                                                                      (SOME fname, fnames)
+                                                                  else
+                                                                      (hasLib, fname :: fnames))
+                                                              (NONE, []) fnames
+
+                                 val fnames = rev fnames
+                                 val fnames = case hasLib of
+                                                  NONE => fnames
+                                                | SOME hasLib => hasLib :: fnames
+                             in
+                                 (providers, fnames)
+                             end
+
 type providers = {provideC : string SM.map,
                  provideT : string SM.map,
                  provideV : string SM.map}