]> matita.cs.unibo.it Git - helm.git/blobdiff - matitaB/components/grafite_engine/grafiteEngine.ml
Matitaweb:
[helm.git] / matitaB / components / grafite_engine / grafiteEngine.ml
index ff9d00b819e74ae57830a8bc4f234d004636ad93..2021114853c7368a86fc5512715d69b814837812 100644 (file)
@@ -44,7 +44,7 @@ let inject_unification_hint =
    ~alias_only status
  =
   if not alias_only then
-   let t = refresh_uri_in_term (status :> NCic.status) t in
+   let t = refresh_uri_in_term (status :> NCicEnvironment.status) t in
     basic_eval_unification_hint (t,n) status
   else
    status
@@ -54,7 +54,7 @@ let inject_unification_hint =
 ;;
 
 let eval_unification_hint status t n = 
- let newast,metasenv,subst,status,t =
+ let metasenv,subst,status,t =
   GrafiteDisambiguate.disambiguate_nterm status None [] [] [] ("",0,t) in
  assert (metasenv=[]);
  let t = NCicUntrusted.apply_subst status subst [] t in
@@ -79,13 +79,12 @@ let basic_eval_interpretation ~alias_only (dsc, (symbol, args), cic_appl_pattern
   else
    status
  in
- let mode = GrafiteAst.WithPreferences (*assert false*) in (* MATITA 1.0 VEDI SOTTO *)
  let diff =
   (* FIXME! the uri should be filled with something meaningful! *)
-  [DisambiguateTypes.Symbol (symbol, Some (None,dsc)),
+  [DisambiguateTypes.Symbol symbol,
    GrafiteAst.Symbol_alias (symbol,None,dsc)]
  in
-  GrafiteDisambiguate.set_proof_aliases status ~implicit_aliases:false mode diff
+  GrafiteDisambiguate.add_to_disambiguation_univ status diff
 ;;
 
 let inject_interpretation =
@@ -116,7 +115,7 @@ let eval_interpretation status data=
 
 let basic_eval_alias (mode,diff) status =
   prerr_endline "basic_eval_alias";
-  GrafiteDisambiguate.set_proof_aliases status ~implicit_aliases:false mode diff
+  GrafiteDisambiguate.add_to_disambiguation_univ status diff
 ;;
 
 let inject_alias =
@@ -135,8 +134,14 @@ let eval_alias status data=
 let basic_eval_input_notation (l1,l2) status =
   GrafiteParser.extend status l1 
    (fun env loc ->
-     NotationPt.AttributedTerm
-      (`Loc loc,TermContentPres.instantiate_level2 status env l2)) 
+     let rec get_disamb = function
+     | [] -> Stdpp.dummy_loc,None,None
+     | (_,(NotationEnv.NoType,NotationEnv.DisambiguationValue dv))::_ -> dv
+     | _::tl -> get_disamb tl
+     in
+     let l2' = TermContentPres.instantiate_level2 status env (get_disamb env) l2 in
+     prerr_endline ("new l2 ast : " ^ (NotationPp.pp_term status l2'));
+     NotationPt.AttributedTerm (`Loc loc,l2')) 
 ;;
 
 let inject_input_notation =
@@ -147,10 +152,10 @@ let inject_input_notation =
    if not alias_only then
     let l1 =
      CicNotationParser.refresh_uri_in_checked_l1_pattern
-      ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCic.status))
+      ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCicEnvironment.status))
       ~refresh_uri_in_reference l1 in
     let l2 = NotationUtil.refresh_uri_in_term
-      ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCic.status))
+      ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCicEnvironment.status))
       ~refresh_uri_in_reference l2
     in
      basic_eval_input_notation (l1,l2) status
@@ -178,10 +183,10 @@ let inject_output_notation =
   if not alias_only then
    let l1 =
     CicNotationParser.refresh_uri_in_checked_l1_pattern
-     ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCic.status))
+     ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCicEnvironment.status))
       ~refresh_uri_in_reference l1 in
    let l2 = NotationUtil.refresh_uri_in_term
-     ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCic.status))
+     ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCicEnvironment.status))
       ~refresh_uri_in_reference l2
    in
     basic_eval_output_notation (l1,l2) status
@@ -201,7 +206,7 @@ let record_index_obj =
  let aux l ~refresh_uri_in_universe 
    ~refresh_uri_in_term ~refresh_uri_in_reference ~alias_only status
  =
