]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/helena/src/toplevel/top.ml
jet a change in dependences
[helm.git] / helm / software / helena / src / toplevel / top.ml
index 984933290764364f3ecd8d71f088efcbeead5f00..b7c6fc1355c056329c416075b81d83953f4ea732 100644 (file)
       V_______________________________________________________________ *)
 
 module KF = Filename
+module KL = List
 module KP = Printf
 module KS = String
+module KT = String
 
 module U  = NUri
 module C  = Cps
@@ -37,7 +39,7 @@ module BR = BrgReduction
 module BU = BrgUntrusted
 module BG = BrgGrafite
 module BA = BrgGallina
-module BP = BrgELPI
+module BP = BrgLP
 module ZD = BagCrg
 module ZO = BagOutput
 module ZT = BagType
@@ -87,17 +89,16 @@ type kernel_entity = BrgEntity of Brg.entity
                    | BagEntity of Bag.entity
                   | CrgEntity of Crg.entity
 
+IFDEF SUMMARY THEN
+
 let print_counters st = function
    | 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.V3, CrgEntity e -> 
-      let f e = (BrgEntity e) in E.xlate f BD.brg_of_crg e
-   | G.V0, CrgEntity e -> 
-      let f e = (BagEntity e) in E.xlate f (ZD.bag_of_crg st.kst) e
-   | _, entity          -> entity
+END
+
+IFDEF TRACE THEN
 
 let pp_progress e =
    let f _ na u =
@@ -110,16 +111,28 @@ let pp_progress e =
       | BrgEntity e -> E.common f e
       | BagEntity e -> E.common f e      
 
+END
+
+IFDEF SUMMARY THEN
+
 let count_entity st = function
    | BrgEntity e -> {st with bc = BO.count_entity C.start st.bc e}
    | BagEntity e -> {st with zc = ZO.count_entity C.start st.zc e}
    | CrgEntity e -> {st with dc = DO.count_entity C.start st.dc e}
 
+END
+
+IFDEF OBJECTS THEN
+
 let export_entity st = function
    | 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
 
+END
+
+IFDEF TYPE THEN
+
 let type_check st k =
    let brg_err msg = brg_error st "Type Error" msg; failwith "Interrupted" in
    let bag_err msg = bag_error st "Type Error" msg; failwith "Interrupted" in
@@ -129,13 +142,9 @@ let type_check st k =
       | BagEntity entity -> ZU.type_check bag_err ok st.kst entity
       | CrgEntity _      -> st
 
-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 -> BU.validate brg_err ok st.kst entity
-      | BagEntity _      -> st
-      | CrgEntity _      -> st
+END
+
+IFDEF MANAGER THEN
 
 let manager st output_entity = function
    | BrgEntity entity -> 
@@ -144,6 +153,23 @@ let manager st output_entity = function
    | BagEntity _      -> st
    | CrgEntity _      -> st
 
+END
+
+let xlate_entity st entity = match !G.kernel, entity with
+   | G.V3, CrgEntity e -> 
+      let f e = (BrgEntity e) in E.xlate f BD.brg_of_crg e
+   | G.V0, CrgEntity e -> 
+      let f e = (BagEntity e) in E.xlate f (ZD.bag_of_crg st.kst) e
+   | _, entity         -> entity
+
+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 -> BU.validate brg_err ok st.kst entity
+      | BagEntity _      -> st
+      | CrgEntity _      -> st
+
 (* extended lexer ***********************************************************)
 
 type 'token lexer = {
@@ -204,45 +230,88 @@ let entity_of_input lexbuf i = match i, !parbuf with
    | Text, hd :: tl ->
       parbuf := tl; hd
 
+IFDEF PREPROCESS THEN
+
 let process_input f st = function 
    | AutEntity e     ->
       let f pst e = f {st with pst = pst} (AutEntity e) in
       AA.process_command f st.pst e
    | xe              -> f st xe
 
+END
+
+IFDEF SUMMARY THEN
+
 let count_input st = function
    | AutEntity e -> {st with ac = AO.count_command C.start st.ac e}
    | xe          -> st
 
+END
+
 (****************************************************************************)
 
-let version = ref true
-let preprocess = ref false
-let root = ref ""
-let export = ref false
 let st = ref (initial_status ())
 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
+   let st =
+IFDEF SUMMARY THEN
+      if !G.summary then count_entity st entity else st
+ELSE 
+      st
+END
+   in
+   let st =
+IFDEF STAGE THEN
+      if !G.stage >= 3 then
+IFDEF TYPE THEN 
+         let f = if !G.validate then validate else type_check in f st entity
+ELSE
+         validate st entity
+END
       else st
