]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/matita.ml
new concept of virtuals, defined only in the gui that behave as the old (still
[helm.git] / helm / software / matita / matita.ml
1 (* Copyright (C) 2004-2005, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 open Printf
29
30 open MatitaGtkMisc
31 open GrafiteTypes
32
33 (** {2 Initialization} *)
34
35 let _ = 
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 ()
41 ;;
42
43 (* let _ = Saturation.init () (* ALB to link paramodulation *) *)
44
45 (** {2 GUI callbacks} *)
46
47 let gui = MatitaGui.instance ()
48
49 let script =
50   let s = 
51     MatitaScript.script 
52       ~source_view:gui#sourceView
53       ~mathviewer:(MatitaMathView.mathViewer ())
54       ~urichooser:(fun uris ->
55         try
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"))
61           () ~id:"boh?" uris
62         with MatitaTypes.Cancel -> [])
63       ~set_star:gui#setStar
64       ~ask_confirmation:
65         (fun ~title ~message -> 
66             MatitaGtkMisc.ask_confirmation ~title ~message 
67             ~parent:gui#main#toplevel ())
68       ()
69   in
70   Predefined_virtuals.load_predefined_virtuals ();
71   Predefined_virtuals.load_predefined_classes ();
72   gui#sourceView#source_buffer#begin_not_undoable_action ();
73   s#reset (); 
74   s#template (); 
75   gui#sourceView#source_buffer#end_not_undoable_action ();
76   s
77   
78   (* math viewers *)
79 let _ =
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;
92         (try
93           script#setGoal (Some (Continuationals.Stack.find_goal stack));
94           let goal =
95            match script#goal with
96               None -> assert false
97             | Some n -> n
98           in
99            sequents_viewer#goto_sequent goal
100         with Failure _ -> script#setGoal None);
101     | Proof proof -> sequents_viewer#load_logo_with_qed
102     | No_proof -> sequents_viewer#load_logo
103     | Intermediate _ -> assert false (* only the engine may be in this state *)
104   in
105   script#addObserver sequents_observer;
106   script#addObserver browser_observer
107
108   (** {{{ Debugging *)
109 let _ =
110   if BuildTimeConf.debug ||
111      Helm_registry.get_bool "matita.debug_menu" 
112   then begin
113     gui#main#debugMenu#misc#show ();
114     let addDebugItem ~label callback =
115       let item =
116         GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label () in
117       ignore (item#connect#activate callback) in
118     let addDebugSeparator () =
119       ignore (GMenu.separator_item ~packing:gui#main#debugMenu_menu#append ())
120     in
121     addDebugItem "dump aliases" (fun _ ->
122       let status = script#lexicon_status in
123       HLog.debug (String.concat "\n"
124        (DisambiguateTypes.Environment.fold
125          (fun _ x l -> (LexiconAstPp.pp_alias x)::l)
126          status.LexiconEngine.aliases [])));
127     addDebugItem "dump environment to \"env.dump\"" (fun _ ->
128       let oc = open_out "env.dump" in
129       CicEnvironment.dump_to_channel oc;
130       close_out oc);
131     addDebugItem "load environment from \"env.dump\"" (fun _ ->
132       let ic = open_in "env.dump" in
133       CicEnvironment.restore_from_channel ic;
134       close_in ic);
135     addDebugItem "dump universes" (fun _ ->
136       List.iter (fun (u,_,g) -> 
137         prerr_endline (UriManager.string_of_uri u); 
138         CicUniv.print_ugraph g) (CicEnvironment.list_obj ())
139       );
140     addDebugItem "dump environment content" (fun _ ->
141       List.iter (fun (u,_,_) -> 
142         prerr_endline (UriManager.string_of_uri u)) 
143         (CicEnvironment.list_obj ()));
144     addDebugItem "dump script status" script#dump;
145     addDebugItem "dump configuration file to ./foo.conf.xml" (fun _ ->
146       Helm_registry.save_to "./foo.conf.xml");
147     addDebugItem "dump metasenv"
148       (fun _ ->
149          if script#onGoingProof () then
150            HLog.debug (CicMetaSubst.ppmetasenv [] script#proofMetasenv));
151     addDebugItem "print top-level grammar entries"
152       CicNotationParser.print_l2_pattern;
153     addDebugItem "dump moo to stderr" (fun _ ->
154       let grafite_status = (MatitaScript.current ())#grafite_status in
155       let moo = grafite_status.moo_content_rev in
156       List.iter
157         (fun cmd ->
158           prerr_endline
159            (GrafiteAstPp.pp_command
160              ~term_pp:(fun _ -> assert false)
161              ~obj_pp:(fun _ -> assert false)
162              cmd))
163         (List.rev moo));
164     addDebugItem "print metasenv goals and stack to stderr"
165       (fun _ ->
166         prerr_endline ("metasenv goals: " ^ String.concat " "
167           (List.map (fun (g, _, _) -> string_of_int g)
168             (MatitaScript.current ())#proofMetasenv));
169         prerr_endline ("stack: " ^ Continuationals.Stack.pp
170           (GrafiteTypes.get_stack (MatitaScript.current ())#grafite_status)));
171      addDebugItem "Print current proof term" 
172        (fun _ -> 
173         HLog.debug
174           (CicPp.ppterm 
175             (match 
176             (MatitaScript.current ())#grafite_status.GrafiteTypes.proof_status
177             with
178             | GrafiteTypes.No_proof -> (Cic.Implicit None)
179             | Incomplete_proof i -> 
180                  let _,_,_subst,p,_, _ = i.GrafiteTypes.proof in 
181                  Lazy.force p
182             | Proof p -> let _,_,_subst,p,_, _ = p in Lazy.force p
183             | Intermediate _ -> assert false)));
184      addDebugItem "Print current proof (natural language) to stderr" 
185        (fun _ -> 
186         prerr_endline 
187           (ApplyTransformation.txt_of_cic_object 120 GrafiteAst.Declarative "" 
188             ~map_unicode_to_tex:(Helm_registry.get_bool
189               "matita.paste_unicode_as_tex")
190             (match 
191             (MatitaScript.current ())#grafite_status.GrafiteTypes.proof_status
192             with
193             | GrafiteTypes.No_proof -> assert false
194             | Incomplete_proof i -> 
195                 let _,m,_subst,p,ty, attrs = i.GrafiteTypes.proof in 
196                 Cic.CurrentProof ("current (incomplete) proof",m,Lazy.force p,ty,[],attrs)
197             | Proof (_,m,_subst,p,ty, attrs) -> 
198                 Cic.CurrentProof ("current proof",m,Lazy.force p,ty,[],attrs)
199             | Intermediate _ -> assert false)));
200 (*     addDebugItem "ask record choice"
201       (fun _ ->
202         HLog.debug (string_of_int
203           (MatitaGtkMisc.ask_record_choice ~gui ~title:"title" ~message:"msg"
204           ~fields:["a"; "b"; "c"]
205           ~records:[
206             ["0"; "0"; "0"]; ["0"; "0"; "1"]; ["0"; "1"; "0"]; ["0"; "1"; "1"];
207             ["1"; "0"; "0"]; ["1"; "0"; "1"]; ["1"; "1"; "0"]; ["1"; "1"; "1"]]
208           ()))); *)
209 (*     addDebugItem "rotate light bulbs"
210       (fun _ ->
211          let nb = gui#main#hintNotebook in
212          nb#goto_page ((nb#current_page + 1) mod 3)); *)
213     addDebugSeparator ();
214 (*
215     addDebugItem "meets between L and R" 
216       (fun _ -> 
217         let l = CoercDb.coerc_carr_of_term (CicUtil.term_of_uri
218           (UriManager.uri_of_string "cic:/matita/test/L.ind#xpointer(1/1)" )) 
219         in
220         let r = CoercDb.coerc_carr_of_term (CicUtil.term_of_uri
221           (UriManager.uri_of_string "cic:/matita/test/R.ind#xpointer(1/1)" )) 
222         in
223         let meets = CoercGraph.meets l r in
224         prerr_endline "MEETS:";
225         List.iter (fun carr -> prerr_endline (CicPp.ppterm (CoercDb.term_of_carr
226         carr))) meets
227     );
228     addDebugSeparator ();
229 *)
230     addDebugItem "disable high level pretty printer"
231       (fun _ -> CicMetaSubst.use_low_level_ppterm_in_context := true);
232     addDebugItem "enable high level pretty printer"
233       (fun _ -> CicMetaSubst.use_low_level_ppterm_in_context := false);
234 (* ZACK moved to the View menu
235     addDebugItem "disable all (pretty printing) notations"
236       (fun _ -> CicNotation.set_active_notations []);
237     addDebugItem "enable all (pretty printing) notations"
238       (fun _ ->
239         CicNotation.set_active_notations
240           (List.map fst (CicNotation.get_all_notations ())));
241 *)
242     addDebugSeparator ();
243     addDebugItem "enable multiple disambiguation passes (default)"
244       (fun _ -> MultiPassDisambiguator.only_one_pass := false);
245     addDebugItem "enable only one disambiguation pass"
246       (fun _ -> MultiPassDisambiguator.only_one_pass := true);
247     addDebugItem "always show all disambiguation errors"
248       (fun _ -> MatitaGui.all_disambiguation_passes := true);
249     addDebugItem "prune disambiguation errors"
250       (fun _ -> MatitaGui.all_disambiguation_passes := false);
251     addDebugSeparator ();
252 (* ZACK moved to the View menu
253     addDebugItem "enable coercions hiding"
254       (fun _ -> Acic2content.hide_coercions := true);
255     addDebugItem "disable coercions hiding"
256       (fun _ -> Acic2content.hide_coercions := false);
257 *)
258     addDebugItem "show coercions graph" (fun _ ->
259       let c = MatitaMathView.cicBrowser () in
260       c#load (`About `Coercions));
261     addDebugItem "show coercions graph (full)" (fun _ ->
262       let c = MatitaMathView.cicBrowser () in
263       c#load (`About `CoercionsFull));
264     addDebugItem "dump coercions Db" (fun _ ->
265       List.iter
266       (fun (s,t,ul) -> 
267           HLog.debug
268            ((String.concat ","
269               (List.map
270                 (fun u,saturations,_ ->
271                   UriManager.name_of_uri u ^
272                    "(" ^ string_of_int saturations ^ ")")
273                 ul)) ^ ":"
274              ^ CoercDb.string_of_carr s ^ " -> " ^ CoercDb.string_of_carr t))
275         (CoercDb.to_list ()));
276     addDebugSeparator ();
277     let mview () = (MatitaMathView.sequentsViewer_instance ())#cicMathView in
278 (*     addDebugItem "save (sequent) MathML to matita.xml"
279       (fun _ -> ignore ((Gdome.domImplementation ())#saveDocumentToFile
280         ~doc:(HExtlib.unopt (mview ())#get_document) ~name:"matita.xml" ())); *)
281     addDebugItem "load (sequent) MathML from matita.xml"
282       (fun _ -> (mview ())#load_uri ~filename:"matita.xml");
283     addDebugItem "autoWin"
284     (fun _ -> MatitaAutoGui.auto_dialog Auto.get_auto_status);
285   end
286   (** Debugging }}} *)
287
288   (** {2 Main} *)
289
290 let _ =
291   at_exit (fun () -> print_endline "\nThanks for using Matita!\n");
292   Sys.catch_break true;
293   let args = Helm_registry.get_list Helm_registry.string "matita.args" in
294   (try gui#loadScript (List.hd args) with Failure _ -> ());
295   gui#main#mainWin#show ();
296   try
297    GtkThread.main ()
298   with Sys.Break ->
299    Sys.set_signal Sys.sigint
300     (Sys.Signal_handle
301       (fun _ ->
302         prerr_endline "Still cleaning the library: don't be impatient!"));
303    prerr_endline "Matita is cleaning up. Please wait.";
304    let baseuri = 
305      GrafiteTypes.get_baseuri (MatitaScript.current ())#grafite_status
306    in
307      LibraryClean.clean_baseuris [baseuri]
308
309 (* vim:set foldmethod=marker: *)