]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/gTopLevel/gTopLevel.ml
Fourier tactic update
[helm.git] / helm / gTopLevel / gTopLevel.ml
index 15cfdcd103813cbb0f5f71ba77c2794f19204785..2b476a6745c278a7fe07953c747507344f630956 100644 (file)
@@ -47,7 +47,9 @@ let htmlfooter =
  "</html>"
 ;;
 
-let prooffile = "/home/zack/dati/HELM/currentproof.gTopLevel"
+let prooffile = "/public/sacerdot/currentproof";;
+(*CSC: the getter should handle the innertypes, not the FS *)
+let innertypesfile = "/public/sacerdot/innertypes";;
 
 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
 
@@ -68,6 +70,7 @@ let argspec =
 in
 Arg.parse argspec ignore ""
 
+
 (* MISC FUNCTIONS *)
 
 let domImpl = Gdome.domImplementation ();;
@@ -153,39 +156,21 @@ let applyStylesheets input styles args =
 
 let mml_of_cic_object uri annobj ids_to_inner_sorts ids_to_inner_types =
  let xml =
-  Cic2Xml.print_object uri ids_to_inner_sorts annobj 
+  Cic2Xml.print_object uri ~ids_to_inner_sorts annobj 
  in
  let xmlinnertypes =
-  Cic2Xml.print_inner_types uri ids_to_inner_sorts
-   ids_to_inner_types
+  Cic2Xml.print_inner_types uri ~ids_to_inner_sorts
+   ~ids_to_inner_types
  in
   let input = Xml2Gdome.document_of_xml domImpl xml in
 (*CSC: We save the innertypes to disk so that we can retrieve them in the  *)
 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
 (*CSC: local.                                                              *)
-   Xml.pp xmlinnertypes (Some "/tmp/innertypes") ;
+   Xml.pp xmlinnertypes (Some innertypesfile) ;
    let output = applyStylesheets input mml_styles mml_args in
     output
 ;;
 
-  (* pretty print on standard output the current sequent *)
-let dumpsequent () =
-  let metasenv =
-    match !ProofEngine.proof with
-    | None -> assert false
-    | Some (_, metasenv, _, _) -> metasenv
-  in
-  let seq =
-    match !ProofEngine.goal with
-    | None -> assert false
-    | Some metano -> List.find (function (m,_,_) -> m=metano) metasenv
-  in
-  print_string (
-    "<current_seq>\n" ^
-    (SequentPp.TextualPp.print_sequent seq) ^
-    "\n</current_seq>");
-  print_newline ()
-;;
 
 (* CALLBACKS *)
 
@@ -263,7 +248,7 @@ prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent current
 
 (*
 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
- ~name:"/public/sacerdot/guruguru1" ~indent:true ()) ;
+ ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
 *)
 
 let mml_of_cic_term metano term =
@@ -356,10 +341,10 @@ let call_tactic_with_input tactic rendering_window () =
        None -> assert false
      | Some (curi,_,_,_) -> curi
    in
-   let metasenv =
+   let uri,metasenv,bo,ty =
     match !ProofEngine.proof with
        None -> assert false
-     | Some (_,metasenv,_,_) -> metasenv
+     | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
    in
    let context =
     List.map
@@ -378,10 +363,12 @@ let call_tactic_with_input tactic rendering_window () =
     try
      while true do
       match
-       CicTextualParserContext.main curi context CicTextualLexer.token lexbuf
+       CicTextualParserContext.main
+        curi context metasenv CicTextualLexer.token lexbuf
       with
          None -> ()