+ELSE
+IFDEF TYPE THEN 
+      let f = if !G.validate then validate else type_check in f st entity
+ELSE
+      validate st entity
+END
+END
    in
-   if !export then export_entity st entity;
+IFDEF OBJECTS THEN
+   if !G.export then export_entity st entity
+ELSE () END;
+IFDEF MANAGER THEN
    match st.mst with
      | None                    -> st
      | Some (export_entity, _) -> manager st export_entity entity
+ELSE
+     st
+END
 
-let process_1 st entity = 
+let process_1 st entity =
+IFDEF TRACE THEN
    if !G.ct >= 3 then pp_progress entity;
-   let st = if !G.summary then count_entity st entity else st in
-   if !export && !G.stage = 1 then export_entity st entity;
+ELSE () END;
+   let st =
+IFDEF SUMMARY THEN
+      if !G.summary then count_entity st entity else st
+ELSE
+      st
+END
+   in
+IFDEF STAGE THEN
+IFDEF OBJECTS THEN
+   if !G.export && !G.stage = 1 then export_entity st entity
+ELSE () END;
    if !G.stage >= 2 then process_2 st (xlate_entity st entity) else st 
+ELSE
+   process_2 st (xlate_entity st entity)
+END
 
 let process_0 st entity = 
    let f st entity =
+IFDEF STAGE THEN
       if !G.stage = 0 then st else
       match entity with
          | AutEntity e -> 
@@ -254,9 +323,31 @@ let process_0 st entity =
             let d tst e = process_1 {st with tst = tst} (CrgEntity e) in
            TD.crg_of_txt crr d gen_text st.tst e
         | NoEntity    -> assert false
+ELSE
+      match entity with
+         | AutEntity e -> 
+            let err ast = {st with ast = ast} in
+            let g ast e = process_1 {st with ast = ast} (CrgEntity e) in
+           AD.crg_of_aut err g st.kst st.ast e
+         | TxtEntity e -> 
+            let crr tst = {st with tst = tst} in
+            let d tst e = process_1 {st with tst = tst} (CrgEntity e) in
+           TD.crg_of_txt crr d gen_text st.tst e
+        | NoEntity    -> assert false
+END
    in
-   let st = if !G.summary then count_input st entity else st in 
-   if !preprocess then process_input f st entity else f st entity
+   let st =
+IFDEF SUMMARY THEN
+      if !G.summary then count_input st entity else st
+ELSE
+      st
+END
+   in 
+IFDEF PREPROCESS THEN
+   if !G.preprocess then process_input f st entity else f st entity
+ELSE
+   f st entity
+END
 
 let process_nostreaming st lexbuf input =
    let id x = x in
@@ -279,6 +370,52 @@ let process_streaming st lexbuf input =
 
 (****************************************************************************)
 
+IFDEF PREPROCESS THEN
+
+let set_preprocess () = 
+   if !G.trace >= 2 then begin
+      G.preprocess := true;
+IFDEF SUMMARY THEN
+      G.summary := true
+ELSE () END
+   end
+
+END
+
+IFDEF MANAGER THEN
+
+let set_manager s = match KS.lowercase s with
+   | "v8"  -> G.manager := G.Coq
+   | "ma2" -> G.manager := G.Matita
+   | "lp1" -> G.manager := G.LP1
+   | "lp2" -> G.manager := G.LP2
+   | "tj2" -> G.manager := G.TJ2
+   | "tj3" -> G.manager := G.TJ3
+   | s     -> L.warn level (KP.sprintf "Unknown manager: %s" s)
+
+END
+
+IFDEF SUMMARY THEN
+
+let set_summary () =
+   if !G.trace >= 2 then G.summary := true
+
+END
+
+let set_trace i = 
+   if !G.trace = 0 && i > 0 then Y.gmtime (G.version_string false);
+   if !G.trace > 0 && i = 0 then Y.utime_stamp "at exit";
+   G.trace := i;
+IFDEF SUMMARY THEN
+   if i <= 1 then G.summary := false
+ELSE () END;
+IFDEF PREPROCESS THEN
+   if i <= 1 then G.preprocess := false
+ELSE () END
+
+let custom_exit () =
+   if !G.trace >= 1 then Y.utime_stamp "at exit"
+
 let process st name =
    let process = if !streaming then process_streaming else process_nostreaming in
    let input = type_of_input name in
@@ -289,7 +426,26 @@ let process st name =
    st, input
 
 let main = 