-  let refresh_uri_in_term = refresh_uri_in_term (status:>NCic.status) in
+  let refresh_uri_in_term = refresh_uri_in_term (status:>NCicEnvironment.status) in
   if not alias_only then
     basic_index_obj
       (List.map 
@@ -317,7 +322,7 @@ let inject_constraint =
     (* NCicLibrary.add_constraint adds the constraint to the NCicEnvironment
      * and also to the storage (for undo/redo). During inclusion of compiled
      * files the storage must not be touched. *)
-    NCicEnvironment.add_lt_constraint u1 u2;
+    NCicEnvironment.add_lt_constraint status u1 u2;
     status
   else
    status
@@ -349,7 +354,7 @@ let eval_ng_tac tac =
        ) seqs)
   | GrafiteAst.NAuto (_loc, (None,a)) -> 
       NnAuto.auto_tac ~params:(None,a) ?trace_ref:None
-  | GrafiteAst.NAuto (_loc, (Some l,a)) ->
+  | GrafiteAst.NAuto (_loc, (Some (_,l),a)) ->
       NnAuto.auto_tac
        ~params:(Some List.map (fun x -> "",0,x) l,a) ?trace_ref:None
   | GrafiteAst.NBranch _ -> NTactics.branch_tac ~force:false
@@ -488,13 +493,38 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
       GrafiteTypes.Serializer.require
        ~alias_only ~baseuri ~fname:fullpath status
   | GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
-  | GrafiteAst.NCoercion (loc, name, t, ty, source, target) ->
+  | GrafiteAst.NCoercion (loc, name, None) ->
+     let status, t, ty, source, target =
+       let o_t = NotationPt.Ident (name,`Ambiguous) in
+       let metasenv,subst, status,t =
+         GrafiteDisambiguate.disambiguate_nterm 
+           status None [] [] [] ("",0,o_t) in
+       assert( metasenv = [] && subst = []);
+       let ty = NCicTypeChecker.typeof status [] [] [] t in
+       let source, target =
+         let clean = function
+         | NCic.Appl (NCic.Const _ as r :: l) -> 
+             NotationPt.Appl (NotationPt.NCic r ::
+               List.map (fun _ -> NotationPt.Implicit `JustOne)l)
+         | NCic.Const _ as r -> NotationPt.NCic r
+         | _ -> assert false in
+         let rec aux = function
+         | NCic.Prod (_,_, (NCic.Prod _ as rest)) -> aux rest
+         | NCic.Prod (name, src, tgt) -> (name, clean src), clean tgt
+         | _ -> assert false in aux ty in
+       status, o_t, NotationPt.NCic ty, source, target in
      let status, composites =
       NCicCoercDeclaration.eval_ncoercion status name t ty source target in
      let mode = GrafiteAst.WithPreferences in (* MATITA 1.0: fixme *)
      let aliases = GrafiteDisambiguate.aliases_for_objs status composites in
       eval_alias status (mode,aliases)
-  | GrafiteAst.NQed loc ->
+  | GrafiteAst.NCoercion (loc, name, Some (t, ty, source, target)) ->
+     let status, composites =
+      NCicCoercDeclaration.eval_ncoercion status name t ty source target in
+     let mode = GrafiteAst.WithPreferences in (* MATITA 1.0: fixme *)
+     let aliases = GrafiteDisambiguate.aliases_for_objs status composites in
+      eval_alias status (mode,aliases)
+  | GrafiteAst.NQed (loc,index) ->
      if status#ng_mode <> `ProofMode then
       raise (GrafiteTypes.Command_error "Not in proof mode")
      else
@@ -529,7 +559,7 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
         let obj = uri,height,[],[],obj_kind in
         let old_status = status in
         let status = NCicLibrary.add_obj status obj in
-        let index_obj =
+        let index_obj = index &&
          match obj_kind with
             NCic.Constant (_,_,_,_,(_,`Example,_))
           | NCic.Fixpoint (_,_,(_,`Example,_)) -> false
@@ -574,7 +604,7 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
                 else
                   nstatus
                with
-               | MultiPassDisambiguator.DisambiguationError _
+               | GrafiteDisambiguate.Error _
                | NCicTypeChecker.TypeCheckerFailure _ ->
                   (*HLog.warn "error in generating projection/eliminator";*)
                   status
@@ -595,14 +625,15 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
                        let _,_,menv,_,_ = invobj in
                         (match menv with
                              [] -> eval_ncommand ~include_paths opts status
-                                    ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
+                                    ("",0,GrafiteAst.NQed (Stdpp.dummy_loc,false))
                            | _ -> status))
                        (* XXX *)
                       with _ -> (*HLog.warn "error in generating inversion principle"; *)
                                 let status = status#set_ng_mode `CommandMode in status)
                   status
                   (NCic.Prop::
-                    List.map (fun s -> NCic.Type s) (NCicEnvironment.get_universes ()))
+                    List.map (fun s -> NCic.Type s)
+                    (NCicEnvironment.get_universes status))
               | _ -> status
            in
            let coercions =
