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/
33 (** {2 Initialization} *)
36 MatitaInit.add_cmdline_spec
37 ["-tptppath",Arg.String
38 (fun s -> Helm_registry.set_string "matita.tptppath" s),
39 "Where to find the Axioms/ and Problems/ directory"];
40 MatitaInit.initialize_all ()
43 (* let _ = Saturation.init () (* ALB to link paramodulation *) *)
45 (** {2 GUI callbacks} *)
47 let gui = MatitaGui.instance ()
52 ~source_view:gui#sourceView
53 ~mathviewer:(MatitaMathView.mathViewer ())
54 ~urichooser:(fun uris ->
56 MatitaGui.interactive_uri_choice ~selection_mode:`SINGLE
57 ~title:"Matita: URI chooser"
58 ~msg:"Select the URI" ~hide_uri_entry:true
59 ~hide_try:true ~ok_label:"_Apply" ~ok_action:`SELECT
60 ~copy_cb:(fun s -> gui#sourceView#buffer#insert ("\n"^s^"\n"))
62 with MatitaTypes.Cancel -> [])
65 (fun ~title ~message ->
66 MatitaGtkMisc.ask_confirmation ~title ~message
67 ~parent:gui#main#toplevel ())
70 Predefined_virtuals.load_predefined_virtuals ();
71 Predefined_virtuals.load_predefined_classes ();
72 gui#sourceView#source_buffer#begin_not_undoable_action ();
75 gui#sourceView#source_buffer#end_not_undoable_action ();
80 let cic_math_view = MatitaMathView.cicMathView_instance () in
81 let sequents_viewer = MatitaMathView.sequentsViewer_instance () in
82 sequents_viewer#load_logo;
83 cic_math_view#set_href_callback
84 (Some (fun uri -> (MatitaMathView.cicBrowser ())#load
85 (`Uri (UriManager.uri_of_string uri))));
86 let browser_observer _ _ = MatitaMathView.refresh_all_browsers () in
87 let sequents_observer _ grafite_status =
88 sequents_viewer#reset;
89 match grafite_status.proof_status with
90 | Incomplete_proof ({ stack = stack } as incomplete_proof) ->
91 sequents_viewer#load_sequents incomplete_proof;
93 script#setGoal (Some (Continuationals.Stack.find_goal stack));
95 match script#goal with
99 sequents_viewer#goto_sequent goal
100 with Failure _ -> script#setGoal None);
101 | Proof proof -> sequents_viewer#load_logo_with_qed
103 (match grafite_status.ng_status with
105 sequents_viewer#nload_sequents nstatus;
107 script#setGoal (Some (Continuationals.Stack.find_goal nstatus.NTacStatus.gstatus));
109 match script#goal with
113 sequents_viewer#goto_sequent goal
114 with Failure _ -> script#setGoal None);
115 | CommandMode _ -> sequents_viewer#load_logo
117 | Intermediate _ -> assert false (* only the engine may be in this state *)
119 script#addObserver sequents_observer;
120 script#addObserver browser_observer
124 if BuildTimeConf.debug ||
125 Helm_registry.get_bool "matita.debug_menu"
127 gui#main#debugMenu#misc#show ();
128 let addDebugItem ~label callback =
130 GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label () in
131 ignore (item#connect#activate callback) in
132 let addDebugSeparator () =
133 ignore (GMenu.separator_item ~packing:gui#main#debugMenu_menu#append ())
135 addDebugItem "dump aliases" (fun _ ->
136 let status = script#lexicon_status in
137 LexiconEngine.dump_aliases HLog.debug "" status);
139 addDebugItem "dump interpretations" (fun _ ->
140 let status = script#lexicon_status in
142 List.filter (function LexiconAst.Interpretation _ -> true | _ -> false)
144 HLog.debug (String.concat "\n"
146 (fun x l -> (LexiconAstPp.pp_command x)::l)
147 (filter status.LexiconEngine.lexicon_content_rev) [])));
149 addDebugItem "dump environment to \"env.dump\"" (fun _ ->
150 let oc = open_out "env.dump" in
151 CicEnvironment.dump_to_channel oc;
153 addDebugItem "load environment from \"env.dump\"" (fun _ ->
154 let ic = open_in "env.dump" in
155 CicEnvironment.restore_from_channel ic;
157 addDebugItem "dump universes" (fun _ ->
158 List.iter (fun (u,_,g) ->
159 prerr_endline (UriManager.string_of_uri u);
160 CicUniv.print_ugraph g) (CicEnvironment.list_obj ())
162 addDebugItem "dump environment content" (fun _ ->
163 List.iter (fun (u,_,_) ->
164 prerr_endline (UriManager.string_of_uri u))
165 (CicEnvironment.list_obj ()));
166 addDebugItem "dump script status" script#dump;
167 addDebugItem "dump configuration file to ./foo.conf.xml" (fun _ ->
168 Helm_registry.save_to "./foo.conf.xml");
169 addDebugItem "dump metasenv"
171 if script#onGoingProof () then
172 HLog.debug (CicMetaSubst.ppmetasenv [] script#proofMetasenv));
173 addDebugItem "print top-level grammar entries"
174 CicNotationParser.print_l2_pattern;
175 addDebugItem "dump moo to stderr" (fun _ ->
176 let grafite_status = (MatitaScript.current ())#grafite_status in
177 let moo = grafite_status.moo_content_rev in
181 (GrafiteAstPp.pp_command
182 ~term_pp:(fun t -> CicPp.ppterm t)
183 ~obj_pp:(fun _ -> assert false)
186 addDebugItem "print metasenv goals and stack to stderr"
188 prerr_endline ("metasenv goals: " ^ String.concat " "
189 (List.map (fun (g, _, _) -> string_of_int g)
190 (MatitaScript.current ())#proofMetasenv));
191 prerr_endline ("stack: " ^ Continuationals.Stack.pp
192 (GrafiteTypes.get_stack (MatitaScript.current ())#grafite_status)));
193 addDebugItem "Print current proof term"
198 (MatitaScript.current ())#grafite_status.GrafiteTypes.proof_status
200 | GrafiteTypes.No_proof -> (Cic.Implicit None)
201 | Incomplete_proof i ->
202 let _,_,_subst,p,_, _ = i.GrafiteTypes.proof in
204 | Proof p -> let _,_,_subst,p,_, _ = p in Lazy.force p
205 | Intermediate _ -> assert false)));
206 addDebugItem "Print current proof (natural language) to stderr"
209 (ApplyTransformation.txt_of_cic_object 120 []
210 ~map_unicode_to_tex:(Helm_registry.get_bool
211 "matita.paste_unicode_as_tex")
213 (MatitaScript.current ())#grafite_status.GrafiteTypes.proof_status
215 | GrafiteTypes.No_proof -> assert false
216 | Incomplete_proof i ->
217 let _,m,_subst,p,ty, attrs = i.GrafiteTypes.proof in
218 Cic.CurrentProof ("current (incomplete) proof",m,Lazy.force p,ty,[],attrs)
219 | Proof (_,m,_subst,p,ty, attrs) ->
220 Cic.CurrentProof ("current proof",m,Lazy.force p,ty,[],attrs)
221 | Intermediate _ -> assert false)));
222 (* addDebugItem "ask record choice"
224 HLog.debug (string_of_int
225 (MatitaGtkMisc.ask_record_choice ~gui ~title:"title" ~message:"msg"
226 ~fields:["a"; "b"; "c"]
228 ["0"; "0"; "0"]; ["0"; "0"; "1"]; ["0"; "1"; "0"]; ["0"; "1"; "1"];
229 ["1"; "0"; "0"]; ["1"; "0"; "1"]; ["1"; "1"; "0"]; ["1"; "1"; "1"]]
231 (* addDebugItem "rotate light bulbs"
233 let nb = gui#main#hintNotebook in
234 nb#goto_page ((nb#current_page + 1) mod 3)); *)
235 addDebugSeparator ();
237 addDebugItem "meets between L and R"
239 let l = CoercDb.coerc_carr_of_term (CicUtil.term_of_uri
240 (UriManager.uri_of_string "cic:/matita/test/L.ind#xpointer(1/1)" ))
242 let r = CoercDb.coerc_carr_of_term (CicUtil.term_of_uri
243 (UriManager.uri_of_string "cic:/matita/test/R.ind#xpointer(1/1)" ))
245 let meets = CoercGraph.meets l r in
246 prerr_endline "MEETS:";
247 List.iter (fun carr -> prerr_endline (CicPp.ppterm (CoercDb.term_of_carr
250 addDebugSeparator ();
252 addDebugItem "disable high level pretty printer"
253 (fun _ -> CicMetaSubst.use_low_level_ppterm_in_context := true);
254 addDebugItem "enable high level pretty printer"
255 (fun _ -> CicMetaSubst.use_low_level_ppterm_in_context := false);
256 (* ZACK moved to the View menu
257 addDebugItem "disable all (pretty printing) notations"
258 (fun _ -> CicNotation.set_active_notations []);
259 addDebugItem "enable all (pretty printing) notations"
261 CicNotation.set_active_notations
262 (List.map fst (CicNotation.get_all_notations ())));
264 addDebugSeparator ();
265 addDebugItem "enable multiple disambiguation passes (default)"
266 (fun _ -> MultiPassDisambiguator.only_one_pass := false);
267 addDebugItem "enable only one disambiguation pass"
268 (fun _ -> MultiPassDisambiguator.only_one_pass := true);
269 addDebugItem "always show all disambiguation errors"
270 (fun _ -> MatitaGui.all_disambiguation_passes := true);
271 addDebugItem "prune disambiguation errors"
272 (fun _ -> MatitaGui.all_disambiguation_passes := false);
273 addDebugSeparator ();
274 (* ZACK moved to the View menu
275 addDebugItem "enable coercions hiding"
276 (fun _ -> Acic2content.hide_coercions := true);
277 addDebugItem "disable coercions hiding"
278 (fun _ -> Acic2content.hide_coercions := false);
280 addDebugItem "show coercions graph" (fun _ ->
281 let c = MatitaMathView.cicBrowser () in
282 c#load (`About `Coercions));
283 addDebugItem "show coercions graph (full)" (fun _ ->
284 let c = MatitaMathView.cicBrowser () in
285 c#load (`About `CoercionsFull));
286 addDebugItem "dump coercions Db" (fun _ ->
292 (fun u,saturations,_ ->
293 UriManager.name_of_uri u ^
294 "(" ^ string_of_int saturations ^ ")")
296 ^ CoercDb.string_of_carr s ^ " -> " ^ CoercDb.string_of_carr t))
297 (CoercDb.to_list ()));
298 addDebugSeparator ();
299 let mview () = (MatitaMathView.sequentsViewer_instance ())#cicMathView in
300 (* addDebugItem "save (sequent) MathML to matita.xml"
301 (fun _ -> ignore ((Gdome.domImplementation ())#saveDocumentToFile
302 ~doc:(HExtlib.unopt (mview ())#get_document) ~name:"matita.xml" ())); *)
303 addDebugItem "load (sequent) MathML from matita.xml"
304 (fun _ -> (mview ())#load_uri ~filename:"matita.xml");
305 addDebugSeparator ();
306 addDebugItem "Expand virtuals"
307 (fun _ -> (MatitaScript.current ())#expandAllVirtuals);
314 at_exit (fun () -> print_endline "\nThanks for using Matita!\n");
315 Sys.catch_break true;
316 let args = Helm_registry.get_list Helm_registry.string "matita.args" in
317 (try gui#loadScript (List.hd args) with Failure _ -> ());
318 gui#main#mainWin#show ();
322 Sys.set_signal Sys.sigint
325 prerr_endline "Still cleaning the library: don't be impatient!"));
326 prerr_endline "Matita is cleaning up. Please wait.";
328 GrafiteTypes.get_baseuri (MatitaScript.current ())#grafite_status
330 LibraryClean.clean_baseuris [baseuri]
332 (* vim:set foldmethod=marker: *)