]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/matitaInterpreter.ml
removed useless parameter uri from mml_of_cic_object
[helm.git] / helm / matita / matitaInterpreter.ml
index f52901ea684f4a075e1766b1c6a7d32e0f9413b6..c9d5a71612d7e1893c11b033307b518d54759eec 100644 (file)
@@ -195,9 +195,16 @@ class sharedState
           Quiet
       | TacticAst.Command (TacticAst.Print `Env) ->
           let uris = CicEnvironment.list_uri () in
+          console#echo_message "Environment:";
           List.iter (fun u ->
-            console#echo_message (UriManager.string_of_uri u);
-            prerr_endline "x"
+            console#echo_message ("  " ^ (UriManager.string_of_uri u))
+          ) uris;
+          Quiet
+      | TacticAst.Command (TacticAst.Print `Coer) ->
+          let uris = CoercGraph.get_coercions_list () in
+          console#echo_message "Coercions:";
+          List.iter (fun (s,t,u) ->
+            console#echo_message ("  " ^ (UriManager.string_of_uri u))
           ) uris;
           Quiet
       | tactical ->
@@ -276,22 +283,15 @@ let inddef_of_ast params indTypes (disambiguator:MatitaTypes.disambiguator) =
   let cicIndTypes = List.rev cicIndTypes in
   (UriManager.uri_of_string uri, (cicIndTypes, [], paramsno))
 
- (* 
- *
- *
- * FIXME this should be in another module, shared with gTopLevel 
- *
- *
- * *)
-let
- save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
+let 
+ save_object_to_disk uri obj 
 =
- let name =
-  let struri = UriManager.string_of_uri uri in
-  let idx = (String.rindex struri '/') + 1 in
-   String.sub struri idx (String.length struri - idx)
- in
-  let path = pathname ^ "/" ^ name in
+  (* generate annobj, ids_to_inner_sorts and ids_to_inner_types *)
+  let annobj,_,_,ids_to_inner_sorts,ids_to_inner_types,_,_ =
+    Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
+  in 
+
+  (* prepare XML *)
   let xml, bodyxml =
    Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
     annobj 
@@ -300,38 +300,40 @@ let
    Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
     ~ask_dtd_to_the_getter:false
   in
-   (* innertypes *)
-   let innertypesuri = UriManager.innertypesuri_of_uri uri in
-    Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
-    Http_getter.register' innertypesuri
-     (Helm_registry.get "local_library.url" ^
-       Str.replace_first (Str.regexp "^cic:") ""
-        (UriManager.string_of_uri innertypesuri) ^ ".xml"
-     ) ;
-    (* constant type / variable / mutual inductive types definition *)
-    Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
-    Http_getter.register' uri
-     (Helm_registry.get "local_library.url" ^
-       Str.replace_first (Str.regexp "^cic:") ""
-        (UriManager.string_of_uri uri) ^ ".xml"
-     ) ;
-    match bodyxml with
-       None -> ()
-     | Some bodyxml' ->
-        (* constant body *)
-        let bodyuri =
-         match UriManager.bodyuri_of_uri uri with
-            None -> assert false
-          | Some bodyuri -> bodyuri
-        in
-         Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
-         Http_getter.register' bodyuri
-          (Helm_registry.get "local_library.url" ^
-            Str.replace_first (Str.regexp "^cic:") ""
-             (UriManager.string_of_uri bodyuri) ^ ".xml"
-          )
+  
+  (* prepare URIs and paths *)
+  let innertypesuri = UriManager.innertypesuri_of_uri uri in
+  let bodyuri = UriManager.bodyuri_of_uri uri in
+  let innertypesfilename = Str.replace_first (Str.regexp "^cic:") ""
+        (UriManager.string_of_uri innertypesuri) ^ ".xml" in
+  let innertypespath = !basedir ^ "/" ^ innertypesfilename in
+  let xmlfilename = Str.replace_first (Str.regexp "^cic:") ""
+        (UriManager.string_of_uri uri) ^ ".xml" in
+  let xmlpath = !basedir ^ "/" ^ xmlfilename in
+  let xmlbodyfilename = Str.replace_first (Str.regexp "^cic:") ""
+        (UriManager.string_of_uri uri) ^ ".body.xml" in
+  let xmlbodypath = !basedir ^ "/" ^  xmlbodyfilename in
+  let path_scheme_of path = "file:/" ^ path in
+
+   (* now write to disk *)
+    Xml.pp ~quiet:true xmlinnertypes (Some innertypespath) ;
+    Xml.pp ~quiet:true xml (Some xmlpath) ;
+
+   (* now register to the getter *)
+    Http_getter.register' innertypesuri (path_scheme_of innertypespath); 
+    Http_getter.register' uri (path_scheme_of xmlpath);
+   
+    (* now the optional body, both write and register *)
+    (match bodyxml,bodyuri with
+       None,None -> ()
+     | Some bodyxml,Some bodyuri->
+         Xml.pp ~quiet:true bodyxml (Some xmlbodypath) ;
+         Http_getter.register' bodyuri (path_scheme_of xmlbodypath)
+     | _-> assert false) 
 ;;
 
