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 let pp_ast_statement =
31 GrafiteAstPp.pp_statement ~term_pp:CicNotationPp.pp_term
32 ~lazy_term_pp:CicNotationPp.pp_term ~obj_pp:CicNotationPp.pp_obj
34 (** {2 Initialization} *)
38 let run_script is eval_function =
41 | None -> assert false
44 let slash_n_RE = Pcre.regexp "\\n" in
46 if Helm_registry.get_bool "matita.quiet" then
50 (* dump_status status; *)
51 let stm = pp_ast_statement stm in
52 let stm = Pcre.replace ~rex:slash_n_RE stm in
54 if String.length stm > 50 then
55 String.sub stm 0 50 ^ " ..."
59 HLog.debug ("Executing: ``" ^ stm ^ "''"))
62 eval_function status is cb
66 | CicNotationParser.Parse_error _ as exn -> raise exn
68 HLog.error (snd (MatitaExcPp.to_string exn));
72 match Helm_registry.get_list Helm_registry.string "matita.args" with
74 | _ -> MatitaInit.die_usage ()
76 let pp_ocaml_mode () =
78 HLog.message " ** Entering Ocaml mode ** ";
80 HLog.message "Type 'go ();;' to enter an interactive matitac";
93 let baseuri = GrafiteTypes.get_string_option !status "baseuri" in
94 let basedir = Helm_registry.get "matita.basedir" in
95 LibraryClean.clean_baseuris ~basedir ~verbose:false [baseuri];
97 with GrafiteTypes.Option_error("baseuri", "not found") ->
98 (* no baseuri ==> nothing to clean yet *)
101 let rec interactive_loop () =
102 let str = Ulexing.from_utf8_channel stdin in
105 (MatitaEngine.eval_from_stream ~prompt:true
106 ~include_paths:(Helm_registry.get_list Helm_registry.string
109 | GrafiteEngine.Drop -> pp_ocaml_mode ()
110 | Sys.Break -> HLog.error "user break!"; interactive_loop ()
111 | GrafiteTypes.Command_error _ -> interactive_loop ()
115 | HExtlib.Localized (floc,CicNotationParser.Parse_error err) ->
116 let (x, y) = HExtlib.loc_of_floc floc in
117 HLog.error (sprintf "Parse error at %d-%d: %s" x y err);
119 | exn -> HLog.error (Printexc.to_string exn); interactive_loop ()
122 Helm_registry.load_from BuildTimeConf.matita_conf;
123 CicNotation2.load_notation BuildTimeConf.core_notation_script;
125 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
126 LibraryDb.create_owner_environment ();
127 CicEnvironment.set_trust (* environment trust *)
128 (let trust = Helm_registry.get_bool "matita.environment_trust" in
130 status := Some (ref (MatitaSync.init ()));
131 Sys.catch_break true;
135 MatitaInit.initialize_all ();
136 (* must be called after init since args are set by cmdline parsing *)
137 let fname = fname () in
138 status := Some (ref (MatitaSync.init ()));
139 Sys.catch_break true;
140 let origcb = HLog.get_log_callback () in
143 | `Debug | `Message -> ()
144 | `Warning | `Error -> origcb tag s
146 if Helm_registry.get_bool "matita.quiet" then
147 HLog.set_log_callback newcb;
148 let matita_debug = Helm_registry.get_bool "matita.debug" in
150 let time = Unix.time () in
151 if Helm_registry.get_bool "matita.quiet" then
152 origcb `Message ("compiling " ^ Filename.basename fname ^ "...")
154 HLog.message (sprintf "execution of %s started:" fname);
156 Ulexing.from_utf8_channel
159 | fname -> open_in fname) in
161 Helm_registry.get_list Helm_registry.string "matita.includes" in
164 (MatitaEngine.eval_from_stream ~include_paths
165 ~clean_baseuri:(not (Helm_registry.get_bool "matita.preserve")))
166 with End_of_file -> ());
167 let elapsed = Unix.time () -. time in
168 let tm = Unix.gmtime elapsed in
170 if tm.Unix.tm_sec > 0 then (string_of_int tm.Unix.tm_sec ^ "''") else ""
173 if tm.Unix.tm_min > 0 then (string_of_int tm.Unix.tm_min ^ "' ") else ""
176 if tm.Unix.tm_hour > 0 then (string_of_int tm.Unix.tm_hour ^ "h ") else ""
178 let proof_status,moo_content_rev,metadata,status =
180 | Some s -> !s.proof_status, !s.moo_content_rev, !s.metadata, !s
181 | None -> assert false
183 if proof_status <> GrafiteTypes.No_proof then
186 "there are still incomplete proofs at the end of the script";
191 let basedir = Helm_registry.get "matita.basedir" in
192 let baseuri = GrafiteParserMisc.baseuri_of_script ~include_paths fname in
193 let moo_fname = LibraryMisc.obj_file_of_baseuri ~basedir ~baseuri in
194 let metadata_fname = LibraryMisc.metadata_file_of_baseuri ~basedir ~baseuri in
195 GrafiteMarshal.save_moo moo_fname moo_content_rev;
196 LibraryNoDb.save_metadata metadata_fname metadata;
198 (sprintf "execution of %s completed in %s." fname (hou^min^sec));
203 HLog.error "user break!";
204 if mode = `COMPILER then
205 clean_exit (Some ~-1)
208 | GrafiteEngine.Drop ->
209 if mode = `COMPILER then
213 | HExtlib.Localized (floc,CicNotationParser.Parse_error err) ->
214 let (x, y) = HExtlib.loc_of_floc floc in
215 HLog.error (sprintf "Parse error at %d-%d: %s" x y err);
216 if mode = `COMPILER then
221 if matita_debug then raise exn;
222 if mode = `COMPILER then