@@ -618,7 +649,7 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
             List.fold_left
              (fun status (name,cpos,arity) ->
                try
-                 let newast,metasenv,subst,status,t =
+                 let metasenv,subst,status,t =
                   GrafiteDisambiguate.disambiguate_nterm status None [] [] []
                    ("",0,NotationPt.Ident (name,`Ambiguous)) in
                  assert (metasenv = [] && subst = []);
@@ -628,7 +659,7 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
                       status (name,t,cpos,arity) in
                  let aliases = GrafiteDisambiguate.aliases_for_objs status nuris in
                   eval_alias status (mode,aliases)
-               with MultiPassDisambiguator.DisambiguationError _-> 
+               with GrafiteDisambiguate.Error _ -> 
                  HLog.warn ("error in generating coercion: "^name);
                  status) 
              status coercions
@@ -668,7 +699,7 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
        let status = status#set_stack ninitial_stack in
        let status = subst_metasenv_and_fix_names status in
        let status = status#set_ng_mode `ProofMode in
-       eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
+       eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed (Stdpp.dummy_loc,false))
   | GrafiteAst.NObj (loc,obj) ->
      if status#ng_mode <> `CommandMode then
       raise (GrafiteTypes.Command_error "Not in command mode")
@@ -684,7 +715,7 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
       let status = status#set_ng_mode `ProofMode in
       (match nmenv with
           [] ->
-           eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
+           eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed (Stdpp.dummy_loc,true))
         | _ -> status)
   | GrafiteAst.NDiscriminator (_,_) -> assert false (*(loc, indty) ->
       if status#ng_mode <> `CommandMode then
@@ -711,7 +742,7 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
       let metasenv,subst,status,sort = match sort with
         | None -> [],[],status,NCic.Sort NCic.Prop
         | Some s ->
-            let newast,metasenv,subst,status,sort = 
+            let metasenv,subst,status,sort = 
               GrafiteDisambiguate.disambiguate_nterm status None [] [] []
               (text,prefix_len,s) 
             in metasenv,subst,status,sort
@@ -726,7 +757,7 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
             "ninverter: found target %s, which is not a sort"
              (status#ppterm ~metasenv ~subst ~context:[] sort))) in
       let status = status#set_ng_mode `ProofMode in
-      let newast,metasenv,subst,status,indty =
+      let metasenv,subst,status,indty =
        GrafiteDisambiguate.disambiguate_nterm status None [] [] subst
         (text,prefix_len,indty) in
       let indtyno,(_,leftno,tys,_,_) =
@@ -745,7 +776,7 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
        (match menv with
           [] ->
             eval_ncommand ~include_paths opts status
-             ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
+             ("",0,GrafiteAst.NQed (Stdpp.dummy_loc,false))
         | _ -> assert false)
   | GrafiteAst.NUnivConstraint (loc,u1,u2) ->
       eval_add_constraint status [`Type,u1] [`Type,u2]
@@ -757,6 +788,7 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
      in
       eval_interpretation status (dsc,(symbol, args),cic_appl_pattern)
   | GrafiteAst.Notation (loc, dir, l1, associativity, precedence, l2) ->
+      prerr_endline ("new notation: " ^ (NotationPp.pp_term status l1));
       let l1 = 
         CicNotationParser.check_l1_pattern
          l1 (dir = Some `RightToLeft) precedence associativity
@@ -765,19 +797,22 @@ let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
         if dir <> Some `RightToLeft then eval_input_notation status (l1,l2)
         else status
       in
+      let status =
        if dir <> Some `LeftToRight then eval_output_notation status (l1,l2)
        else status
+      in prerr_endline ("new grammar:\n" ^ (Print_grammar.ebnf_of_term status));
+      status
   | GrafiteAst.Alias (loc, spec) -> 
      let diff =
       (*CSC: Warning: this code should be factorized with the corresponding
              code in DisambiguatePp *)
       match spec with
       | GrafiteAst.Ident_alias (id,uri) -> 
-         [DisambiguateTypes.Id (id,Some uri),spec]
+         [DisambiguateTypes.Id id,spec]
       | GrafiteAst.Symbol_alias (symb, uri, desc) ->
-         [DisambiguateTypes.Symbol (symb, Some (uri,desc)),spec]
+         [DisambiguateTypes.Symbol symb,spec]
       | GrafiteAst.Number_alias (uri,desc) ->
-         [DisambiguateTypes.Num (Some (uri,desc)),spec]
+         [DisambiguateTypes.Num,spec]
      in
       let mode = GrafiteAst.WithPreferences in(*assert false in (* VEDI SOPRA *) MATITA 1.0*)
        eval_alias status (mode,diff)
@@ -795,6 +830,7 @@ let rec eval_executable ~include_paths opts status (text,prefix_len,ex) =
         List.fold_left 
           (fun status tac ->
             let status = eval_ng_tac (text,prefix_len,tac) status in
+            prerr_endline "prima di subst_metasenv_and_fix_names";
             subst_metasenv_and_fix_names status)
           status tacl
        in