1 (* Copyright (C) 2000-2002, 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://cs.unibo.it/helm/.
26 (******************************************************************************)
30 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
34 (******************************************************************************)
40 module MQI = MQueryInterpreter
43 (* GLOBAL CONSTANTS *)
45 let mqi_flags = [] (* default MathQL interpreter options *)
46 let mqi_handle = MQIC.init mqi_flags prerr_string
48 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
52 " <body bgColor=\"white\">"
62 Sys.getenv "GTOPLEVEL_PROOFFILE"
64 Not_found -> "/public/currentproof"
69 Sys.getenv "GTOPLEVEL_PROOFFILETYPE"
71 Not_found -> "/public/currentprooftype"
74 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
76 let htmlheader_and_content = ref htmlheader;;
78 let check_term = ref (fun _ _ _ -> assert false);;
80 exception RenderingWindowsNotInitialized;;
82 let set_rendering_window,rendering_window =
83 let rendering_window_ref = ref None in
84 (function rw -> rendering_window_ref := Some rw),
86 match !rendering_window_ref with
87 None -> raise RenderingWindowsNotInitialized
92 exception SettingsWindowsNotInitialized;;
94 let set_settings_window,settings_window =
95 let settings_window_ref = ref None in
96 (function rw -> settings_window_ref := Some rw),
98 match !settings_window_ref with
99 None -> raise SettingsWindowsNotInitialized
104 exception OutputHtmlNotInitialized;;
106 let set_outputhtml,outputhtml =
107 let outputhtml_ref = ref None in
108 (function rw -> outputhtml_ref := Some rw),
110 match !outputhtml_ref with
111 None -> raise OutputHtmlNotInitialized
112 | Some outputhtml -> outputhtml
116 exception QedSetSensitiveNotInitialized;;
117 let qed_set_sensitive =
118 ref (function _ -> raise QedSetSensitiveNotInitialized)
121 exception SaveSetSensitiveNotInitialized;;
122 let save_set_sensitive =
123 ref (function _ -> raise SaveSetSensitiveNotInitialized)
126 (* COMMAND LINE OPTIONS *)
132 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
135 Arg.parse argspec ignore ""
139 let term_of_cic_textual_parser_uri uri =
140 let module C = Cic in
141 let module CTP = CicTextualParser0 in
143 CTP.ConUri uri -> C.Const (uri,[])
144 | CTP.VarUri uri -> C.Var (uri,[])
145 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
146 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
149 let string_of_cic_textual_parser_uri uri =
150 let module C = Cic in
151 let module CTP = CicTextualParser0 in
154 CTP.ConUri uri -> UriManager.string_of_uri uri
155 | CTP.VarUri uri -> UriManager.string_of_uri uri
156 | CTP.IndTyUri (uri,tyno) ->
157 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
158 | CTP.IndConUri (uri,tyno,consno) ->
159 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
162 (* 4 = String.length "cic:" *)
163 String.sub uri' 4 (String.length uri' - 4)
166 let output_html outputhtml msg =
167 htmlheader_and_content := !htmlheader_and_content ^ msg ;
168 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
169 outputhtml#set_topline (-1)
172 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
176 let check_window outputhtml uris =
179 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
181 GPack.notebook ~scrollable:true ~packing:window#add () in
186 let scrolled_window =
187 GBin.scrolled_window ~border_width:10
189 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
194 TermViewer.sequent_viewer
195 ~packing:scrolled_window#add ~width:400 ~height:280 () in
198 term_of_cic_textual_parser_uri
199 (MQueryMisc.cic_textual_parser_uri_of_string uri)
201 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
204 mmlwidget#load_sequent [] (111,[],expr)
207 output_html outputhtml
208 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
213 (notebook#connect#switch_page
214 (function i -> Lazy.force (List.nth render_terms i)))
220 interactive_user_uri_choice ~(selection_mode:[`SINGLE|`EXTENDED]) ?(ok="Ok")
221 ?(enable_button_for_non_vars=false) ~title ~msg uris
223 let choices = ref [] in
224 let chosen = ref false in
225 let use_only_constants = ref false in
227 GWindow.dialog ~modal:true ~title ~width:600 () in
229 GMisc.label ~text:msg
230 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
231 let scrolled_window =
232 GBin.scrolled_window ~border_width:10
233 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
235 let expected_height = 18 * List.length uris in
236 let height = if expected_height > 400 then 400 else expected_height in
237 GList.clist ~columns:1 ~packing:scrolled_window#add
238 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
239 let _ = List.map (function x -> clist#append [x]) uris in
241 GPack.hbox ~border_width:0
242 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
244 GMisc.label ~text:"None of the above. Try this one:"
245 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
247 GEdit.entry ~editable:true
248 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
250 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
252 GButton.button ~label:ok
253 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
254 let _ = okb#misc#set_sensitive false in
259 if enable_button_for_non_vars then
260 hbox#pack ~expand:false ~fill:false ~padding:5 w)
261 ~label:"Try constants only" () in
263 GButton.button ~label:"Check"
264 ~packing:(hbox#pack ~padding:5) () in
265 let _ = checkb#misc#set_sensitive false in
267 GButton.button ~label:"Abort"
268 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
270 let check_callback () =
271 assert (List.length !choices > 0) ;
272 check_window (outputhtml ()) !choices
274 ignore (window#connect#destroy GMain.Main.quit) ;
275 ignore (cancelb#connect#clicked window#destroy) ;
277 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
279 (nonvarsb#connect#clicked
281 use_only_constants := true ;
285 ignore (checkb#connect#clicked check_callback) ;
287 (clist#connect#select_row
288 (fun ~row ~column ~event ->
289 checkb#misc#set_sensitive true ;
290 okb#misc#set_sensitive true ;
291 choices := (List.nth uris row)::!choices)) ;
293 (clist#connect#unselect_row
294 (fun ~row ~column ~event ->
296 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
298 (manual_input#connect#changed
300 if manual_input#text = "" then
303 checkb#misc#set_sensitive false ;
304 okb#misc#set_sensitive false ;
305 clist#misc#set_sensitive true
309 choices := [manual_input#text] ;
310 clist#unselect_all () ;
311 checkb#misc#set_sensitive true ;
312 okb#misc#set_sensitive true ;
313 clist#misc#set_sensitive false
315 window#set_position `CENTER ;
319 if !use_only_constants then
321 (function uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
324 if List.length !choices > 0 then !choices else raise NoChoice
329 let interactive_interpretation_choice interpretations =
330 let chosen = ref None in
333 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
334 let vbox = GPack.vbox ~packing:window#add () in
338 ("Ambiguous input since there are many well-typed interpretations." ^
339 " Please, choose one of them.")
340 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
342 GPack.notebook ~scrollable:true
343 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
346 (function interpretation ->
348 let expected_height = 18 * List.length interpretation in
349 let height = if expected_height > 400 then 400 else expected_height in
350 GList.clist ~columns:2 ~packing:notebook#append_page ~height
351 ~titles:["id" ; "URI"] ()
355 (function (id,uri) ->
356 let n = clist#append [id;uri] in
357 clist#set_row ~selectable:false n
360 clist#columns_autosize ()
363 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
365 GButton.button ~label:"Ok"
366 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
368 GButton.button ~label:"Abort"
369 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
371 ignore (window#connect#destroy GMain.Main.quit) ;
372 ignore (cancelb#connect#clicked window#destroy) ;
375 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
376 window#set_position `CENTER ;
380 None -> raise NoChoice
387 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
388 (* FG : THIS FUNCTION IS BECOMING A REAL NONSENSE *)
390 let query = ref "" in
391 let out s = query := ! query ^ s in
392 MQueryGenerator.set_confirm_query
394 query := ""; MQueryUtil.text_of_query out q ""; true);
396 out (!query ^ " <h1>Result:</h1> "); MQueryUtil.text_of_result out result "<br>";
401 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
404 let struri = UriManager.string_of_uri uri in
405 let idx = (String.rindex struri '/') + 1 in
406 String.sub struri idx (String.length struri - idx)
408 let path = pathname ^ "/" ^ name in
410 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
414 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
415 ~ask_dtd_to_the_getter:false
418 let innertypesuri = UriManager.innertypesuri_of_uri uri in
419 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
420 Getter.register innertypesuri
421 (Configuration.annotations_url ^
422 Str.replace_first (Str.regexp "^cic:") ""
423 (UriManager.string_of_uri innertypesuri) ^ ".xml"
425 (* constant type / variable / mutual inductive types definition *)
426 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
428 (Configuration.annotations_url ^
429 Str.replace_first (Str.regexp "^cic:") ""
430 (UriManager.string_of_uri uri) ^ ".xml"
437 match UriManager.bodyuri_of_uri uri with
439 | Some bodyuri -> bodyuri
441 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
442 Getter.register bodyuri
443 (Configuration.annotations_url ^
444 Str.replace_first (Str.regexp "^cic:") ""
445 (UriManager.string_of_uri bodyuri) ^ ".xml"
452 exception OpenConjecturesStillThere;;
453 exception WrongProof;;
455 let pathname_of_annuri uristring =
456 Configuration.annotations_dir ^
457 Str.replace_first (Str.regexp "^cic:") "" uristring
460 let make_dirs dirpath =
461 ignore (Unix.system ("mkdir -p " ^ dirpath))
464 let save_obj uri obj =
466 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
467 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
469 Cic2acic.acic_object_of_cic_object obj
471 (* let's save the theorem and register it to the getter *)
472 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
474 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
479 match !ProofEngine.proof with
481 | Some (uri,[],bo,ty) ->
483 CicReduction.are_convertible []
484 (CicTypeChecker.type_of_aux' [] [] bo) ty
487 (*CSC: Wrong: [] is just plainly wrong *)
488 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
489 let (acic,ids_to_inner_types,ids_to_inner_sorts) =
490 (rendering_window ())#output#load_proof uri proof
492 !qed_set_sensitive false ;
493 (* let's save the theorem and register it to the getter *)
494 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
496 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
501 | _ -> raise OpenConjecturesStillThere
504 (** save an unfinished proof on the filesystem *)
505 let save_unfinished_proof () =
506 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
507 let (xml, bodyxml) = ProofEngine.get_current_status_as_xml () in
508 Xml.pp ~quiet:true xml (Some prooffiletype) ;
509 output_html outputhtml
510 ("<h1 color=\"Green\">Current proof type saved to " ^
511 prooffiletype ^ "</h1>") ;
512 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
513 output_html outputhtml
514 ("<h1 color=\"Green\">Current proof body saved to " ^
518 (* Used to typecheck the loaded proofs *)
519 let typecheck_loaded_proof metasenv bo ty =
520 let module T = CicTypeChecker in
523 (fun metasenv ((_,context,ty) as conj) ->
524 ignore (T.type_of_aux' metasenv context ty) ;
527 ignore (T.type_of_aux' metasenv [] ty) ;
528 ignore (T.type_of_aux' metasenv [] bo)
531 let decompose_uris_choice_callback uris =
532 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
533 let module U = UriManager in
536 match MQueryMisc.cic_textual_parser_uri_of_string uri with
537 CicTextualParser0.IndTyUri (uri,typeno) -> (uri,typeno,[])
539 (interactive_user_uri_choice
540 ~selection_mode:`EXTENDED ~ok:"Ok" ~enable_button_for_non_vars:false
541 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
543 (function (uri,typeno,_) ->
544 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
549 let mk_fresh_name_callback context name ~typ =
551 match ProofEngineHelpers.mk_fresh_name context name ~typ with
552 Cic.Name fresh_name -> fresh_name
553 | Cic.Anonymous -> assert false
556 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
557 ("Enter a fresh name for the hypothesis " ^
559 (List.map (function None -> None | Some (n,_) -> Some n) context))
561 Some fresh_name' -> Cic.Name fresh_name'
562 | None -> raise NoChoice
565 let refresh_proof (output : TermViewer.proof_viewer) =
567 let uri,currentproof =
568 match !ProofEngine.proof with
570 | Some (uri,metasenv,bo,ty) ->
571 if List.length metasenv = 0 then
573 !qed_set_sensitive true ;
574 prerr_endline "CSC: ###### REFRESH_PROOF, Hbugs.clear ()" ;
579 prerr_endline "CSC: ###### REFRESH_PROOF, Hbugs.notify ()" ;
582 (*CSC: Wrong: [] is just plainly wrong *)
584 (Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
586 ignore (output#load_proof uri currentproof)
589 match !ProofEngine.proof with
591 | Some (uri,metasenv,bo,ty) ->
592 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
593 raise (InvokeTactics.RefreshProofException e)
595 let refresh_goals ?(empty_notebook=true) notebook =
597 match !ProofEngine.goal with
599 if empty_notebook then
601 notebook#remove_all_pages ~skip_switch_page_event:false ;
602 notebook#set_empty_page
605 notebook#proofw#unload
608 match !ProofEngine.proof with
610 | Some (_,metasenv,_,_) -> metasenv
613 List.find (function (m,_,_) -> m=metano) metasenv
615 let regenerate_notebook () =
616 let skip_switch_page_event =
618 (m,_,_)::_ when m = metano -> false
621 notebook#remove_all_pages ~skip_switch_page_event ;
622 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
624 if empty_notebook then
626 regenerate_notebook () ;
627 notebook#set_current_page
628 ~may_skip_switch_page_event:false metano
632 notebook#set_current_page
633 ~may_skip_switch_page_event:true metano ;
634 notebook#proofw#load_sequent metasenv currentsequent
639 match !ProofEngine.goal with
644 match !ProofEngine.proof with
646 | Some (_,metasenv,_,_) -> metasenv
649 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
650 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
651 raise (InvokeTactics.RefreshSequentException e)
652 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unknown."); raise (InvokeTactics.RefreshSequentException e)
654 module InvokeTacticsCallbacks =
656 let sequent_viewer () = (rendering_window ())#notebook#proofw
657 let term_editor () = (rendering_window ())#inputt
658 let scratch_window () = (rendering_window ())#scratch_window
660 let refresh_proof () =
661 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
664 let refresh_goals () =
665 let notebook = (rendering_window ())#notebook in
666 refresh_goals notebook
668 let decompose_uris_choice_callback = decompose_uris_choice_callback
669 let mk_fresh_name_callback = mk_fresh_name_callback
670 let output_html msg = output_html (outputhtml ()) msg
673 module InvokeTactics' = InvokeTactics.Make (InvokeTacticsCallbacks);;
674 (* Just to initialize the Hbugs module *)
675 module Ignore = Hbugs.Initialize (InvokeTactics');;
677 (** load an unfinished proof from filesystem *)
678 let load_unfinished_proof () =
679 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
680 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
681 let notebook = (rendering_window ())#notebook in
684 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:"/dummy.con"
687 None -> raise NoChoice
689 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
690 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
691 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
692 typecheck_loaded_proof metasenv bo ty ;
694 Some (uri, metasenv, bo, ty) ;
698 | (metano,_,_)::_ -> Some metano
700 refresh_proof output ;
701 refresh_goals notebook ;
702 output_html outputhtml
703 ("<h1 color=\"Green\">Current proof type loaded from " ^
704 prooffiletype ^ "</h1>") ;
705 output_html outputhtml
706 ("<h1 color=\"Green\">Current proof body loaded from " ^
707 prooffile ^ "</h1>") ;
708 !save_set_sensitive true;
711 InvokeTactics.RefreshSequentException e ->
712 output_html outputhtml
713 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
714 "sequent: " ^ Printexc.to_string e ^ "</h1>")
715 | InvokeTactics.RefreshProofException e ->
716 output_html outputhtml
717 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
718 "proof: " ^ Printexc.to_string e ^ "</h1>")
720 output_html outputhtml
721 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
724 let edit_aliases () =
725 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
726 let id_to_uris = inputt#id_to_uris in
727 let chosen = ref false in
730 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
732 GPack.vbox ~border_width:0 ~packing:window#add () in
733 let scrolled_window =
734 GBin.scrolled_window ~border_width:10
735 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
736 let input = GEdit.text ~editable:true ~width:400 ~height:100
737 ~packing:scrolled_window#add () in
739 GPack.hbox ~border_width:0
740 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
742 GButton.button ~label:"Ok"
743 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
745 GButton.button ~label:"Cancel"
746 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
747 ignore (window#connect#destroy GMain.Main.quit) ;
748 ignore (cancelb#connect#clicked window#destroy) ;
750 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
751 let dom,resolve_id = !id_to_uris in
753 (input#insert_text ~pos:0
758 match resolve_id v with
760 | Some (CicTextualParser0.Uri uri) -> uri
761 | Some (CicTextualParser0.Term _)
762 | Some CicTextualParser0.Implicit -> assert false
766 CicTextualParser0.Id id -> id
767 | CicTextualParser0.Symbol (descr,_) ->
768 (* CSC: To be implemented *)
770 )^ " " ^ (string_of_cic_textual_parser_uri uri)
776 let inputtext = input#get_chars 0 input#length in
778 let alfa = "[a-zA-Z_-]" in
779 let digit = "[0-9]" in
780 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
781 let blanks = "\( \|\t\|\n\)+" in
782 let nonblanks = "[^ \t\n]+" in
783 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
785 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
789 let n' = Str.search_forward regexpr inputtext n in
790 let id = CicTextualParser0.Id (Str.matched_group 2 inputtext) in
792 MQueryMisc.cic_textual_parser_uri_of_string
793 ("cic:" ^ (Str.matched_group 5 inputtext))
795 let dom,resolve_id = aux (n' + 1) in
796 if List.mem id dom then
802 Some (CicTextualParser0.Uri uri)
805 Not_found -> TermEditor.empty_id_to_uris
809 id_to_uris := (dom,resolve_id)
813 let module L = LogicalOperations in
814 let module G = Gdome in
815 let notebook = (rendering_window ())#notebook in
816 let output = (rendering_window ())#output in
817 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
819 output#make_sequent_of_selected_term ;
820 refresh_proof output ;
821 refresh_goals notebook
823 InvokeTactics.RefreshSequentException e ->
824 output_html outputhtml
825 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
826 "sequent: " ^ Printexc.to_string e ^ "</h1>")
827 | InvokeTactics.RefreshProofException e ->
828 output_html outputhtml
829 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
830 "proof: " ^ Printexc.to_string e ^ "</h1>")
832 output_html outputhtml
833 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
837 let module L = LogicalOperations in
838 let module G = Gdome in
839 let notebook = (rendering_window ())#notebook in
840 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
841 let output = (rendering_window ())#output in
843 output#focus_sequent_of_selected_term ;
844 refresh_goals notebook
846 InvokeTactics.RefreshSequentException e ->
847 output_html outputhtml
848 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
849 "sequent: " ^ Printexc.to_string e ^ "</h1>")
850 | InvokeTactics.RefreshProofException e ->
851 output_html outputhtml
852 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
853 "proof: " ^ Printexc.to_string e ^ "</h1>")
855 output_html outputhtml
856 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
859 exception NoPrevGoal;;
860 exception NoNextGoal;;
863 let module L = LogicalOperations in
864 let module G = Gdome in
865 let notebook = (rendering_window ())#notebook in
866 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
868 match !ProofEngine.proof with
870 | Some (_,metasenv,_,_) -> metasenv
873 refresh_goals ~empty_notebook:false notebook
875 InvokeTactics.RefreshSequentException e ->
876 output_html outputhtml
877 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
878 "sequent: " ^ Printexc.to_string e ^ "</h1>")
880 output_html outputhtml
881 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
885 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
888 GWindow.window ~width:800 ~border_width:2 () in
889 let scrolled_window =
890 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
892 GMathViewAux.single_selection_math_view
893 ~packing:scrolled_window#add ~width:600 ~height:400 ()
895 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
896 let href = Gdome.domString "href" in
897 let show_in_show_window_obj uri obj =
898 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
901 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
902 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
904 Cic2acic.acic_object_of_cic_object obj
907 ApplyStylesheets.mml_of_cic_object
908 ~explode_all:false uri acic ids_to_inner_sorts ids_to_inner_types
910 window#set_title (UriManager.string_of_uri uri) ;
911 window#misc#hide () ; window#show () ;
912 mmlwidget#load_doc mml ;
915 output_html outputhtml
916 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
918 let show_in_show_window_uri uri =
919 let obj = CicEnvironment.get_obj uri in
920 show_in_show_window_obj uri obj
922 let show_in_show_window_callback mmlwidget (n : Gdome.element option) _ =
926 if n'#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
928 (n'#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
930 show_in_show_window_uri (UriManager.uri_of_string uri)
932 ignore (mmlwidget#action_toggle n')
935 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
937 show_in_show_window_obj, show_in_show_window_uri,
938 show_in_show_window_callback
941 exception NoObjectsLocated;;
943 let user_uri_choice ~title ~msg uris =
946 [] -> raise NoObjectsLocated
950 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
955 String.sub uri 4 (String.length uri - 4)
958 let locate_callback id =
959 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
960 let result = MQueryGenerator.locate mqi_handle id in
964 MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri)
967 (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>")
969 output_html outputhtml html ;
970 user_uri_choice ~title:"Ambiguous input."
972 ("Ambiguous input \"" ^ id ^
973 "\". Please, choose one interpetation:")
978 let input_or_locate_uri ~title =
979 let uri = ref None in
982 ~width:400 ~modal:true ~title ~border_width:2 () in
983 let vbox = GPack.vbox ~packing:window#add () in
985 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
987 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
989 GEdit.entry ~editable:true
990 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
992 GButton.button ~label:"Check"
993 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
994 let _ = checkb#misc#set_sensitive false in
996 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
998 GMisc.label ~text:"You can also enter an indentifier to locate:"
999 ~packing:(hbox2#pack ~padding:5) () in
1001 GEdit.entry ~editable:true
1002 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1004 GButton.button ~label:"Locate"
1005 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1006 let _ = locateb#misc#set_sensitive false in
1008 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1010 GButton.button ~label:"Ok"
1011 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1012 let _ = okb#misc#set_sensitive false in
1014 GButton.button ~label:"Cancel"
1015 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1017 ignore (window#connect#destroy GMain.Main.quit) ;
1019 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1020 let check_callback () =
1021 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1022 let uri = "cic:" ^ manual_input#text in
1024 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1025 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1028 Getter.Unresolved ->
1029 output_html outputhtml
1030 ("<h1 color=\"Red\">URI " ^ uri ^
1031 " does not correspond to any object.</h1>") ;
1033 | UriManager.IllFormedUri _ ->
1034 output_html outputhtml
1035 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1038 output_html outputhtml
1039 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1043 (okb#connect#clicked
1045 if check_callback () then
1047 uri := Some manual_input#text ;
1051 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1053 (manual_input#connect#changed
1055 if manual_input#text = "" then
1057 checkb#misc#set_sensitive false ;
1058 okb#misc#set_sensitive false
1062 checkb#misc#set_sensitive true ;
1063 okb#misc#set_sensitive true
1066 (locate_input#connect#changed
1067 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1069 (locateb#connect#clicked
1071 let id = locate_input#text in
1072 manual_input#set_text (locate_callback id) ;
1073 locate_input#delete_text 0 (String.length id)
1078 None -> raise NoChoice
1079 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1082 exception AmbiguousInput;;
1084 (* A WIDGET TO ENTER CIC TERMS *)
1086 module ChosenTermEditor = TexTermEditor;;
1087 module ChosenTextualParser0 = TexCicTextualParser0;;
1089 module ChosenTermEditor = TermEditor;;
1090 module ChosenTextualParser0 = CicTextualParser0;;
1095 let get_metasenv () = !ChosenTextualParser0.metasenv
1096 let set_metasenv metasenv = ChosenTextualParser0.metasenv := metasenv
1098 let output_html msg = output_html (outputhtml ()) msg;;
1099 let interactive_user_uri_choice =
1100 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1101 interactive_user_uri_choice ~selection_mode ?ok
1102 ?enable_button_for_non_vars ~title ~msg;;
1103 let interactive_interpretation_choice = interactive_interpretation_choice;;
1104 let input_or_locate_uri = input_or_locate_uri;;
1108 module TexTermEditor' = ChosenTermEditor.Make(Callbacks);;
1110 (* OTHER FUNCTIONS *)
1113 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1114 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1117 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1119 None -> raise NoChoice
1121 let uri = locate_callback input in
1125 output_html outputhtml
1126 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1130 exception UriAlreadyInUse;;
1131 exception NotAUriToAConstant;;
1133 let new_inductive () =
1134 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1135 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1136 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1137 let notebook = (rendering_window ())#notebook in
1139 let chosen = ref false in
1140 let inductive = ref true in
1141 let paramsno = ref 0 in
1142 let get_uri = ref (function _ -> assert false) in
1143 let get_base_uri = ref (function _ -> assert false) in
1144 let get_names = ref (function _ -> assert false) in
1145 let get_types_and_cons = ref (function _ -> assert false) in
1146 let get_context_and_subst = ref (function _ -> assert false) in
1149 ~width:600 ~modal:true ~position:`CENTER
1150 ~title:"New Block of Mutual (Co)Inductive Definitions"
1151 ~border_width:2 () in
1152 let vbox = GPack.vbox ~packing:window#add () in
1154 GPack.hbox ~border_width:0
1155 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1157 GMisc.label ~text:"Enter the URI for the new block:"
1158 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1160 GEdit.entry ~editable:true
1161 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1163 GPack.hbox ~border_width:0
1164 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1168 "Enter the number of left parameters in every arity and constructor type:"
1169 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1170 let paramsno_entry =
1171 GEdit.entry ~editable:true ~text:"0"
1172 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1174 GPack.hbox ~border_width:0
1175 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1177 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1178 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1180 GButton.radio_button ~label:"Inductive"
1181 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1183 GButton.radio_button ~label:"Coinductive"
1184 ~group:inductiveb#group
1185 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1187 GPack.hbox ~border_width:0
1188 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1190 GMisc.label ~text:"Enter the list of the names of the types:"
1191 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1193 GEdit.entry ~editable:true
1194 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1196 GPack.hbox ~border_width:0
1197 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1199 GButton.button ~label:"> Next"
1200 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1201 let _ = okb#misc#set_sensitive true in
1203 GButton.button ~label:"Abort"
1204 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1205 ignore (window#connect#destroy GMain.Main.quit) ;
1206 ignore (cancelb#connect#clicked window#destroy) ;
1210 (okb#connect#clicked
1213 let uristr = "cic:" ^ uri_entry#text in
1214 let namesstr = names_entry#text in
1215 let paramsno' = int_of_string (paramsno_entry#text) in
1216 match Str.split (Str.regexp " +") namesstr with
1218 | (he::tl) as names ->
1219 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1222 ignore (Getter.resolve uri) ;
1223 raise UriAlreadyInUse
1225 Getter.Unresolved ->
1226 get_uri := (function () -> uri) ;
1227 get_names := (function () -> names) ;
1228 inductive := inductiveb#active ;
1229 paramsno := paramsno' ;
1234 output_html outputhtml
1235 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1243 GBin.frame ~label:name
1244 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1245 let vbox = GPack.vbox ~packing:frame#add () in
1246 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1248 GMisc.label ~text:("Enter its type:")
1249 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1250 let scrolled_window =
1251 GBin.scrolled_window ~border_width:5
1252 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1254 TexTermEditor'.term_editor
1256 ~width:400 ~height:20 ~packing:scrolled_window#add
1257 ~share_id_to_uris_with:inputt ()
1258 ~isnotempty_callback:
1260 (*non_empty_type := b ;*)
1261 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1264 GPack.hbox ~border_width:0
1265 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1267 GMisc.label ~text:("Enter the list of its constructors:")
1268 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1269 let cons_names_entry =
1270 GEdit.entry ~editable:true
1271 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1272 (newinputt,cons_names_entry)
1275 vbox#remove hboxn#coerce ;
1277 GPack.hbox ~border_width:0
1278 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1280 GButton.button ~label:"> Next"
1281 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1283 GButton.button ~label:"Abort"
1284 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1285 ignore (cancelb#connect#clicked window#destroy) ;
1287 (okb#connect#clicked
1290 let names = !get_names () in
1291 let types_and_cons =
1293 (fun name (newinputt,cons_names_entry) ->
1294 let consnamesstr = cons_names_entry#text in
1295 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1297 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1300 [] -> expr,cons_names
1301 | _ -> raise AmbiguousInput
1302 ) names type_widgets
1304 let uri = !get_uri () in
1306 (* Let's see if so far the definition is well-typed *)
1309 (* To test if the arities of the inductive types are well *)
1310 (* typed, we check the inductive block definition where *)
1311 (* no constructor is given to each type. *)
1314 (fun name (ty,cons) -> (name, !inductive, ty, []))
1315 names types_and_cons
1317 CicTypeChecker.typecheck_mutual_inductive_defs uri
1318 (tys,params,paramsno)
1320 get_context_and_subst :=
1324 (fun (context,subst) name (ty,_) ->
1326 (Some (Cic.Name name, Cic.Decl ty))::context,
1327 (Cic.MutInd (uri,!i,[]))::subst
1330 ) ([],[]) names types_and_cons) ;
1331 let types_and_cons' =
1333 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1334 names types_and_cons
1336 get_types_and_cons := (function () -> types_and_cons') ;
1341 output_html outputhtml
1342 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1345 and phase3 name cons =
1346 let get_cons_types = ref (function () -> assert false) in
1349 ~width:600 ~modal:true ~position:`CENTER
1350 ~title:(name ^ " Constructors")
1351 ~border_width:2 () in
1352 let vbox = GPack.vbox ~packing:window2#add () in
1353 let cons_type_widgets =
1355 (function consname ->
1357 GPack.hbox ~border_width:0
1358 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1360 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1361 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1362 let scrolled_window =
1363 GBin.scrolled_window ~border_width:5
1364 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1366 TexTermEditor'.term_editor
1368 ~width:400 ~height:20 ~packing:scrolled_window#add
1369 ~share_id_to_uris_with:inputt ()
1370 ~isnotempty_callback:
1372 (* (*non_empty_type := b ;*)
1373 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1378 GPack.hbox ~border_width:0
1379 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1381 GButton.button ~label:"> Next"
1382 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1383 let _ = okb#misc#set_sensitive true in
1385 GButton.button ~label:"Abort"
1386 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1387 ignore (window2#connect#destroy GMain.Main.quit) ;
1388 ignore (cancelb#connect#clicked window2#destroy) ;
1390 (okb#connect#clicked
1394 let context,subst= !get_context_and_subst () in
1399 inputt#get_metasenv_and_term ~context ~metasenv:[]
1403 let undebrujined_expr =
1405 (fun expr t -> CicSubstitution.subst t expr) expr subst
1407 name, undebrujined_expr
1408 | _ -> raise AmbiguousInput
1409 ) cons cons_type_widgets
1411 get_cons_types := (function () -> cons_types) ;
1415 output_html outputhtml
1416 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1420 let okb_pressed = !chosen in
1422 if (not okb_pressed) then
1425 assert false (* The control never reaches this point *)
1428 (!get_cons_types ())
1431 (* No more phases left or Abort pressed *)
1437 let uri = !get_uri () in
1440 let tys = !get_types_and_cons () in
1441 let obj = Cic.InductiveDefinition tys params !paramsno in
1444 prerr_endline (CicPp.ppobj obj) ;
1445 CicTypeChecker.typecheck_mutual_inductive_defs uri
1446 (tys,params,!paramsno) ;
1449 prerr_endline "Offending mutual (co)inductive type declaration:" ;
1450 prerr_endline (CicPp.ppobj obj) ;
1452 (* We already know that obj is well-typed. We need to add it to the *)
1453 (* environment in order to compute the inner-types without having to *)
1454 (* debrujin it or having to modify lots of other functions to avoid *)
1455 (* asking the environment for the MUTINDs we are defining now. *)
1456 CicEnvironment.put_inductive_definition uri obj ;
1458 show_in_show_window_obj uri obj
1461 output_html outputhtml
1462 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1466 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1467 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1468 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1469 let notebook = (rendering_window ())#notebook in
1471 let chosen = ref false in
1472 let get_metasenv_and_term = ref (function _ -> assert false) in
1473 let get_uri = ref (function _ -> assert false) in
1474 let non_empty_type = ref false in
1477 ~width:600 ~modal:true ~title:"New Proof or Definition"
1478 ~border_width:2 () in
1479 let vbox = GPack.vbox ~packing:window#add () in
1481 GPack.hbox ~border_width:0
1482 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1484 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1485 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1487 GEdit.entry ~editable:true
1488 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1490 GPack.hbox ~border_width:0
1491 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1493 GMisc.label ~text:"Enter the theorem or definition type:"
1494 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1495 let scrolled_window =
1496 GBin.scrolled_window ~border_width:5
1497 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1498 (* the content of the scrolled_window is moved below (see comment) *)
1500 GPack.hbox ~border_width:0
1501 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1503 GButton.button ~label:"Ok"
1504 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1505 let _ = okb#misc#set_sensitive false in
1507 GButton.button ~label:"Cancel"
1508 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1509 (* moved here to have visibility of the ok button *)
1511 TexTermEditor'.term_editor
1513 ~width:400 ~height:100 ~packing:scrolled_window#add
1514 ~share_id_to_uris_with:inputt ()
1515 ~isnotempty_callback:
1517 non_empty_type := b ;
1518 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1521 newinputt#set_term inputt#get_as_string ;
1524 uri_entry#connect#changed
1526 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1528 ignore (window#connect#destroy GMain.Main.quit) ;
1529 ignore (cancelb#connect#clicked window#destroy) ;
1531 (okb#connect#clicked
1535 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1536 let uristr = "cic:" ^ uri_entry#text in
1537 let uri = UriManager.uri_of_string uristr in
1538 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1539 raise NotAUriToAConstant
1543 ignore (Getter.resolve uri) ;
1544 raise UriAlreadyInUse
1546 Getter.Unresolved ->
1547 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1548 get_uri := (function () -> uri) ;
1553 output_html outputhtml
1554 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1560 let metasenv,expr = !get_metasenv_and_term () in
1561 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1562 ProofEngine.proof :=
1563 Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1564 ProofEngine.goal := Some 1 ;
1565 refresh_goals notebook ;
1566 refresh_proof output ;
1567 !save_set_sensitive true ;
1569 ProofEngine.intros ~mk_fresh_name_callback () ;
1570 refresh_goals notebook ;
1571 refresh_proof output
1573 InvokeTactics.RefreshSequentException e ->
1574 output_html outputhtml
1575 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1576 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1577 | InvokeTactics.RefreshProofException e ->
1578 output_html outputhtml
1579 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1580 "proof: " ^ Printexc.to_string e ^ "</h1>")
1582 output_html outputhtml
1583 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1586 let check_term_in_scratch scratch_window metasenv context expr =
1588 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1589 let expr = Cic.Cast (expr,ty) in
1590 scratch_window#show () ;
1591 scratch_window#set_term expr ;
1592 scratch_window#set_context context ;
1593 scratch_window#set_metasenv metasenv ;
1594 scratch_window#sequent_viewer#load_sequent metasenv (111,context,expr)
1597 print_endline ("? " ^ CicPp.ppterm expr) ;
1601 let check scratch_window () =
1602 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1603 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1605 match !ProofEngine.proof with
1607 | Some (_,metasenv,_,_) -> metasenv
1610 match !ProofEngine.goal with
1613 let (_,canonical_context,_) =
1614 List.find (function (m,_,_) -> m=metano) metasenv
1619 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1620 check_term_in_scratch scratch_window metasenv' context expr
1623 output_html outputhtml
1624 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1628 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1630 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
1633 output_html outputhtml
1634 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1637 exception NotADefinition;;
1640 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1641 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1642 let notebook = (rendering_window ())#notebook in
1644 let uri = input_or_locate_uri ~title:"Open" in
1645 CicTypeChecker.typecheck uri ;
1646 let metasenv,bo,ty =
1647 match CicEnvironment.get_cooked_obj uri with
1648 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1649 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1652 | Cic.InductiveDefinition _ -> raise NotADefinition
1654 ProofEngine.proof :=
1655 Some (uri, metasenv, bo, ty) ;
1656 ProofEngine.goal := None ;
1657 refresh_goals notebook ;
1658 refresh_proof output
1660 InvokeTactics.RefreshSequentException e ->
1661 output_html outputhtml
1662 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1663 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1664 | InvokeTactics.RefreshProofException e ->
1665 output_html outputhtml
1666 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1667 "proof: " ^ Printexc.to_string e ^ "</h1>")
1669 output_html outputhtml
1670 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1673 let show_query_results results =
1676 ~modal:false ~title:"Query results." ~border_width:2 () in
1677 let vbox = GPack.vbox ~packing:window#add () in
1679 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1682 ~text:"Click on a URI to show that object"
1683 ~packing:hbox#add () in
1684 let scrolled_window =
1685 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1686 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1687 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
1690 (function (uri,_) ->
1694 clist#set_row ~selectable:false n
1697 clist#columns_autosize () ;
1699 (clist#connect#select_row
1700 (fun ~row ~column ~event ->
1701 let (uristr,_) = List.nth results row in
1703 MQueryMisc.cic_textual_parser_uri_of_string
1704 (MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format'
1707 CicTextualParser0.ConUri uri
1708 | CicTextualParser0.VarUri uri
1709 | CicTextualParser0.IndTyUri (uri,_)
1710 | CicTextualParser0.IndConUri (uri,_,_) ->
1711 show_in_show_window_uri uri
1717 let refine_constraints (must_obj,must_rel,must_sort) =
1718 let chosen = ref false in
1719 let use_only = ref false in
1722 ~modal:true ~title:"Constraints refinement."
1723 ~width:800 ~border_width:2 () in
1724 let vbox = GPack.vbox ~packing:window#add () in
1726 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1729 ~text: "\"Only\" constraints can be enforced or not."
1730 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1732 GButton.toggle_button ~label:"Enforce \"only\" constraints"
1733 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1736 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
1737 (* Notebook for the constraints choice *)
1739 GPack.notebook ~scrollable:true
1740 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1741 (* Rel constraints *)
1744 ~text: "Constraints on Rels" () in
1746 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1749 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1752 ~text: "You can now specify the constraints on Rels."
1753 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1754 let expected_height = 25 * (List.length must_rel + 2) in
1755 let height = if expected_height > 400 then 400 else expected_height in
1756 let scrolled_window =
1757 GBin.scrolled_window ~border_width:10 ~height ~width:600
1758 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1759 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1760 let rel_constraints =
1762 (function (position,depth) ->
1765 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1769 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1771 None -> position, ref None
1773 let mutable_ref = ref (Some depth') in
1775 GButton.toggle_button
1776 ~label:("depth = " ^ string_of_int depth') ~active:true
1777 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1780 (depthb#connect#toggled
1782 let sel_depth = if depthb#active then Some depth' else None in
1783 mutable_ref := sel_depth
1785 position, mutable_ref
1787 (* Sort constraints *)
1790 ~text: "Constraints on Sorts" () in
1792 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1795 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1798 ~text: "You can now specify the constraints on Sorts."
1799 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1800 let expected_height = 25 * (List.length must_sort + 2) in
1801 let height = if expected_height > 400 then 400 else expected_height in
1802 let scrolled_window =
1803 GBin.scrolled_window ~border_width:10 ~height ~width:600
1804 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1805 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1806 let sort_constraints =
1808 (function (position,depth,sort) ->
1811 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1814 ~text:(sort ^ " " ^ position)
1815 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1817 None -> position, ref None, sort
1819 let mutable_ref = ref (Some depth') in
1821 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
1823 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1826 (depthb#connect#toggled
1828 let sel_depth = if depthb#active then Some depth' else None in
1829 mutable_ref := sel_depth
1831 position, mutable_ref, sort
1833 (* Obj constraints *)
1836 ~text: "Constraints on constants" () in
1838 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1841 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1844 ~text: "You can now specify the constraints on constants."
1845 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1846 let expected_height = 25 * (List.length must_obj + 2) in
1847 let height = if expected_height > 400 then 400 else expected_height in
1848 let scrolled_window =
1849 GBin.scrolled_window ~border_width:10 ~height ~width:600
1850 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1851 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1852 let obj_constraints =
1854 (function (uri,position,depth) ->
1857 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1860 ~text:(uri ^ " " ^ position)
1861 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1863 None -> uri, position, ref None
1865 let mutable_ref = ref (Some depth') in
1867 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
1869 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1872 (depthb#connect#toggled
1874 let sel_depth = if depthb#active then Some depth' else None in
1875 mutable_ref := sel_depth
1877 uri, position, mutable_ref
1879 (* Confirm/abort buttons *)
1881 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1883 GButton.button ~label:"Ok"
1884 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1886 GButton.button ~label:"Abort"
1887 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1889 ignore (window#connect#destroy GMain.Main.quit) ;
1890 ignore (cancelb#connect#clicked window#destroy) ;
1892 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
1893 window#set_position `CENTER ;
1897 let chosen_must_rel =
1899 (function (position,ref_depth) -> position,!ref_depth) rel_constraints in
1900 let chosen_must_sort =
1902 (function (position,ref_depth,sort) -> position,!ref_depth,sort)
1905 let chosen_must_obj =
1907 (function (uri,position,ref_depth) -> uri,position,!ref_depth)
1910 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
1912 (*CSC: ???????????????????????? I assume that must and only are the same... *)
1913 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
1921 let completeSearchPattern () =
1922 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1923 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1925 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
1926 let must = MQueryLevels2.get_constraints expr in
1927 let must',only = refine_constraints must in
1928 let results = MQueryGenerator.searchPattern mqi_handle must' only in
1929 show_query_results results
1932 output_html outputhtml
1933 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1936 let insertQuery () =
1937 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1939 let chosen = ref None in
1942 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
1943 let vbox = GPack.vbox ~packing:window#add () in
1945 GMisc.label ~text:"Insert Query. For Experts Only."
1946 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1947 let scrolled_window =
1948 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1949 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1950 let input = GEdit.text ~editable:true
1951 ~packing:scrolled_window#add () in
1953 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1955 GButton.button ~label:"Ok"
1956 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1958 GButton.button ~label:"Load from file..."
1959 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1961 GButton.button ~label:"Abort"
1962 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1963 ignore (window#connect#destroy GMain.Main.quit) ;
1964 ignore (cancelb#connect#clicked window#destroy) ;
1966 (okb#connect#clicked
1968 chosen := Some (input#get_chars 0 input#length) ; window#destroy ())) ;
1970 (loadb#connect#clicked
1973 GToolbox.select_file ~title:"Select Query File" ()
1977 let inch = open_in filename in
1978 let rec read_file () =
1980 let line = input_line inch in
1981 line ^ "\n" ^ read_file ()
1985 let text = read_file () in
1986 input#delete_text 0 input#length ;
1987 ignore (input#insert_text text ~pos:0))) ;
1988 window#set_position `CENTER ;
1995 MQI.execute mqi_handle (MQueryUtil.query_of_text (Lexing.from_string q))
1997 show_query_results results
2000 output_html outputhtml
2001 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2004 let choose_must list_of_must only =
2005 let chosen = ref None in
2006 let user_constraints = ref [] in
2009 ~modal:true ~title:"Query refinement." ~border_width:2 () in
2010 let vbox = GPack.vbox ~packing:window#add () in
2012 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2016 ("You can now specify the genericity of the query. " ^
2017 "The more generic the slower.")
2018 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2020 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2024 "Suggestion: start with faster queries before moving to more generic ones."
2025 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2027 GPack.notebook ~scrollable:true
2028 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2031 let last = List.length list_of_must in
2037 (if !page = 1 then "More generic" else
2038 if !page = last then "More precise" else " ") () in
2039 let expected_height = 25 * (List.length must + 2) in
2040 let height = if expected_height > 400 then 400 else expected_height in
2041 let scrolled_window =
2042 GBin.scrolled_window ~border_width:10 ~height ~width:600
2043 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2045 GList.clist ~columns:2 ~packing:scrolled_window#add
2046 ~titles:["URI" ; "Position"] ()
2050 (function (uri,position) ->
2053 [uri; if position then "MainConclusion" else "Conclusion"]
2055 clist#set_row ~selectable:false n
2058 clist#columns_autosize ()
2061 let label = GMisc.label ~text:"User provided" () in
2063 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2065 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2068 ~text:"Select the constraints that must be satisfied and press OK."
2069 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2070 let expected_height = 25 * (List.length only + 2) in
2071 let height = if expected_height > 400 then 400 else expected_height in
2072 let scrolled_window =
2073 GBin.scrolled_window ~border_width:10 ~height ~width:600
2074 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2076 GList.clist ~columns:2 ~packing:scrolled_window#add
2077 ~selection_mode:`EXTENDED
2078 ~titles:["URI" ; "Position"] ()
2082 (function (uri,position) ->
2085 [uri; if position then "MainConclusion" else "Conclusion"]
2087 clist#set_row ~selectable:true n
2090 clist#columns_autosize () ;
2092 (clist#connect#select_row
2093 (fun ~row ~column ~event ->
2094 user_constraints := (List.nth only row)::!user_constraints)) ;
2096 (clist#connect#unselect_row
2097 (fun ~row ~column ~event ->
2100 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2103 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2105 GButton.button ~label:"Ok"
2106 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2108 GButton.button ~label:"Abort"
2109 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2111 ignore (window#connect#destroy GMain.Main.quit) ;
2112 ignore (cancelb#connect#clicked window#destroy) ;
2114 (okb#connect#clicked
2115 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2116 window#set_position `CENTER ;
2120 None -> raise NoChoice
2122 if n = List.length list_of_must then
2123 (* user provided constraints *)
2126 List.nth list_of_must n
2129 let searchPattern () =
2130 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
2131 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2134 match !ProofEngine.proof with
2135 None -> assert false
2136 | Some proof -> proof
2138 match !ProofEngine.goal with
2142 TacticChaser.searchPattern
2144 ~output_html:(output_html outputhtml) ~choose_must ()
2145 ~status:(proof, metano)
2148 user_uri_choice ~title:"Ambiguous input."
2149 ~msg: "Many lemmas can be successfully applied. Please, choose one:"
2152 inputt#set_term uri' ;
2153 InvokeTactics'.apply ()
2156 output_html outputhtml
2157 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2160 let choose_selection mmlwidget (element : Gdome.element option) =
2161 let module G = Gdome in
2162 let rec aux element =
2163 if element#hasAttributeNS
2164 ~namespaceURI:Misc.helmns
2165 ~localName:(G.domString "xref")
2167 mmlwidget#set_selection (Some element)
2170 match element#get_parentNode with
2171 None -> assert false
2172 (*CSC: OCAML DIVERGES!
2173 | Some p -> aux (new G.element_of_node p)
2175 | Some p -> aux (new Gdome.element_of_node p)
2177 GdomeInit.DOMCastException _ ->
2179 "******* trying to select above the document root ********"
2183 | None -> mmlwidget#set_selection None
2186 (* STUFF TO BUILD THE GTK INTERFACE *)
2188 (* Stuff for the widget settings *)
2190 let export_to_postscript output =
2191 let lastdir = ref (Unix.getcwd ()) in
2194 GToolbox.select_file ~title:"Export to PostScript"
2195 ~dir:lastdir ~filename:"screenshot.ps" ()
2199 (output :> GMathView.math_view)#export_to_postscript
2200 ~filename:filename ();
2203 let activate_t1 output button_set_anti_aliasing
2204 button_set_transparency export_to_postscript_menu_item
2207 let is_set = button_t1#active in
2208 output#set_font_manager_type
2209 ~fm_type:(if is_set then `font_manager_t1 else `font_manager_gtk) ;
2212 button_set_anti_aliasing#misc#set_sensitive true ;
2213 button_set_transparency#misc#set_sensitive true ;
2214 export_to_postscript_menu_item#misc#set_sensitive true ;
2218 button_set_anti_aliasing#misc#set_sensitive false ;
2219 button_set_transparency#misc#set_sensitive false ;
2220 export_to_postscript_menu_item#misc#set_sensitive false ;
2224 let set_anti_aliasing output button_set_anti_aliasing () =
2225 output#set_anti_aliasing button_set_anti_aliasing#active
2228 let set_transparency output button_set_transparency () =
2229 output#set_transparency button_set_transparency#active
2232 let changefont output font_size_spinb () =
2233 output#set_font_size font_size_spinb#value_as_int
2236 let set_log_verbosity output log_verbosity_spinb () =
2237 output#set_log_verbosity log_verbosity_spinb#value_as_int
2240 class settings_window output sw
2241 export_to_postscript_menu_item selection_changed_callback
2243 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2245 GPack.vbox ~packing:settings_window#add () in
2248 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2249 ~border_width:5 ~packing:vbox#add () in
2251 GButton.toggle_button ~label:"activate t1 fonts"
2252 ~packing:(table#attach ~left:0 ~top:0) () in
2253 let button_set_anti_aliasing =
2254 GButton.toggle_button ~label:"set_anti_aliasing"
2255 ~packing:(table#attach ~left:0 ~top:1) () in
2256 let button_set_transparency =
2257 GButton.toggle_button ~label:"set_transparency"
2258 ~packing:(table#attach ~left:2 ~top:1) () in
2261 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2262 ~border_width:5 ~packing:vbox#add () in
2263 let font_size_label =
2264 GMisc.label ~text:"font size:"
2265 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2266 let font_size_spinb =
2268 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2271 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2272 let log_verbosity_label =
2273 GMisc.label ~text:"log verbosity:"
2274 ~packing:(table#attach ~left:0 ~top:1) () in
2275 let log_verbosity_spinb =
2277 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2280 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2282 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2284 GButton.button ~label:"Close"
2285 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2287 method show = settings_window#show
2289 button_set_anti_aliasing#misc#set_sensitive false ;
2290 button_set_transparency#misc#set_sensitive false ;
2291 (* Signals connection *)
2292 ignore(button_t1#connect#clicked
2293 (activate_t1 output button_set_anti_aliasing
2294 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2295 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2296 ignore(button_set_anti_aliasing#connect#toggled
2297 (set_anti_aliasing output button_set_anti_aliasing));
2298 ignore(button_set_transparency#connect#toggled
2299 (set_transparency output button_set_transparency)) ;
2300 ignore(log_verbosity_spinb#connect#changed
2301 (set_log_verbosity output log_verbosity_spinb)) ;
2302 ignore(closeb#connect#clicked settings_window#misc#hide)
2305 (* Scratch window *)
2307 class scratch_window =
2310 ~title:"MathML viewer"
2311 ~border_width:2 () in
2313 GPack.vbox ~packing:window#add () in
2315 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2317 GButton.button ~label:"Whd"
2318 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2320 GButton.button ~label:"Reduce"
2321 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2323 GButton.button ~label:"Simpl"
2324 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2325 let scrolled_window =
2326 GBin.scrolled_window ~border_width:10
2327 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2328 let sequent_viewer =
2329 TermViewer.sequent_viewer
2330 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2332 val mutable term = Cic.Rel 1 (* dummy value *)
2333 val mutable context = ([] : Cic.context) (* dummy value *)
2334 val mutable metasenv = ([] : Cic.metasenv) (* dummy value *)
2335 method sequent_viewer = sequent_viewer
2336 method show () = window#misc#hide () ; window#show ()
2338 method set_term t = term <- t
2339 method context = context
2340 method set_context t = context <- t
2341 method metasenv = metasenv
2342 method set_metasenv t = metasenv <- t
2345 (sequent_viewer#connect#selection_changed (choose_selection sequent_viewer));
2346 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2347 ignore(whdb#connect#clicked InvokeTactics'.whd_in_scratch) ;
2348 ignore(reduceb#connect#clicked InvokeTactics'.reduce_in_scratch) ;
2349 ignore(simplb#connect#clicked InvokeTactics'.simpl_in_scratch)
2352 let open_contextual_menu_for_selected_terms mmlwidget infos =
2353 let button = GdkEvent.Button.button infos in
2354 let terms_selected = List.length mmlwidget#get_selections > 0 in
2357 let time = GdkEvent.Button.time infos in
2358 let menu = GMenu.menu () in
2359 let f = new GMenu.factory menu in
2361 f#add_item "Whd" ~key:GdkKeysyms._W ~callback:InvokeTactics'.whd in
2362 let reduce_menu_item =
2363 f#add_item "Reduce" ~key:GdkKeysyms._R ~callback:InvokeTactics'.reduce in
2364 let simpl_menu_item =
2365 f#add_item "Simpl" ~key:GdkKeysyms._S ~callback:InvokeTactics'.simpl in
2366 let _ = f#add_separator () in
2367 let generalize_menu_item =
2368 f#add_item "Generalize"
2369 ~key:GdkKeysyms._G ~callback:InvokeTactics'.generalize in
2370 let _ = f#add_separator () in
2371 let clear_menu_item =
2372 f#add_item "Clear" ~key:GdkKeysyms._C ~callback:InvokeTactics'.clear in
2373 let clearbody_menu_item =
2374 f#add_item "ClearBody"
2375 ~key:GdkKeysyms._B ~callback:InvokeTactics'.clearbody
2377 whd_menu_item#misc#set_sensitive terms_selected ;
2378 reduce_menu_item#misc#set_sensitive terms_selected ;
2379 simpl_menu_item#misc#set_sensitive terms_selected ;
2380 generalize_menu_item#misc#set_sensitive terms_selected ;
2381 clear_menu_item#misc#set_sensitive terms_selected ;
2382 clearbody_menu_item#misc#set_sensitive terms_selected ;
2383 menu#popup ~button ~time
2389 let vbox1 = GPack.vbox () in
2391 val mutable proofw_ref = None
2392 val mutable compute_ref = None
2394 Lazy.force self#compute ;
2395 match proofw_ref with
2396 None -> assert false
2397 | Some proofw -> proofw
2398 method content = vbox1
2400 match compute_ref with
2401 None -> assert false
2402 | Some compute -> compute
2406 let scrolled_window1 =
2407 GBin.scrolled_window ~border_width:10
2408 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2410 TermViewer.sequent_viewer ~width:400 ~height:275
2411 ~packing:(scrolled_window1#add) () in
2412 let _ = proofw_ref <- Some proofw in
2414 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2416 GButton.button ~label:"Ring"
2417 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2419 GButton.button ~label:"Fourier"
2420 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2422 GButton.button ~label:"Reflexivity"
2423 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2425 GButton.button ~label:"Symmetry"
2426 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2428 GButton.button ~label:"Assumption"
2429 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2430 let contradictionb =
2431 GButton.button ~label:"Contradiction"
2432 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2434 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2436 GButton.button ~label:"Exists"
2437 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2439 GButton.button ~label:"Split"
2440 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2442 GButton.button ~label:"Left"
2443 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2445 GButton.button ~label:"Right"
2446 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2447 let searchpatternb =
2448 GButton.button ~label:"SearchPattern_Apply"
2449 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2451 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2453 GButton.button ~label:"Exact"
2454 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2456 GButton.button ~label:"Intros"
2457 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2459 GButton.button ~label:"Apply"
2460 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2461 let elimintrossimplb =
2462 GButton.button ~label:"ElimIntrosSimpl"
2463 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2465 GButton.button ~label:"ElimType"
2466 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2468 GButton.button ~label:"Fold_whd"
2469 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2471 GButton.button ~label:"Fold_reduce"
2472 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2474 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2476 GButton.button ~label:"Fold_simpl"
2477 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2479 GButton.button ~label:"Cut"
2480 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2482 GButton.button ~label:"Change"
2483 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2485 GButton.button ~label:"Let ... In"
2486 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2488 GButton.button ~label:"RewriteSimpl ->"
2489 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2490 let rewritebacksimplb =
2491 GButton.button ~label:"RewriteSimpl <-"
2492 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2494 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2496 GButton.button ~label:"Absurd"
2497 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2499 GButton.button ~label:"Decompose"
2500 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2502 GButton.button ~label:"Transitivity"
2503 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2505 GButton.button ~label:"Replace"
2506 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2508 GButton.button ~label:"Injection"
2509 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2511 GButton.button ~label:"Discriminate"
2512 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2513 (* Zack: spostare in una toolbar
2515 GButton.button ~label:"Generalize"
2516 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2518 GButton.button ~label:"ClearBody"
2519 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2521 GButton.button ~label:"Clear"
2522 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2524 GButton.button ~label:"Whd"
2525 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2527 GButton.button ~label:"Reduce"
2528 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2530 GButton.button ~label:"Simpl"
2531 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2534 ignore(exactb#connect#clicked InvokeTactics'.exact) ;
2535 ignore(applyb#connect#clicked InvokeTactics'.apply) ;
2536 ignore(elimintrossimplb#connect#clicked InvokeTactics'.elimintrossimpl) ;
2537 ignore(elimtypeb#connect#clicked InvokeTactics'.elimtype) ;
2538 ignore(foldwhdb#connect#clicked InvokeTactics'.fold_whd) ;
2539 ignore(foldreduceb#connect#clicked InvokeTactics'.fold_reduce) ;
2540 ignore(foldsimplb#connect#clicked InvokeTactics'.fold_simpl) ;
2541 ignore(cutb#connect#clicked InvokeTactics'.cut) ;
2542 ignore(changeb#connect#clicked InvokeTactics'.change) ;
2543 ignore(letinb#connect#clicked InvokeTactics'.letin) ;
2544 ignore(ringb#connect#clicked InvokeTactics'.ring) ;
2545 ignore(fourierb#connect#clicked InvokeTactics'.fourier) ;
2546 ignore(rewritesimplb#connect#clicked InvokeTactics'.rewritesimpl) ;
2547 ignore(rewritebacksimplb#connect#clicked InvokeTactics'.rewritebacksimpl) ;
2548 ignore(replaceb#connect#clicked InvokeTactics'.replace) ;
2549 ignore(reflexivityb#connect#clicked InvokeTactics'.reflexivity) ;
2550 ignore(symmetryb#connect#clicked InvokeTactics'.symmetry) ;
2551 ignore(transitivityb#connect#clicked InvokeTactics'.transitivity) ;
2552 ignore(existsb#connect#clicked InvokeTactics'.exists) ;
2553 ignore(splitb#connect#clicked InvokeTactics'.split) ;
2554 ignore(leftb#connect#clicked InvokeTactics'.left) ;
2555 ignore(rightb#connect#clicked InvokeTactics'.right) ;
2556 ignore(assumptionb#connect#clicked InvokeTactics'.assumption) ;
2557 ignore(absurdb#connect#clicked InvokeTactics'.absurd) ;
2558 ignore(contradictionb#connect#clicked InvokeTactics'.contradiction) ;
2559 ignore(introsb#connect#clicked InvokeTactics'.intros) ;
2560 ignore(decomposeb#connect#clicked InvokeTactics'.decompose) ;
2561 ignore(searchpatternb#connect#clicked searchPattern) ;
2562 ignore(injectionb#connect#clicked InvokeTactics'.injection) ;
2563 ignore(discriminateb#connect#clicked InvokeTactics'.discriminate) ;
2564 (* Zack: spostare in una toolbar
2565 ignore(whdb#connect#clicked whd) ;
2566 ignore(reduceb#connect#clicked reduce) ;
2567 ignore(simplb#connect#clicked simpl) ;
2568 ignore(clearbodyb#connect#clicked clearbody) ;
2569 ignore(clearb#connect#clicked clear) ;
2570 ignore(generalizeb#connect#clicked generalize) ;
2572 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2574 ((new GObj.event_ops proofw#as_widget)#connect#button_press
2575 (open_contextual_menu_for_selected_terms proofw)) ;
2581 let vbox1 = GPack.vbox () in
2582 let scrolled_window1 =
2583 GBin.scrolled_window ~border_width:10
2584 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2586 TermViewer.sequent_viewer ~width:400 ~height:275
2587 ~packing:(scrolled_window1#add) () in
2589 method proofw = (assert false : TermViewer.sequent_viewer)
2590 method content = vbox1
2591 method compute = (assert false : unit)
2595 let empty_page = new empty_page;;
2599 val notebook = GPack.notebook ()
2601 val mutable skip_switch_page_event = false
2602 val mutable empty = true
2603 method notebook = notebook
2605 let new_page = new page () in
2607 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2608 notebook#append_page
2609 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2610 new_page#content#coerce
2611 method remove_all_pages ~skip_switch_page_event:skip =
2613 notebook#remove_page 0 (* let's remove the empty page *)
2615 List.iter (function _ -> notebook#remove_page 0) !pages ;
2617 skip_switch_page_event <- skip
2618 method set_current_page ~may_skip_switch_page_event n =
2619 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2620 let new_page = notebook#page_num page#content#coerce in
2621 if may_skip_switch_page_event && new_page <> notebook#current_page then
2622 skip_switch_page_event <- true ;
2623 notebook#goto_page new_page
2624 method set_empty_page =
2627 notebook#append_page
2628 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2629 empty_page#content#coerce
2631 let (_,_,page) = List.nth !pages notebook#current_page in
2635 (notebook#connect#switch_page
2637 let skip = skip_switch_page_event in
2638 skip_switch_page_event <- false ;
2641 let (metano,setgoal,page) = List.nth !pages i in
2642 ProofEngine.goal := Some metano ;
2643 Lazy.force (page#compute) ;
2652 class rendering_window output (notebook : notebook) =
2653 let scratch_window = new scratch_window in
2656 ~title:"gTopLevel - Helm's Proof Assistant"
2657 ~border_width:0 ~allow_shrink:false () in
2658 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2660 let handle_box = GBin.handle_box ~border_width:2
2661 ~packing:(vbox_for_menu#pack ~padding:0) () in
2662 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2663 let factory0 = new GMenu.factory menubar in
2664 let accel_group = factory0#accel_group in
2666 let file_menu = factory0#add_submenu "File" in
2667 let factory1 = new GMenu.factory file_menu ~accel_group in
2668 let export_to_postscript_menu_item =
2671 factory1#add_item "New Block of (Co)Inductive Definitions..."
2672 ~key:GdkKeysyms._B ~callback:new_inductive
2675 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2678 let reopen_menu_item =
2679 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2683 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2684 ignore (factory1#add_separator ()) ;
2686 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2687 ~callback:load_unfinished_proof) ;
2688 let save_menu_item =
2689 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S
2690 ~callback:save_unfinished_proof
2693 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2694 ignore (!save_set_sensitive false);
2695 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2696 ignore (!qed_set_sensitive false);
2697 ignore (factory1#add_separator ()) ;
2698 let export_to_postscript_menu_item =
2699 factory1#add_item "Export to PostScript..."
2700 ~callback:(export_to_postscript output) in
2701 ignore (factory1#add_separator ()) ;
2703 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) ;
2704 export_to_postscript_menu_item
2707 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2708 let factory2 = new GMenu.factory edit_menu ~accel_group in
2709 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2710 let proveit_menu_item =
2711 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2712 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2714 let focus_menu_item =
2715 factory2#add_item "Focus" ~key:GdkKeysyms._F
2716 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2719 focus_and_proveit_set_sensitive :=
2721 proveit_menu_item#misc#set_sensitive b ;
2722 focus_menu_item#misc#set_sensitive b
2724 let _ = !focus_and_proveit_set_sensitive false in
2725 (* edit term menu *)
2726 let edit_term_menu = factory0#add_submenu "Edit Term" in
2727 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2728 let check_menu_item =
2729 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2730 ~callback:(check scratch_window) in
2731 let _ = check_menu_item#misc#set_sensitive false in
2733 let search_menu = factory0#add_submenu "Search" in
2734 let factory4 = new GMenu.factory search_menu ~accel_group in
2736 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2738 let searchPattern_menu_item =
2739 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
2740 ~callback:completeSearchPattern in
2741 let _ = searchPattern_menu_item#misc#set_sensitive false in
2742 let show_menu_item =
2743 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2745 let insert_query_item =
2746 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._Y
2747 ~callback:insertQuery in
2749 let hbugs_menu = factory0#add_submenu "HBugs" in
2750 let factory6 = new GMenu.factory hbugs_menu ~accel_group in
2751 let toggle_hbugs_menu_item =
2752 factory6#add_check_item
2753 ~active:false ~key:GdkKeysyms._F5 ~callback:Hbugs.toggle "HBugs enabled"
2756 let settings_menu = factory0#add_submenu "Settings" in
2757 let factory3 = new GMenu.factory settings_menu ~accel_group in
2759 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
2760 ~callback:edit_aliases in
2761 let _ = factory3#add_separator () in
2763 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2764 ~callback:(function _ -> (settings_window ())#show ()) in
2766 let _ = window#add_accel_group accel_group in
2770 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2772 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2773 let scrolled_window0 =
2774 GBin.scrolled_window ~border_width:10
2775 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2776 let _ = scrolled_window0#add output#coerce in
2778 GBin.frame ~label:"Insert Term"
2779 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2780 let scrolled_window1 =
2781 GBin.scrolled_window ~border_width:5
2782 ~packing:frame#add () in
2784 TexTermEditor'.term_editor
2786 ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2787 ~isnotempty_callback:
2789 check_menu_item#misc#set_sensitive b ;
2790 searchPattern_menu_item#misc#set_sensitive b) in
2792 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2794 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2796 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2800 ~source:"<html><body bgColor=\"white\"></body></html>"
2801 ~width:400 ~height: 100
2806 method outputhtml = outputhtml
2807 method inputt = inputt
2808 method output = (output : TermViewer.proof_viewer)
2809 method scratch_window = scratch_window
2810 method notebook = notebook
2811 method show = window#show
2813 notebook#set_empty_page ;
2814 export_to_postscript_menu_item#misc#set_sensitive false ;
2815 check_term := (check_term_in_scratch scratch_window) ;
2817 (* signal handlers here *)
2818 ignore(output#connect#selection_changed
2820 choose_selection output elem ;
2821 !focus_and_proveit_set_sensitive true
2823 ignore (output#connect#click (show_in_show_window_callback output)) ;
2824 let settings_window = new settings_window output scrolled_window0
2825 export_to_postscript_menu_item (choose_selection output) in
2826 set_settings_window settings_window ;
2827 set_outputhtml outputhtml ;
2828 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
2829 Logger.log_callback :=
2830 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
2835 let initialize_everything () =
2836 let module U = Unix in
2837 let output = TermViewer.proof_viewer ~width:350 ~height:280 () in
2838 let notebook = new notebook in
2839 let rendering_window' = new rendering_window output notebook in
2840 set_rendering_window rendering_window' ;
2841 let print_error_as_html prefix msg =
2842 output_html (outputhtml ())
2843 ("<h1 color=\"red\">" ^ prefix ^ msg ^ "</h1>")
2845 Gdome_xslt.setErrorCallback (Some (print_error_as_html "XSLT Error: "));
2846 Gdome_xslt.setDebugCallback
2847 (Some (print_error_as_html "XSLT Debug Message: "));
2848 rendering_window'#show () ;
2849 (* Hbugs.toggle true; *)
2854 ignore (GtkMain.Main.init ()) ;
2855 initialize_everything () ;
2856 MQIC.close mqi_handle;
2861 Sys.catch_break true;
2863 with Sys.Break -> () (* exit nicely, invoking at_exit functions *)