Evaluating a test with automatic inclusion of basis
authorAdam Chlipala <adamc@hcoop.net>
Sun, 30 Jul 2006 19:30:35 +0000 (19:30 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sun, 30 Jul 2006 19:30:35 +0000 (19:30 +0000)
configDefault/domtool.cfg
configDefault/domtool.cfs
lib/alias.dtl
src/main.sig
src/main.sml
tests/domain2.dtl
tests/testAlias.dtl [new file with mode: 0644]

index 1f9f8fe..79fab00 100644 (file)
@@ -1,2 +1,2 @@
-val configRoot = "/home/adamc/cvs/domtool2/lib"
+val libRoot = "/home/adamc/cvs/domtool2/lib"
 val resultRoot = "/home/adamc/domtool"
 val resultRoot = "/home/adamc/domtool"
index 7d24e60..f8a2aec 100644 (file)
@@ -1,7 +1,7 @@
-val configRoot : string
-(* Root directory for a directory hierarchy corresponding to domain structure,
- * where each node contains files related to that domain's configuration. *)
+val libRoot : string
+(* Basis library root directory *)
 
 val resultRoot : string
 (* Root directory for a directory hierarchy corresponding to domain structure,
  * where each node contains Domtool-generated result files for that domain. *)
 
 val resultRoot : string
 (* Root directory for a directory hierarchy corresponding to domain structure,
  * where each node contains Domtool-generated result files for that domain. *)
+
index 0ced362..c591aaf 100644 (file)
@@ -29,7 +29,7 @@ extern val dropTarget : aliasTarget;
 {{Silently delete all mail to the associated source.}}
 
 extern val aliasPrim : aliasSource -> aliasTarget -> [Domain];
 {{Silently delete all mail to the associated source.}}
 
 extern val aliasPrim : aliasSource -> aliasTarget -> [Domain];
-{{Request redirection of all mail from the source to the target.}
+{{Request redirection of all mail from the source to the target.}}
 
 val alias = \user -> \email -> aliasPrim (userSource user) (addressTarget email);
 {{Redirect mail for the user at the current domain to the e-mail address.}}
 
 val alias = \user -> \email -> aliasPrim (userSource user) (addressTarget email);
 {{Redirect mail for the user at the current domain to the e-mail address.}}
@@ -41,7 +41,7 @@ val aliasDrop = \user -> aliasPrim (userSource user) dropTarget;
 
 val defaultAlias = \email -> aliasPrim defaultSource (addressTarget email);
 {{When a message to the current domain doesn't match any other alias, and it
 
 val defaultAlias = \email -> aliasPrim defaultSource (addressTarget email);
 {{When a message to the current domain doesn't match any other alias, and it
-  doesn't match any systemwide username, send it to this e-mail address
+  doesn't match any systemwide username, send it to this e-mail address.}}
 val catchAllAlias = \email -> aliasPrim catchAllSource (addressTarget email);
 {{When a message to the current domain doesn't match any other alias, send it
   to this e-mail address, even if it matches a systemwide username.}}
 val catchAllAlias = \email -> aliasPrim catchAllSource (addressTarget email);
 {{When a message to the current domain doesn't match any other alias, send it
   to this e-mail address, even if it matches a systemwide username.}}
index 46aedfb..45510b7 100644 (file)
@@ -22,8 +22,12 @@ signature MAIN = sig
 
     val tInit : Ast.typ
 
 
     val tInit : Ast.typ
 
-    val check : string -> unit
-    val reduce : string -> unit
+    val check : string -> Env.env * Ast.exp option
+    val check' : Env.env -> string -> Env.env
+
+    val basis : unit -> Env.env
+
+    val reduce : string -> Ast.exp option
     val eval : string -> unit
 
 end
     val eval : string -> unit
 
 end
index e00562a..86da95f 100644 (file)
@@ -28,73 +28,91 @@ val tInit = (TAction ((CRoot, dmy),
                      StringMap.empty,
                      StringMap.empty),
             dmy)
                      StringMap.empty,
                      StringMap.empty),
             dmy)
+
+
            
            
-fun check fname =
+fun check' G fname =
     let
     let
+       (*val _ = print ("Check " ^ fname ^ "\n")*)
        val prog = Parse.parse fname
     in
        if !ErrorMsg.anyErrors then
        val prog = Parse.parse fname
     in
        if !ErrorMsg.anyErrors then
-           ()
+           G
        else
        else
-           let
-               val G' = Tycheck.checkFile Env.empty tInit prog
-           in
-               ()
-           end
+           Tycheck.checkFile G tInit prog
     end
 
     end
 
-fun reduce fname =
+fun basis () =
     let
     let
-       val prog = Parse.parse fname
+       val dir = Posix.FileSys.opendir Config.libRoot
+
+       fun loop files =
+           case Posix.FileSys.readdir dir of
+               NONE => files
+             | SOME fname =>
+               if String.isSuffix ".dtl" fname then
+                   loop (String.concatWith "/" [Config.libRoot, fname]
+                         :: files)
+               else
+                   loop files
+
+       val files = loop []
+       val files = Order.order files
+    in
+       foldl (fn (fname, G) => check' G fname) Env.empty files
+    end
+
+fun check fname =
+    let
+       val _ = ErrorMsg.reset ()
+
+       val b = basis ()
     in
        if !ErrorMsg.anyErrors then
     in
        if !ErrorMsg.anyErrors then
-           ()
+           (b, NONE)
        else
            let
        else
            let
-               val G' = Tycheck.checkFile Env.empty tInit prog
+               val prog = Parse.parse fname
            in
                if !ErrorMsg.anyErrors then
            in
                if !ErrorMsg.anyErrors then
-                   ()
+                   (Env.empty, NONE)
                else
                else
-                   case prog of
-                       (_, _, SOME body) =>
-                       let
-                           val body' = Reduce.reduceExp G' body
-                       in
-                           printd (PD.hovBox (PD.PPS.Rel 0,
-                                              [PD.string "Result:",
-                                               PD.space 1,
-                                               p_exp body']))
-                       end
-                     | _ => ()
+                   let
+                       val G' = Tycheck.checkFile b tInit prog
+                   in
+                       (G', #3 prog)
+                   end
            end
     end
 
            end
     end
 
-fun eval fname =
+fun reduce fname =
     let
     let
-       val prog = Parse.parse fname
+       val (G, body) = check fname
     in
        if !ErrorMsg.anyErrors then
     in
        if !ErrorMsg.anyErrors then
-           ()
+           NONE
        else
        else
-           let
-               val G' = Tycheck.checkFile Env.empty tInit prog
-           in
-               if !ErrorMsg.anyErrors then
-                   ()
-               else
-                   case prog of
-                       (_, _, SOME body) =>
-                       let
-                           val body' = Reduce.reduceExp G' body
-                       in
-                           if !ErrorMsg.anyErrors then
-                               ()
-                           else
-                               Eval.exec StringMap.empty body'
-                       end
-                     | _ => ()
-           end
+           case body of
+               SOME body =>
+               let
+                   val body' = Reduce.reduceExp G body
+               in
+                   (*printd (PD.hovBox (PD.PPS.Rel 0,
+                                        [PD.string "Result:",
+                                         PD.space 1,
+                                         p_exp body']))*)
+                   SOME body'
+               end
+             | _ => NONE
     end
 
     end
 
+fun eval fname =
+    case reduce fname of
+       (SOME body') =>
+       if !ErrorMsg.anyErrors then
+           ()
+       else
+           Eval.exec StringMap.empty body'
+      | NONE => ()
+
 end
 end
dissimilarity index 83%
index 520abd1..75ffec8 100644 (file)
@@ -1,33 +1,8 @@
-extern type domain;
-extern val domain : domain -> Domain => [Root];
-
-extern type emailUser;
-extern type email;
-
-extern type aliasSource;
-extern val userSource : emailUser -> aliasSource;
-extern val defaultSource : aliasSource;
-extern val catchAllSource : aliasSource;
-
-extern type aliasTarget;
-extern val addressTarget : email -> aliasTarget;
-extern val addressesTarget : [email] -> aliasTarget;
-extern val dropTarget : aliasTarget;
-
-extern val aliasPrim : aliasSource -> aliasTarget -> [Domain];
-
-val alias = \user -> \email -> aliasPrim (userSource user) (addressTarget email);
-val aliasMulti = \user -> \emails -> aliasPrim (userSource user) (addressesTarget emails);
-val aliasDrop = \user -> aliasPrim (userSource user) dropTarget;
-
-val defaultAlias = \email -> aliasPrim defaultSource (addressTarget email);
-val catchAllAlias = \email -> aliasPrim catchAllSource (addressTarget email);
-
-domain "hcoop.net" with
-       alias "schmeppo" "dlonker";
-       aliasMulti "me" ["nowhere","smelly@yikes"];
-       aliasDrop "yippo";
-
-       defaultAlias "billy";
-       catchAllAlias "bonkers"
-end
+domain "hcoop.net" with
+       alias "schmeppo" "dlonker";
+       aliasMulti "me" ["nowhere","smelly@yikes"];
+       aliasDrop "yippo";
+
+       defaultAlias "billy";
+       catchAllAlias "bonkers"
+end
diff --git a/tests/testAlias.dtl b/tests/testAlias.dtl
new file mode 100644 (file)
index 0000000..75ffec8
--- /dev/null
@@ -0,0 +1,8 @@
+domain "hcoop.net" with
+       alias "schmeppo" "dlonker";
+       aliasMulti "me" ["nowhere","smelly@yikes"];
+       aliasDrop "yippo";
+
+       defaultAlias "billy";
+       catchAllAlias "bonkers"
+end