+
+
   (* TODO Zack a lot more to be done here:
     * - save object to disk in xml format
     * - register uri to the getter 
@@ -349,6 +351,7 @@ let add_constant_to_world ~(console:MatitaTypes.console)
     CicEnvironment.add_type_checked_term uri (obj, ugraph);
     MetadataDb.index_constant ~dbd
       ~owner:(Helm_registry.get "matita.owner") ~uri ~body ~ty;
+    save_object_to_disk uri obj;  
     console#echo_message (sprintf "%s constant defined" suri)
   end
 
@@ -365,6 +368,7 @@ let add_inductive_def_to_world ~(console:MatitaTypes.console)
     CicEnvironment.put_inductive_definition uri (obj, ugraph);
     MetadataDb.index_inductive_def ~dbd
       ~owner:(Helm_registry.get "matita.owner") ~uri ~types:indTypes;
+    save_object_to_disk uri obj;  
     console#echo_message (sprintf "%s inductive type defined" suri);
     let elim sort =
       try
@@ -448,8 +452,6 @@ class commandState
             (* do nothing, just for compatibility with coq syntax *)
           New_state Command
       | TacticAst.Command (TacticAst.Coercion c_ast) ->
-          prerr_endline ("beccata la coercion " ^ (CicAstPp.pp_term c_ast));
-
           let env, metasenv, coercion, ugraph = 
             disambiguator#disambiguateTermAst c_ast 
           in
@@ -492,14 +494,18 @@ class commandState
             in  
             aux ty
           in
-          let uri_of_term = function
+          let rec uri_of_term = function
             | Cic.Const(u,_) -> u
             | Cic.MutInd (u, i , _) ->
                 (* we have to build by hand the #xpointer *)
                 let base = UriManager.string_of_uri u in
                 let xp = "#xpointer(1/" ^ (string_of_int (i+1)) ^ ")" in
                   UriManager.uri_of_string (base ^ xp)
-            | _ -> assert false 
+            | Cic.Appl (he::_) -> uri_of_term he
+            | t -> 
+                prerr_endline ("Fallisco a estrarre la uri di " ^ 
+                  (CicPp.ppterm t));
+                assert false 
           in
           let ty_src,ty_tgt = extract_last_two_p coer_ty in
           let src_uri = uri_of_term ty_src in
@@ -510,12 +516,14 @@ class commandState
           (* FIXME: we should chek it this object can be a coercion 
            * maybe add the check to extract_last_two_p
            *)
+          console#echo_message (sprintf "Coercion %s"
+            (UriManager.string_of_uri coer_uri));
           List.iter (fun (uri,obj,ugraph) -> 
-            (*
-            prerr_endline (Printf.sprintf 
-             "Aggiungo la coercion %s\n%s\n\n"
-             (UriManager.string_of_uri uri) (CicPp.ppobj obj));
-            *)
+          (*  
+            console#echo_message 
+             (sprintf "Coercion (automatic) %s" 
+               (UriManager.string_of_uri uri));
+          *)
             let (name, body, ty, attrs) = split_obj obj in
             add_constant_to_world ~console 
               ~dbd ~uri ?body ~ty ~attrs ~ugraph ();