1 (* Copyright (C) 2004-2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
30 (** {2 Initialization} *)
34 let run_script is eval_function =
37 | None -> assert false
40 let slash_n_RE = Pcre.regexp "\\n" in
42 if Helm_registry.get_bool "matita.quiet" then
46 (* dump_status status; *)
47 let stm = GrafiteAstPp.pp_statement stm in
48 let stm = Pcre.replace ~rex:slash_n_RE stm in
50 if String.length stm > 50 then
51 String.sub stm 0 50 ^ " ..."
55 MatitaLog.debug ("Executing: ``" ^ stm ^ "''"))
58 eval_function status is cb
62 | CicNotationParser.Parse_error _ as exn -> raise exn
64 MatitaLog.error (MatitaExcPp.to_string exn);
68 match Helm_registry.get_list Helm_registry.string "matita.args" with
70 | _ -> MatitaInit.die_usage ()
72 let pp_ocaml_mode () =
74 MatitaLog.message " ** Entering Ocaml mode ** ";
76 MatitaLog.message "Type 'go ();;' to enter an interactive matitac";
89 let baseuri = MatitaTypes.get_string_option !status "baseuri" in
90 MatitacleanLib.clean_baseuris ~verbose:false [baseuri];
92 with MatitaTypes.Option_error("baseuri", "not found") ->
93 (* no baseuri ==> nothing to clean yet *)
96 let rec interactive_loop () =
97 let str = Ulexing.from_utf8_channel stdin in
100 (MatitaEngine.eval_from_stream_greedy
101 ~include_paths:(Helm_registry.get_list Helm_registry.string
104 | MatitaEngine.Drop -> pp_ocaml_mode ()
105 | Sys.Break -> MatitaLog.error "user break!"; interactive_loop ()
106 | MatitaTypes.Command_error _ -> interactive_loop ()
110 | CicNotationParser.Parse_error (floc,err) ->
111 let (x, y) = CicNotationPt.loc_of_floc floc in
112 MatitaLog.error (sprintf "Parse error at %d-%d: %s" x y err);
114 | exn -> MatitaLog.error (Printexc.to_string exn); interactive_loop ()
117 Helm_registry.load_from BuildTimeConf.matita_conf;
118 CicNotation.load_notation BuildTimeConf.core_notation_script;
120 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
121 MatitaDb.create_owner_environment ();
122 CicEnvironment.set_trust (* environment trust *)
123 (let trust = Helm_registry.get_bool "matita.environment_trust" in
125 status := Some (ref (Lazy.force MatitaEngine.initial_status));
126 Sys.catch_break true;
130 MatitaInit.initialize_all ();
131 (* must be called after init since args are set by cmdline parsing *)
132 let fname = fname () in
133 status := Some (ref (Lazy.force MatitaEngine.initial_status));
134 Sys.catch_break true;
135 let origcb = MatitaLog.get_log_callback () in
138 | `Debug | `Message -> ()
139 | `Warning | `Error -> origcb tag s
141 if Helm_registry.get_bool "matita.quiet" then
142 MatitaLog.set_log_callback newcb;
144 let time = Unix.time () in
145 if Helm_registry.get_bool "matita.quiet" then
146 origcb `Message ("compiling " ^ Filename.basename fname ^ "...")
148 MatitaLog.message (sprintf "execution of %s started:" fname);
150 Ulexing.from_utf8_channel
153 | fname -> open_in fname)
156 (MatitaEngine.eval_from_stream
157 ~include_paths:(Helm_registry.get_list Helm_registry.string
159 ~clean_baseuri:(not (Helm_registry.get_bool "matita.preserve")));
160 let elapsed = Unix.time () -. time in
161 let tm = Unix.gmtime elapsed in
163 if tm.Unix.tm_sec > 0 then (string_of_int tm.Unix.tm_sec ^ "''") else ""
166 if tm.Unix.tm_min > 0 then (string_of_int tm.Unix.tm_min ^ "' ") else ""
169 if tm.Unix.tm_hour > 0 then (string_of_int tm.Unix.tm_hour ^ "h ") else ""
171 let proof_status,moo_content_rev =
173 | Some s -> !s.proof_status, !s.moo_content_rev
174 | None -> assert false
176 if proof_status <> MatitaTypes.No_proof then
179 "there are still incomplete proofs at the end of the script";
184 let moo_fname = MatitaMisc.obj_file_of_script fname in
185 MatitaMoo.save_moo moo_fname moo_content_rev;
187 (sprintf "execution of %s completed in %s." fname (hou^min^sec));
192 MatitaLog.error "user break!";
193 if mode = `COMPILER then
194 clean_exit (Some ~-1)
197 | MatitaEngine.Drop ->
198 if mode = `COMPILER then
202 | CicNotationParser.Parse_error (floc,err) ->
203 let (x, y) = CicNotationPt.loc_of_floc floc in
204 MatitaLog.error (sprintf "Parse error at %d-%d: %s" x y err);
205 if mode = `COMPILER then
210 if Helm_registry.get_bool "matita.debug" then raise exn;
211 if mode = `COMPILER then