-       | Some expr ->
+       | Some (metasenv',expr) ->
+          ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
           tactic expr ;
           refresh_sequent proofw ;
           refresh_proof output
@@ -496,10 +483,10 @@ let call_tactic_with_input_and_goal_input tactic rendering_window () =
                     None -> assert false
                   | Some (curi,_,_,_) -> curi
                 in
-                let metasenv =
+                let uri,metasenv,bo,ty =
                  match !ProofEngine.proof with
                     None -> assert false
-                  | Some (_,metasenv,_,_) -> metasenv
+                  | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
                 in
                 let context =
                  List.map
@@ -519,11 +506,12 @@ let call_tactic_with_input_and_goal_input tactic rendering_window () =
                   try
                    while true do
                     match
-                     CicTextualParserContext.main curi context
+                     CicTextualParserContext.main curi context metasenv
                       CicTextualLexer.token lexbuf
                     with
                        None -> ()
-                     | Some expr ->
+                     | Some (metasenv',expr) ->
+                        ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
                         tactic ~goal_input:(Hashtbl.find ids_to_terms id)
                          ~input:expr ;
                         refresh_sequent proofw ;
@@ -694,6 +682,8 @@ let clear rendering_window =
  call_tactic_with_hypothesis_input ProofEngine.clear rendering_window
 ;;
 
+let fourier rendering_window = call_tactic ProofEngine.fourier rendering_window;;
+
 
 let whd_in_scratch scratch_window =
  call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
@@ -751,8 +741,7 @@ let qed rendering_window () =
 (*????
 let dtdname = "http://www.cs.unibo.it/helm/dtd/cic.dtd";;
 *)
-(* let dtdname = "/home/zack/dati/HELM/V7/dtd/cic.dtd";; *)
-let dtdname = "/public/helm-cvs/helm/dtd/cic.dtd";;
+let dtdname = "/projects/helm/V7/dtd/cic.dtd";;
 
 let save rendering_window () =
  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
@@ -765,7 +754,7 @@ let save rendering_window () =
        let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
         Cic2acic.acic_object_of_cic_object currentproof
        in
-        let xml = Cic2Xml.print_object uri ids_to_inner_sorts acurrentproof in
+        let xml = Cic2Xml.print_object uri ~ids_to_inner_sorts acurrentproof in
          let xml' =
           [< Xml.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
              Xml.xml_cdata
@@ -1074,13 +1063,13 @@ let check rendering_window scratch_window () =
      while true do
       (* Execute the actions *)
       match
-       CicTextualParserContext.main curi names_context CicTextualLexer.token
-        lexbuf
+       CicTextualParserContext.main curi names_context metasenv
+        CicTextualLexer.token lexbuf
       with
          None -> ()
-       | Some expr ->
+       | Some (metasenv',expr) ->
           try
-           let ty  = CicTypeChecker.type_of_aux' metasenv context expr in
+           let ty  = CicTypeChecker.type_of_aux' metasenv' context expr in
             let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
              scratch_window#show () ;
              scratch_window#mmlwidget#load_tree ~dom:mml
@@ -1107,7 +1096,7 @@ let locate rendering_window () =
            | [] -> ""
            | head :: tail ->
               inputt#delete_text 0 inputlen;
-              MQueryGenerator.locate head 
+              MQueryGenerator.locate_html head 
      with
         e -> "<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>"
   )
@@ -1134,6 +1123,7 @@ let backward rendering_window () =
               MQueryGenerator.backward metasenv ey ty level
        in 
    output_html outputhtml result
+;;
       
 let choose_selection
      (mmlwidget : GMathView.math_view) (element : Gdome.element option)
@@ -1426,22 +1416,22 @@ class rendering_window output proofw (label : GMisc.label) =
  let changeb =
   GButton.button ~label:"Change"
    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
+ let hbox4 =
+  GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
  let letinb =
   GButton.button ~label:"Let ... In"
-   ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
+   ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
  let ringb =
   GButton.button ~label:"Ring"
-   ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
- let hbox4 =
-  GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
+   ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
  let clearbodyb =
   GButton.button ~label:"ClearBody"
    ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
  let clearb =
   GButton.button ~label:"Clear"
    ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
- let dumpb =
-  GButton.button ~label:"Dump"
+ let fourierb =
+  GButton.button ~label:"Fourier"
    ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
  let outputhtml =
   GHtml.xmhtml
@@ -1496,7 +1486,7 @@ object(self)
   ignore(ringb#connect#clicked (ring self)) ;
   ignore(clearbodyb#connect#clicked (clearbody self)) ;
   ignore(clearb#connect#clicked (clear self)) ;
-  ignore(dumpb#connect#clicked dumpsequent);
+  ignore(fourierb#connect#clicked (fourier self)) ;
   ignore(introsb#connect#clicked (intros self)) ;
   Logger.log_callback :=
    (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
@@ -1518,10 +1508,54 @@ let initialize_everything () =
 
 let _ =
  CicCooking.init () ;
- if !usedb then MQueryGenerator.init () ;
+ if !usedb then
+  begin
+   MQueryGenerator.init () ;
+   CicTextualParser0.set_locate_object
+    (function id ->
+      let MathQL.MQRefs uris = MQueryGenerator.locate id in
+       let uri = 
+        match uris with
+           [] ->
+            (GToolbox.input_string ~title:"Unknown input"
+             ("No URI matching \"" ^ id ^ "\" found. Please enter its URI"))
+         | [uri] -> Some uri
+         | _ ->
+           let choice =
+            GToolbox.question_box ~title:"Ambiguous input."
+             ~buttons:uris ~default:1 "Ambiguous input. Please, choose one."
+           in
+            if choice > 0 then
+             Some (List.nth uris (choice - 1))
+            else
+             (* No choice from the user *)
+             None
+       in
+        match uri with
+           Some uri' ->
+            (* Constant *)
+            if String.sub uri' (String.length uri' - 4) 4 = ".con" then
+(*CSC: what cooking number? Here I always use 0, which may be bugged *)
+             Some (Cic.Const (UriManager.uri_of_string uri',0))
+            else
+             (try
+               (* Inductive Type *)
+               let uri'',typeno = CicTextualLexer.indtyuri_of_uri uri' in
+(*CSC: what cooking number? Here I always use 0, which may be bugged *)
+                Some (Cic.MutInd (uri'',0,typeno))
+              with
+               _ ->
+                (* Constructor of an Inductive Type *)
+                let uri'',typeno,consno =
+                 CicTextualLexer.indconuri_of_uri uri'
+                in
+(*CSC: what cooking number? Here I always use 0, which may be bugged *)
+                 Some (Cic.MutConstruct (uri'',0,typeno,consno))
+             )
+         | None -> None
+    )
+  end ;
  ignore (GtkMain.Main.init ()) ;
  initialize_everything () ;
  if !usedb then MQueryGenerator.close ();
- MQueryGenerator.close ()
 ;;
-