]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/matita/matitaScript.ml
new command eval added
[helm.git] / helm / software / matita / matitaScript.ml
index cbaa08721cca870b1643e5005cbf7a62ae4a6825..65d7be828f0e0ebeb4199fd3f4dbb46e8d25180c 100644 (file)
@@ -378,33 +378,22 @@ let rec eval_macro include_paths (buffer : GText.buffer) guistuff lexicon_status
   (* no idea why ocaml wants this *)
   let parsed_text_length = String.length parsed_text in
   let dbd = LibraryDb.instance () in
-  let pp_macro = 
-    let f t = ProofEngineReduction.replace 
-      ~equality:(fun _ t -> match t with Cic.Meta _ -> true | _ -> false)
-      ~what:[()] ~with_what:[Cic.Implicit None] ~where:t
-    in
-    let metasenv = GrafiteTypes.get_proof_metasenv grafite_status in
-    TAPp.pp_macro 
-      ~term_pp:(fun x -> 
-        ApplyTransformation.txt_of_cic_term max_int metasenv [] (f x)
-         ~map_unicode_to_tex:(Helm_registry.get_bool
-           "matita.paste_unicode_as_tex"))
-  in
+  let pp_macro = ApplyTransformation.txt_of_macro ~map_unicode_to_tex:true in
   match mac with
   (* WHELP's stuff *)
   | TA.WMatch (loc, term) -> 
      let l =  Whelp.match_term ~dbd term in
-     let entry = `Whelp (pp_macro mac, l) in
+     let entry = `Whelp (pp_macro [] [] mac, l) in
      guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
      [], "", parsed_text_length
   | TA.WInstance (loc, term) ->
      let l = Whelp.instance ~dbd term in
-     let entry = `Whelp (pp_macro mac, l) in
+     let entry = `Whelp (pp_macro [] [] mac, l) in
      guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
      [], "", parsed_text_length
   | TA.WLocate (loc, s) -> 
      let l = Whelp.locate ~dbd s in
-     let entry = `Whelp (pp_macro mac, l) in
+     let entry = `Whelp (pp_macro [] [] mac, l) in
      guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
      [], "", parsed_text_length
   | TA.WElim (loc, term) ->
@@ -414,14 +403,14 @@ let rec eval_macro include_paths (buffer : GText.buffer) guistuff lexicon_status
        | _ -> failwith "Not a MutInd"
      in
      let l = Whelp.elim ~dbd uri in
-     let entry = `Whelp (pp_macro mac, l) in
+     let entry = `Whelp (pp_macro [] [] mac, l) in
      guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
      [], "", parsed_text_length
   | TA.WHint (loc, term) ->
      let _subst = [] in
      let s = ((None,[0,[],term], _subst, lazy (Cic.Meta (0,[])) ,term, []),0) in
      let l = List.map fst (MQ.experimental_hint ~dbd s) in
-     let entry = `Whelp (pp_macro mac, l) in
+     let entry = `Whelp (pp_macro [] [] mac, l) in
      guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
      [], "", parsed_text_length
   (* REAL macro *)
@@ -436,7 +425,8 @@ let rec eval_macro include_paths (buffer : GText.buffer) guistuff lexicon_status
       if rewrite then
         let l = MQ.equations_for_goal ~dbd proof_status in
         let l = List.filter (fun u -> not (LibraryObjects.in_eq_URIs u)) l in
-        let entry = `Whelp (pp_macro (TA.WHint(loc, Cic.Implicit None)), l) in
+        let entry = 
+          `Whelp (pp_macro [] [] (TA.WHint(loc, Cic.Implicit None)), l) in
         guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
         [], "", parsed_text_length
       else
@@ -472,6 +462,32 @@ let rec eval_macro include_paths (buffer : GText.buffer) guistuff lexicon_status
               fun u -> HLog.error (UriManager.string_of_uri u ^ "\n")
             ) selected;
             assert false)
+  | TA.Eval (_, kind, term) -> 
+      let metasenv = GrafiteTypes.get_proof_metasenv grafite_status in
+      let context =
+       match user_goal with
+          None -> []
+        | Some n -> GrafiteTypes.get_proof_context grafite_status n in
+      let ty,_ = CTC.type_of_aux' metasenv context term CicUniv.empty_ugraph in
+      let term = 
+        match kind with
+        | `Normalize ->
+             CicReduction.normalize ~delta:true ~subst:[] context term
+        | `Simpl -> 
+            ProofEngineReduction.simpl context term
+        | `Unfold None ->
+            ProofEngineReduction.unfold ?what:None context term
+        | `Unfold (Some lazy_term) ->
+             let what, _, _ = 
+               lazy_term context metasenv CicUniv.empty_ugraph in
+             ProofEngineReduction.unfold ~what context term
+        | `Whd ->
+            CicReduction.whd ~delta:true ~subst:[] context term
+      in
+      let t_and_ty = Cic.Cast (term,ty) in
+      guistuff.mathviewer#show_entry (`Cic (t_and_ty,metasenv));
+      [({grafite_status with proof_status = No_proof},lexicon_status), parsed_text ],"", 
+        parsed_text_length 
   | TA.Check (_,term) ->
       let metasenv = GrafiteTypes.get_proof_metasenv grafite_status in
       let context =