-   let print_version () = L.warn level (G.version_string ^ "\n"); exit 0 in
+   let print_version () =
+      let features = [
+(IFDEF LEXER THEN "LEXER" ELSE "" END);
+(IFDEF PARSER THEN "PARSER" ELSE "" END);
+(IFDEF TRACE THEN "TRACE" ELSE "" END);
+(IFDEF SUMMARY THEN "SUMMARY" ELSE "" END);
+(IFDEF EXPAND THEN "EXPAND" ELSE "" END);
+(IFDEF MANAGER THEN "MANAGER" ELSE "" END);
+(IFDEF OBJECTS THEN "OBJECTS" ELSE "" END);
+(IFDEF PREPROCESS THEN "PREPROCESS" ELSE "" END);
+(IFDEF QUOTE THEN "QUOTE" ELSE "" END);
+(IFDEF STAGE THEN "STAGE" ELSE "" END);
+(IFDEF TYPE THEN "TYPE" ELSE "" END);
+(IFDEF PROFV THEN "PROFV" ELSE "" END);
+      ] in
+      let map s = s <> "" in
+      let features_string = KT.concat " " (KL.filter map features) in
+      L.warn level (KP.sprintf "%s [%s]" (G.version_string true) features_string);
+      exit 0
+   in
    let set_hierarchy s = 
       if H.set_graph s then () else 
          L.warn level (KP.sprintf "Unknown type hierarchy: %s" s)
@@ -299,47 +455,40 @@ let main =
       | "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;
-      if !G.trace > 0 && i = 0 then Y.utime_stamp "at exit";
-      G.trace := i;
-      if i <= 1 then G.summary := false;
-      if i <= 1 then preprocess := false
-   in
-   let set_summary () = 
-      if !G.trace >= 2 then G.summary := true
-   in 
-   let set_preprocess () = 
-      if !G.trace >= 2 then begin preprocess := true; G.summary := true end 
-   in
-   let set_manager s = match KS.lowercase s with
-      | "v8"    -> G.manager := G.Coq
-      | "ma2"   -> G.manager := G.Matita
-      | "elpi1" -> G.manager := G.ELPI1
-      | "elpi2" -> G.manager := G.ELPI2
-      | s       -> L.warn level (KP.sprintf "Unknown manager: %s" s) 
-   in
    let clear_options () =
-      export := false; preprocess := false;
-      root := "";
-      G.clear (); H.clear (); O.clear_reductions ();
+      G.clear (); H.clear ();
+IFDEF SUMMARY THEN
+      O.clear_reductions ()
+ELSE () END;
       streaming := false;
-      version := true
    in
+   let undefined opt () =
+      L.warn level (KP.sprintf "%s was compiled without the support for option %s" (G.version_string true) opt);
+      exit 0
+   in
+   let arg_undefined opt = Arg.Unit (undefined opt) in 
    let process_file name =
-      if !G.trace >= 2 then L.warn 1 (KP.sprintf "Processing file: %s" name);
-      if !G.trace >= 2 then Y.utime_stamp "started";
+      if !G.trace >= 2 then begin
+         L.warn 1 (KP.sprintf "Processing file: %s" name);
+         Y.utime_stamp "started"
+      end;
       let base_name = Filename.chop_extension (Filename.basename name) in
-      let cover = KF.concat !root base_name in
-      if !G.stage <= 1 then G.kernel := G.V4;
+      let cover = KF.concat !G.root base_name in
       G.cover := cover;
+IFDEF STAGE THEN
+      if !G.stage <= 1 then G.kernel := G.V4;
+ELSE () END;
+IFDEF MANAGER THEN
       begin match !G.manager with
          | G.Coq    -> st := {!st with mst = Some (BA.open_out base_name)}
          | G.Matita -> st := {!st with mst = Some (BG.open_out base_name)}
-         | G.ELPI1  -> st := {!st with mst = Some (BP.open_out_1 base_name)}
-         | G.ELPI2  -> st := {!st with mst = Some (BP.open_out_2 base_name)}
+         | G.LP1    -> st := {!st with mst = Some (BP.open_out_lp1 base_name)}
+         | G.LP2    -> st := {!st with mst = Some (BP.open_out_lp2 base_name)}
+         | G.TJ2    -> st := {!st with mst = Some (BP.open_out_tj2 base_name)}
+         | G.TJ3    -> st := {!st with mst = Some (BP.open_out_tj3 base_name)}
          | G.Quiet  -> ()
-      end;
+      end
+ELSE () END;
       P.clear_marks ();
       let sst, input = process (refresh_status !st) name in
       st := begin match sst.mst with 
@@ -347,81 +496,91 @@ let main =
          | Some (_, close_out) -> close_out (); {sst with mst = None}
       end;
       if !G.trace >= 2 then Y.utime_stamp "processed";
