]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_kernel/nCicLibrary.ml
EXPERIMENTAL COMMIT (part B, by CSC :-):
[helm.git] / helm / software / components / ng_kernel / nCicLibrary.ml
index 8c988de2f52b8f4d144051b8a2e7975aa96d5ec9..cff822316e45c311e4fdbd05e8430f84e3d62128 100644 (file)
@@ -26,6 +26,52 @@ let cache = ref NUri.UriMap.empty;;
 
 let time_travel (sto,ali,cac) = storage := sto; aliases := ali; cache := cac;;
 
+let magic = 0;;
+
+let path_of_baseuri baseuri =
+ let uri = NUri.string_of_uri baseuri in
+ let path = String.sub uri 4 (String.length uri - 4) in
+ let path = Helm_registry.get "matita.basedir" ^ path in
+ let dirname = Filename.dirname path in
+  HExtlib.mkdir dirname;
+  path ^ ".ng"
+;;
+
+let serialize ~baseuri dump =
+ let ch = open_out (path_of_baseuri baseuri) in
+ Marshal.to_channel ch (magic,dump) [Marshal.Closures];
+ close_out ch;
+ List.iter
+  (fun (uri,obj) ->
+    let ch = open_out (path_of_baseuri uri) in
+    Marshal.to_channel ch (magic,obj) [];
+    close_out ch
+  ) !storage;
+ time_travel time0;
+;;
+
+let require ~baseuri =
+ let ch = open_in (path_of_baseuri baseuri) in
+ let mmagic,dump = Marshal.from_channel ch in
+  close_in ch;
+  if mmagic <> magic then
+   raise (LibraryOutOfSync (lazy "The library is out of sync with the implementation. Please recompile the library."))
+  else
+   dump
+;;
+
+let decompile ~baseuri =
+ Unix.unlink (path_of_baseuri baseuri)
+ (* WE ARE NOT REMOVING ALL THE OBJECTS YET! *)
+;;
+
+(* the miracles of Marshal... *)
+let fetch_obj uri =
+ let obj = require ~baseuri:uri in
+  (* here we need to refresh the URIs! *)
+  obj
+;;
+
 let resolve name =
  try
   HExtlib.filter_map
@@ -79,9 +125,10 @@ let add_obj u obj =
 let get_obj u =
  try List.assq u !storage
  with Not_found ->
-  try NUri.UriMap.find u !cache
-  with Not_found ->
-    (* in the final implementation should get it from disk *)
+  try fetch_obj u
+  with Sys_error _ ->
+   try NUri.UriMap.find u !cache
+   with Not_found ->
     let ouri = NCic2OCic.ouri_of_nuri u in
     try
       let o,_ = CicEnvironment.get_obj CicUniv.oblivion_ugraph ouri in
@@ -95,33 +142,3 @@ let get_obj u =
 
 let clear_cache () = cache := NUri.UriMap.empty;;
 
-let magic = 0;;
-
-let path_of_baseuri baseuri =
- let uri = NUri.string_of_uri baseuri in
- let path = String.sub uri 4 (String.length uri - 4) in
- let path = Helm_registry.get "matita.basedir" ^ path in
- let dirname = Filename.dirname path in
-  HExtlib.mkdir dirname;
-  path ^ ".ng"
-;;
-
-let serialize ~baseuri dump =
- let ch = open_out (path_of_baseuri baseuri) in
- Marshal.to_channel ch (magic,dump) [Marshal.Closures];
- close_out ch
-;;
-
-let require ~baseuri =
- let ch = open_in (path_of_baseuri baseuri) in
- let mmagic,dump = Marshal.from_channel ch in
-  close_in ch;
-  if mmagic <> magic then
-   raise (LibraryOutOfSync (lazy "The library is out of sync with the implementation. Please recompile the library."))
-  else
-   dump
-;;
-
-let decompile ~baseuri =
- Unix.unlink (path_of_baseuri baseuri)
-;;