]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/helena/src/toplevel/top.ml
- bugfix is refreshed state of AutCrg: now we return a fresh state
[helm.git] / helm / software / helena / src / toplevel / top.ml
index 535450c1f155d7b6a2a556818833eaa6e77c0d10..66baa8658c49a6fe6cbe3feebebd4a14517521d4 100644 (file)
@@ -9,18 +9,19 @@
      \ /   This software is distributed as is, NO WARRANTY.              
       V_______________________________________________________________ *)
 
-module  = Filename
-module  = Printf
+module KF = Filename
+module KP = Printf
 
 module U  = NUri
 module C  = Cps
 module L  = Log
 module Y  = Time
+module P  = Marks
 module G  = Options
 module H  = Hierarchy
+module N  = Layer
 module E  = Entity
 module O  = Output
-module S  = Status
 module DO = CrgOutput
 module TD = TxtCrg
 module AA = AutProcess
@@ -39,7 +40,7 @@ module ZT = BagType
 module ZU = BagUntrusted
 
 type status = {
-   kst: S.status;
+   kst: N.status;
    tst: TD.status;
    pst: AA.status;
    ast: AD.status;
@@ -53,13 +54,13 @@ type status = {
 let level = 0
 
 let bag_error st s msg =
-   L.error st.kst.S.lenv ZO.specs (L.Warn s :: msg) 
+   L.error st.kst ZO.specs (L.Warn s :: msg) 
 
 let brg_error st s msg =
-   L.error st.kst.S.lenv BR.specs (L.Warn s :: msg)
+   L.error st.kst BR.specs (L.Warn s :: msg)
 
 let initial_status () = {
-   kst = S.initial_status ();
+   kst = N.initial_status ();
    tst = TD.initial_status ();
    pst = AA.initial_status ();
    ast = AD.initial_status ();
@@ -71,7 +72,7 @@ let initial_status () = {
 }
 
 let refresh_status st = {st with
-   kst = S.refresh_status st.kst;
+   kst = N.refresh_status st.kst;
    tst = TD.refresh_status st.tst;
    ast = AD.refresh_status st.ast;
 }
@@ -83,22 +84,23 @@ type kernel_entity = BrgEntity of Brg.entity
                   | CrgEntity of Crg.entity
 
 let print_counters st = function
-   | G.Crg -> DO.print_counters C.start st.dc
-   | G.Brg -> BO.print_counters C.start st.bc
-   | G.Bag -> ZO.print_counters C.start st.zc
+   | G.V4 -> DO.print_counters C.start st.dc
+   | G.V3 -> BO.print_counters C.start st.bc
+   | G.V0 -> ZO.print_counters C.start st.zc
 
 let xlate_entity st entity = match !G.kernel, entity with
-   | G.Brg, CrgEntity e -> 
+   | G.V3, CrgEntity e -> 
       let f e = (BrgEntity e) in E.xlate f BD.brg_of_crg e
-   | G.Bag, CrgEntity e -> 
-      let f e = (BagEntity e) in E.xlate f (ZD.bag_of_crg st.kst.S.lenv) e
+   | G.V0, CrgEntity e -> 
+      let f e = (BagEntity e) in E.xlate f (ZD.bag_of_crg st.kst) e
    | _, entity          -> entity
 
 let pp_progress e =
    let f _ na u =
       let s = U.string_of_uri u in
-      L.warn 2 (P.sprintf "[%u] <%s>" na.E.n_apix s)
+      L.warn 2 (KP.sprintf "[%u] <%s>" na.E.n_apix s);
    in
+   Y.utime_stamp "intermediate";
    match e with
       | CrgEntity e -> E.common f e
       | BrgEntity e -> E.common f e
@@ -110,9 +112,9 @@ let count_entity st = function
    | CrgEntity e -> {st with dc = DO.count_entity C.start st.dc e}
 
 let export_entity st = function
-   | CrgEntity e -> XL.export_entity (XD.export_term st.kst.S.lenv) e
-   | BrgEntity e -> XL.export_entity (BO.export_term st.kst.S.lenv) e
-   | BagEntity e -> XL.export_entity (ZO.export_term st.kst.S.lenv) e
+   | CrgEntity e -> XL.export_entity (XD.export_term st.kst) e
+   | BrgEntity e -> XL.export_entity (BO.export_term st.kst) e
+   | BagEntity e -> XL.export_entity (ZO.export_term st.kst) e
 
 let type_check st k =
    let brg_err msg = brg_error st "Type Error" msg; failwith "Interrupted" in
@@ -127,17 +129,17 @@ let validate st k =
    let brg_err msg = brg_error st "Validation Error" msg; failwith "Interrupted" in
    let ok _ = st in
    match k with
-      | BrgEntity entity -> 
-         let st = BU.validate brg_err ok st.kst entity in
-         begin match st.och with
-            | None     -> st
-            | Some och -> 
-               if BG.output_entity st.kst.S.lenv och entity then st
-               else begin L.warn level "Matita exportation stopped"; {st with och = None} end
-         end
+      | BrgEntity entity -> BU.validate brg_err ok st.kst entity
       | BagEntity _      -> st
       | CrgEntity _      -> st
 
+let grafite st och = function
+   | BrgEntity entity -> 
+      if BG.output_entity st.kst och entity then st else
+      begin L.warn level "Matita exportation stopped"; {st with och = None} end
+   | BagEntity _      -> st
+   | CrgEntity _      -> st
+
 (* extended lexer ***********************************************************)
 
 type 'token lexer = {
@@ -166,13 +168,13 @@ type input_entity = TxtEntity of Txt.command
                  | NoEntity
 
 let type_of_input name =
-   if F.check_suffix name ".hln" then Text 
-   else if F.check_suffix name ".aut" then 
+   if KF.check_suffix name ".hln" then Text 
+   else if KF.check_suffix name ".aut" then 
       let _ = H.set_sorts 0 ["Set"; "Prop"] in
       assert (H.set_graph "Z2");
       Automath
    else begin
-      L.warn level (P.sprintf "Unknown file type: %s" name); exit 2
+      L.warn level (KP.sprintf "Unknown file type: %s" name); exit 2
    end
 
 let txt_xl = initial_lexer TxtLexer.token 
@@ -219,11 +221,15 @@ let streaming = ref false (* parsing style (temporary) *)
 
 let process_2 st entity =
    let st = if !G.summary then count_entity st entity else st in
+   let st = 
+      if !G.stage >= 3 then 
+         let f = if !version then validate else type_check in f st entity
+      else st
+   in
    if !export then export_entity st entity;
-   if !G.stage >= 3 then 
-      let f = if !version then validate else type_check in 
-      f st entity
-   else st
+   match st.och with
+     | None     -> st
+     | Some och -> grafite st och entity
 
 let process_1 st entity = 
    if !G.trace >= 3 then pp_progress entity;
@@ -275,20 +281,19 @@ let process st name =
    let ich = open_in name in
    let lexbuf = Lexing.from_channel ich in 
    let st = process st lexbuf input in
-   close_in ich; 
-(*   if !G.cc then XL.export_csys st.kst.S.cc; *)
+   close_in ich;
    st, input
 
 let main = 
    let print_version () = L.warn level (G.version_string ^ "\n"); exit 0 in
    let set_hierarchy s = 
       if H.set_graph s then () else 
-         L.warn level (P.sprintf "Unknown type hierarchy: %s" s)
+         L.warn level (KP.sprintf "Unknown type hierarchy: %s" s)
    in
    let set_kernel = function
-      | "brg" -> G.kernel := G.Brg
-      | "bag" -> G.kernel := G.Bag
-      | s     -> L.warn level (P.sprintf "Unknown kernel version: %s" s)
+      | "V3" -> G.kernel := G.V3
+      | "V0" -> G.kernel := G.V0
+      | s    -> L.warn level (KP.sprintf "Unknown kernel version: %s" s)
    in
    let set_trace i = 
       if !G.trace = 0 && i > 0 then Y.gmtime G.version_string;
@@ -306,19 +311,19 @@ let main =
    let clear_options () =
       export := false; preprocess := false;
       root := "";
-      st := initial_status ();
       G.clear (); H.clear (); O.clear_reductions ();
       streaming := false;
       version := true
    in
    let process_file name =
-      if !G.trace >= 2 then L.warn 1 (P.sprintf "Processing file: %s" name);
+      if !G.trace >= 2 then L.warn 1 (KP.sprintf "Processing file: %s" name);
       if !G.trace >= 2 then Y.utime_stamp "started";
       let base_name = Filename.chop_extension (Filename.basename name) in
-      let cover = F.concat !root base_name in
-      if !G.stage <= 1 then G.kernel := G.Crg;
+      let cover = KF.concat !root base_name in
+      if !G.stage <= 1 then G.kernel := G.V4;
       G.cover := cover;
       if !G.ma_preamble <> "" then st := {!st with och = Some (BG.open_out base_name)};
+      P.clear_marks ();
       let sst, input = process (refresh_status !st) name in
       st := begin match sst.och with 
          | None     -> sst
@@ -328,7 +333,7 @@ let main =
       if !G.summary then begin
          AO.print_counters C.start !st.ac;
          if !preprocess then AO.print_process_counters C.start !st.pst;
-         if !G.stage >= 1 then print_counters !st G.Crg;
+         if !G.stage >= 1 then print_counters !st G.V4;
          if !G.stage >= 2 then print_counters !st !G.kernel;
          if !G.stage >= 3 then O.print_reductions ()
       end
@@ -338,8 +343,9 @@ let main =
    in
    let help = 
       "Usage: helena [ -LPVXdgilopqtx1 | -Ts <number> | -MO <dir> | -m <file> | -ahkr <string> ]* [ <file> ]*\n\n" ^
-      "Trace levels: 0 just errors (default), 1 time stamps, 2 processed files, 3 typing information,\n" ^
-      "              4 conversion information, 5 reduction information, 6 level disambiguation\n\n" ^
+      "Trace levels: 0 just errors (default), 1 time stamps, 2 processed files, 3 processed objects,\n" ^
+      "              4 typing information, 5 conversion information, 6 reduction information,\n" ^
+      "              7 level disambiguation\n\n" ^
       "Stages: 0 parsing, 1 to intermediate, 2 to untrusted, 3 to trusted (default)\n"
    in
    let help_L = " show lexer debug information" in 
@@ -355,7 +361,7 @@ let main =
    let help_g = " always expand global definitions" in
    let help_h = "<string>  set type hierarchy (default: \"Z1\")" in
    let help_i = " show local references by index" in
-   let help_k = "<string>  set kernel version (default: \"brg\")" in
+   let help_k = "<string>  set kernel version (default: \"V3\")" in
    let help_l = " disambiguate binders level (Automath)" in
    let help_m = "<file>  export kernel entities (Grafite) setting location of preamble to <file> (default: empty)" in   
    let help_o = " activate sort inclusion (default: false)" in
@@ -392,4 +398,4 @@ let main =
       ("-t", Arg.Clear version, help_t);      
       ("-x", Arg.Set export, help_x);
       ("-1", Arg.Set streaming, help_1);      
-   ] process_file help;
+   ] process_file help