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 HLog.debug ("Executing: ``" ^ stm ^ "''"))
58 eval_function status is cb
62 | CicNotationParser.Parse_error _ as exn -> raise exn
64 HLog.error (snd (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 HLog.message " ** Entering Ocaml mode ** ";
76 HLog.message "Type 'go ();;' to enter an interactive matitac";
89 let baseuri = GrafiteTypes.get_string_option !status "baseuri" in
90 let basedir = Helm_registry.get "matita.basedir" in
91 LibraryClean.clean_baseuris ~basedir ~verbose:false [baseuri];
93 with GrafiteTypes.Option_error("baseuri", "not found") ->
94 (* no baseuri ==> nothing to clean yet *)
97 let rec interactive_loop () =
98 let str = Ulexing.from_utf8_channel stdin in
101 (MatitaEngine.eval_from_stream_greedy
102 ~include_paths:(Helm_registry.get_list Helm_registry.string
105 | GrafiteEngine.Drop -> pp_ocaml_mode ()
106 | Sys.Break -> HLog.error "user break!"; interactive_loop ()
107 | GrafiteTypes.Command_error _ -> interactive_loop ()
111 | HExtlib.Localized (floc,CicNotationParser.Parse_error err) ->
112 let (x, y) = HExtlib.loc_of_floc floc in
113 HLog.error (sprintf "Parse error at %d-%d: %s" x y err);
115 | exn -> HLog.error (Printexc.to_string exn); interactive_loop ()
118 Helm_registry.load_from BuildTimeConf.matita_conf;
119 CicNotation.load_notation BuildTimeConf.core_notation_script;
121 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
122 LibraryDb.create_owner_environment ();
123 CicEnvironment.set_trust (* environment trust *)
124 (let trust = Helm_registry.get_bool "matita.environment_trust" in
126 status := Some (ref (Lazy.force MatitaEngine.initial_status));
127 Sys.catch_break true;
131 MatitaInit.initialize_all ();
132 (* must be called after init since args are set by cmdline parsing *)
133 let fname = fname () in
134 status := Some (ref (Lazy.force MatitaEngine.initial_status));
135 Sys.catch_break true;
136 let origcb = HLog.get_log_callback () in
139 | `Debug | `Message -> ()
140 | `Warning | `Error -> origcb tag s
142 if Helm_registry.get_bool "matita.quiet" then
143 HLog.set_log_callback newcb;
144 let matita_debug = Helm_registry.get_bool "matita.debug" in
146 let time = Unix.time () in
147 if Helm_registry.get_bool "matita.quiet" then
148 origcb `Message ("compiling " ^ Filename.basename fname ^ "...")
150 HLog.message (sprintf "execution of %s started:" fname);
152 Ulexing.from_utf8_channel
155 | fname -> open_in fname)
158 (MatitaEngine.eval_from_stream
159 ~include_paths:(Helm_registry.get_list Helm_registry.string
161 ~clean_baseuri:(not (Helm_registry.get_bool "matita.preserve")));
162 let elapsed = Unix.time () -. time in
163 let tm = Unix.gmtime elapsed in
165 if tm.Unix.tm_sec > 0 then (string_of_int tm.Unix.tm_sec ^ "''") else ""
168 if tm.Unix.tm_min > 0 then (string_of_int tm.Unix.tm_min ^ "' ") else ""
171 if tm.Unix.tm_hour > 0 then (string_of_int tm.Unix.tm_hour ^ "h ") else ""
173 let proof_status,moo_content_rev,metadata,status =
175 | Some s -> !s.proof_status, !s.moo_content_rev, !s.metadata, !s
176 | None -> assert false
178 if proof_status <> GrafiteTypes.No_proof then
181 "there are still incomplete proofs at the end of the script";
186 let basedir = Helm_registry.get "matita.basedir" in
187 let moo_fname = GrafiteMisc.obj_file_of_script ~basedir fname in
188 let metadata_fname = GrafiteMisc.metadata_file_of_script ~basedir fname in
189 GrafiteMarshal.save_moo moo_fname moo_content_rev;
190 LibraryNoDb.save_metadata metadata_fname metadata;
192 (sprintf "execution of %s completed in %s." fname (hou^min^sec));
197 HLog.error "user break!";
198 if mode = `COMPILER then
199 clean_exit (Some ~-1)
202 | GrafiteEngine.Drop ->
203 if mode = `COMPILER then
207 | HExtlib.Localized (floc,CicNotationParser.Parse_error err) ->
208 let (x, y) = HExtlib.loc_of_floc floc in
209 HLog.error (sprintf "Parse error at %d-%d: %s" x y err);
210 if mode = `COMPILER then
215 if matita_debug then raise exn;
216 if mode = `COMPILER then