+IFDEF SUMMARY THEN
       if !G.summary then begin
          AO.print_counters C.start !st.ac;
-         if !preprocess then AO.print_process_counters C.start !st.pst;
+IFDEF PREPROCESS THEN
+         if !G.preprocess then AO.print_process_counters C.start !st.pst
+ELSE () END;
+IFDEF STAGE THEN
          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 ()
+ELSE
+         print_counters !st G.V4;
+         print_counters !st !G.kernel;
+         O.print_reductions ()
+END
       end
-   in
-   let exit () =
-      if !G.trace >= 1 then Y.utime_stamp "at exit"
+ELSE () END
    in
    let help = 
-      "Usage: helena [ -LPVXdgilnopqtx1 | -Ts <number> | -MO <dir> | -c <file> | -ahkmr <string> | -be <age> ]* [ <file> ]*\n\n" ^
+      "Usage: helena [ -LPVXdgilnoqtuxy01 | -Ts <number> | -MO <dir> | -p <file> | -ahkmr <string> | -be <age> ]* [ <file> ]*\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\n" ^
-      "Supported manages: \"ma2\" (Grafite NG), \"v8\" (Gallina 8), \"elpi1\" \"elpi2\" (lambda-Prolog)\n" 
+      "Supported manages: \"ma2\" (Grafite NG), \"v8\" (Gallina 8), \"lp1\" \"lp2\" \"tj2\" (lambda-Prolog)\n" 
    in
-   let help_L = " show lexer debug information" in 
-   let help_M = "<dir>  set location of output directory (manager) to <dir> (default: current directory)" in
-   let help_O = "<dir>  set location of output directory (XML) to <dir> (default: current directory)" in
-   let help_P = " show parser debug information" in 
-   let help_T = "<number>  set trace level (see above)" in
-   let help_V = " show version information" in
-   let help_X = " clear options" in
-   
-   let help_a = "<string>  set prefix of numeric identifiers (default: empty)" in
-   let help_b = "<age>  begin trace at this global constant (default: first)" in
-   let help_c = "<file>  set preamble to this file (default: empty)" in
-   let help_d = " show summary information (requires trace >= 2)" in
-   let help_e = "<age>  end trace at this global constant (default: last)" in
-   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: \"V3\")" in
-   let help_l = " disambiguate binders layer (Automath)" in
-   let help_m = "<string>  export kernel entities for this manager (see above, default: no manager)" in
-   let help_n = " use extended (i.e. native) applications (Automath)" in
-   let help_o = " activate sort inclusion (default: false)" in
-   let help_p = " preprocess source (Automath)" in
-   let help_q = " disable quotation of identifiers" in
-   let help_r = "<string>  set initial segment of URI hierarchy (default: empty)" in
-   let help_s = "<number>  set translation stage (see above)" in
-   let help_t = " type check (version 1)" in
-   let help_x = " export kernel entities (XML)" in
+   let help_L = "         [lexer]     Show lexer debug information" in 
+   let help_M = "<dir>    [manager]   Set location of output directory (manager) to <dir> (default: current directory)" in
+   let help_O = "<dir>    [output]    Set location of output directory (XML) to <dir> (default: current directory)" in
+   let help_P = "         [parser]    Show parser debug information" in 
+   let help_T = "<number> [trace]     Set trace level (see above)" in
+   let help_V = "         [version]   Show version information" in
+   let help_X = "                     Clear options" in
    
