Fix file paths for recursive rmdom
[hcoop/domtool2.git] / src / order.sml
index cf1dee1..2923c19 100644 (file)
@@ -70,7 +70,7 @@ fun unionCTE (((c1, t1), v1), ((c2, t2), v2)) =
     
 val dt = (TError, ErrorMsg.dummyLoc)
 
-fun expNeeded G (e, _) =
+fun expNeeded G (e, loc) =
     case e of
        EInt _ => ((SS.empty,
                    if Env.lookupType G "int" then
@@ -96,6 +96,13 @@ fun expNeeded G (e, _) =
              | SOME t => unionCTE ((typNeeded G t, SS.empty),
                                    expNeeded G' e)
        end
+      | EALam (x, p, e) =>
+       let
+           val G' = Env.bindVal G (x, (TAction (p, StringMap.empty, StringMap.empty), loc), NONE)
+       in
+           unionCTE (((predNeeded G p, SS.empty), SS.empty),
+                     expNeeded G' e)
+       end
       | EVar x =>
        (case Env.lookupVal G x of
             NONE => ((SS.empty, SS.empty), SS.singleton x)
@@ -167,7 +174,7 @@ fun mergeProvide kind fname (m1, m2) =
                  SM.insert (provide, name, fname)))
     m1 m2
 
-fun order fnames =
+fun order basisOpt fnames =
     let
        fun doFile (fname, (provideC, provideT, provideV, require)) =
            let
@@ -186,25 +193,38 @@ fun order fnames =
 
        val require = SM.mapi (fn (fname, ((rc, rt), rv)) =>
                                  let
-                                     fun consider (kind, provide) =
+                                     fun consider (kind, provide, lastChance) =
                                          SS.foldl (fn (name, need) =>
                                                       case SM.find (provide, name) of
-                                                          NONE => (ErrorMsg.error NONE
-                                                                   ("File "
-                                                                    ^ fname
-                                                                    ^ " uses undefined "
-                                                                    ^ kind
-                                                                    ^ " "
-                                                                    ^ name);
-                                                                   need)
+                                                          NONE =>
+                                                          if lastChance name then
+                                                              need
+                                                          else
+                                                              (ErrorMsg.error NONE
+                                                                              ("File "
+                                                                               ^ fname
+                                                                               ^ " uses undefined "
+                                                                               ^ kind
+                                                                               ^ " "
+                                                                               ^ name);
+                                                               need)
                                                         | SOME fname' =>
                                                           SS.add (need, fname'))
 
-                                     val need = consider ("context", provideC)
+                                     val need = consider ("context", provideC,
+                                                          case basisOpt of
+                                                              NONE => (fn _ => false)
+                                                            | SOME b => Env.lookupContext b)
                                                          SS.empty rc
-                                     val need = consider ("type", provideT)
+                                     val need = consider ("type", provideT,
+                                                          case basisOpt of
+                                                              NONE => (fn _ => false)
+                                                            | SOME b => Env.lookupType b)
                                                          need rt
-                                     val need = consider ("value", provideV)
+                                     val need = consider ("value", provideV,
+                                                          case basisOpt of
+                                                              NONE => (fn _ => false)
+                                                            | SOME b => (fn name => Option.isSome (Env.lookupVal b name)))
                                                          need rv
                                  in
                                      need