-   let help_1 = " parse files with streaming policy" in
-   at_exit exit;
+   let help_a = "<string> [alpha]     Set prefix of numeric identifiers (default: empty)" in
+   let help_b = "<age>    [begin]     Begin trace at this global constant (default: first)" in
+   let help_d = "         [data]      Show summary information (requires trace >= 2)" in
+   let help_e = "<age>    [end]       End trace at this global constant (default: last)" in
+   let help_g = "         [global]    Disable age-driven expansion of global definitions (default: enable)" in
+   let help_h = "<string> [hierarchy] Set type hierarchy (default: \"Z1\")" in
+   let help_i = "         [indexes]   Show local references by index" in
+   let help_k = "<string> [kernel]    Set kernel version (default: \"V3\")" in
+   let help_l = "         [layer]     Disambiguate binders layer (Automath)" in
+   let help_m = "<string> [manager]   Export kernel entities for this manager (see above, default: no manager)" in
+   let help_n = "         [names]     Show short constants (default: qualified constants)" in
+   let help_o = "         [objects]   Export kernel entities (XML)" in
+   let help_p = "<file>   [preamble]  Set preamble to this file (default: empty)" in
+   let help_q = "         [quote]     Quote identifiers (default: disable)" in
+   let help_r = "<string> [root]      Set initial segment of URI hierarchy (default: empty)" in
+   let help_s = "<number> [stage]     Set translation stage (see above)" in
+   let help_t = "         [type]      Type check (default: validate)" in
+   let help_u = "         [upsilon]   Activate type comparison by sort inclusion (default: deactivate)" in
+   let help_x = "         [extended]  Use extended applications (Automath)" in
+   let help_y = "         [infinity]  Use ∞-abstractions in contexts" in
+   let help_0 = "         [zero]      Preprocess source (Automath)" in
+   let help_1 = "         [one]       parse files with streaming policy" in
+   at_exit custom_exit;
    Arg.parse [
-      ("-L", Arg.Set G.debug_lexer, help_L);
-      ("-M", Arg.String ((:=) G.manager_dir), help_M);
-      ("-O", Arg.String ((:=) G.xdir), help_O);
-      ("-P", Arg.Set G.debug_parser, help_P);
+      ("-L", (IFDEF LEXER THEN Arg.Set G.debug_lexer ELSE arg_undefined "-L" END), help_L);
+      ("-M", (IFDEF MANAGER THEN Arg.String ((:=) G.manager_dir) ELSE arg_undefined "-M" END), help_M);
+      ("-O", (IFDEF OBJECTS THEN Arg.String ((:=) G.xdir) ELSE arg_undefined "-O" END), help_O);
+      ("-P", (IFDEF PARSER THEN Arg.Set G.debug_parser ELSE arg_undefined "-P" END), help_P);
       ("-T", Arg.Int set_trace, help_T);
       ("-V", Arg.Unit print_version, help_V);
       ("-X", Arg.Unit clear_options, help_X);
       ("-a", Arg.String ((:=) G.alpha), help_a);
       ("-b", Arg.Int ((:=) G.first), help_b);
-      ("-c", Arg.String ((:=) G.preamble), help_c);
-      ("-d", Arg.Unit set_summary, help_d);
+      ("-d", (IFDEF SUMMARY THEN Arg.Unit set_summary ELSE arg_undefined "-d" END), help_d);
       ("-e", Arg.Int ((:=) G.last), help_e);
-      ("-g", Arg.Set G.expand, help_g);
+      ("-g", (IFDEF EXPAND THEN Arg.Set G.expand ELSE arg_undefined "-g" END), help_g);
       ("-h", Arg.String set_hierarchy, help_h);
       ("-i", Arg.Set G.indexes, help_i);
       ("-k", Arg.String set_kernel, help_k);
       ("-l", Arg.Set G.cc, help_l);
-      ("-m", Arg.String set_manager, help_m);      
-      ("-n", Arg.Set G.extended, help_n);
-      ("-o", Arg.Set G.si, help_o);
-      ("-p", Arg.Unit set_preprocess, help_p);
-      ("-q", Arg.Set G.unquote, help_q);      
-      ("-r", Arg.String ((:=) root), help_r);
-      ("-s", Arg.Int ((:=) G.stage), help_s);
-      ("-t", Arg.Clear version, help_t);      
-      ("-x", Arg.Set export, help_x);
+      ("-m", (IFDEF MANAGER THEN Arg.String set_manager ELSE arg_undefined "-m" END), help_m);      
+      ("-n", Arg.Set G.short, help_n);
+      ("-o", (IFDEF OBJECTS THEN Arg.Set G.export ELSE arg_undefined "-o" END), help_o);
+      ("-p", (IFDEF MANAGER THEN Arg.String ((:=) G.preamble) ELSE arg_undefined "-p" END), help_p);
+      ("-q", (IFDEF QUOTE THEN Arg.Set G.quote ELSE arg_undefined "-q" END), help_q);
+      ("-r", Arg.String ((:=) G.root), help_r);
+      ("-s", (IFDEF STAGE THEN Arg.Int ((:=) G.stage) ELSE arg_undefined "-s" END), help_s);
+      ("-t", (IFDEF TYPE THEN Arg.Clear G.validate ELSE arg_undefined "-t" END), help_t);
+      ("-u", Arg.Set G.si, help_u);
+      ("-x", Arg.Set G.extended, help_x);
+      ("-y", Arg.Set G.infinity, help_y);
+      ("-0", (IFDEF PREPROCESS THEN Arg.Unit set_preprocess ELSE arg_undefined "-0" END), help_0);
       ("-1", Arg.Set streaming, help_1);      
    ] process_file help