assert (metasenv=[]);
let t = NCicUntrusted.apply_subst subst [] t in
let status = basic_eval_unification_hint (t,n) status in
- let dump = inject_unification_hint (t,n)::status#dump in
- let status = status#set_dump dump in
- status
+ NCicLibrary.dump_obj status (inject_unification_hint (t,n))
;;
let basic_index_obj l status =
let eval_interpretation status data=
let status = basic_eval_interpretation ~alias_only:false data status in
- let dump = inject_interpretation data::status#dump in
- status#set_dump dump
+ NCicLibrary.dump_obj status (inject_interpretation data)
;;
let basic_eval_alias (mode,diff) status =
let eval_alias status data=
let status = basic_eval_alias data status in
- let dump = inject_alias data::status#dump in
- status#set_dump dump
+ NCicLibrary.dump_obj status (inject_alias data)
;;
let basic_eval_input_notation (l1,l2) status =
let eval_input_notation status data=
let status = basic_eval_input_notation data status in
- let dump = inject_input_notation data::status#dump in
- status#set_dump dump
+ NCicLibrary.dump_obj status (inject_input_notation data)
;;
let basic_eval_output_notation (l1,l2) status =
let eval_output_notation status data=
let status = basic_eval_output_notation data status in
- let dump = inject_output_notation data::status#dump in
- status#set_dump dump
+ NCicLibrary.dump_obj status (inject_output_notation data)
;;
let record_index_obj =
(*prerr_endline (string_of_int height);*)
let data = compute_keys status uri height kind in
let status = basic_index_obj data status in
- let dump = record_index_obj data :: status#dump in
- status#set_dump dump
+ NCicLibrary.dump_obj status (record_index_obj data)
;;
let index_eq uri status =
if newstatus#eq_cache == status#eq_cache then status
else
((*prerr_endline ("recording " ^ (NUri.string_of_uri uri));*)
- let dump = record_index_eq uri :: newstatus#dump
- in newstatus#set_dump dump)
+ NCicLibrary.dump_obj newstatus (record_index_eq uri))
else
((*prerr_endline "Not a fact";*)
status)
let eval_add_constraint status u1 u2 =
let status = basic_eval_add_constraint (u1,u2) status in
- let dump = inject_constraint (u1,u2)::status#dump in
- let status = status#set_dump dump in
- status
+ NCicLibrary.dump_obj status (inject_constraint (u1,u2))
;;
let eval_ng_tac tac =
let baseuri = NUri.uri_of_string baseuri in
(* MATITA 1.0: keep WithoutPreferences? *)
let alias_only = (mode = GrafiteAst.OnlyPreferences) in
- let status,obj =
- GrafiteTypes.Serializer.require ~alias_only ~baseuri status in
- let status = status#set_dump (obj::status#dump) in
- let status = status#set_dependencies (fname::status#dependencies) in
- status
+ GrafiteTypes.Serializer.require ~alias_only ~baseuri ~fname status
| GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
| GrafiteAst.NCoercion (loc, name, t, ty, source, target) ->
let status, composites =
inherit TermContentPres.status
val baseuri = b
val ng_mode = (`CommandMode : [`CommandMode | `ProofMode])
- val dependencies = ([] : string list)
method baseuri = baseuri
method set_baseuri v = {< baseuri = v >}
method ng_mode = ng_mode;
method set_ng_mode v = {< ng_mode = v >}
- method dependencies = dependencies
- method set_dependencies v = {< dependencies = v >}
end
module Serializer =
- NCicLibrary.Serializer(struct type dumpable_status = status end)
+ NCicLibrary.Serializer(struct
+ type dumpable_s = status
+ let get status = (status : #status :> NCicLibrary.dumpable_status)
+ let set (status : dumpable_s) dump_status = status#set_dumpable_status dump_status
+ end)
inherit NCicLibrary.status
inherit GrafiteParser.status
inherit TermContentPres.status
- method dependencies: string list
- method set_dependencies: string list -> 'self
method baseuri: string
method set_baseuri: string -> 'self
method ng_mode: [`ProofMode | `CommandMode]
let basic_eval_and_record_ncoercion infos status =
let uris, cinfos, status = basic_eval_ncoercion infos status in
- let dump = record_ncoercion (infos::cinfos) :: status#dump in
- status#set_dump dump, uris
+ NCicLibrary.dump_obj status (record_ncoercion (infos::cinfos)), uris
;;
let basic_eval_and_record_ncoercion_from_t_cpos_arity
;;
let clean_baseuris ?(verbose=true) buris =
+ (* MATITA 1.0 *) () (*
let cache_of_processed_baseuri = Hashtbl.create 1024 in
let buris = List.map Http_getter_misc.strip_trailing_slash buris in
debug_prerr "clean_baseuris called on:";
with Http_getter_types.Key_not_found _ -> ())
(HExtlib.list_uniq (List.fast_sort Pervasives.compare
(List.map NUri.baseuri_of_uri l @ buris)))
+*)
type timestamp =
[ `Obj of NUri.uri * NCic.obj
| `Constr of NCic.universe * NCic.universe] list *
- (NUri.uri * string * NReference.reference) list *
- NCic.obj NUri.UriMap.t *
- NUri.uri list
+ (NUri.uri * string * NReference.reference) list
;;
-let time0 = [],[],NUri.UriMap.empty,[];;
+let time0 = [],[];;
let storage = ref [];;
let local_aliases = ref [];;
-let cache = ref NUri.UriMap.empty;;
-let includes = ref [];;
-
-let get_already_included () = !includes;;
let load_db,set_global_aliases,get_global_aliases,add_deps,get_deps,remove_deps=
let global_aliases = ref [] in
end
let time_travel status =
- let sto,ali,cac,inc = status#timestamp in
+ let sto,ali = status#timestamp in
let diff_len = List.length !storage - List.length sto in
let to_be_deleted,_ = HExtlib.split_nth diff_len !storage in
if List.length to_be_deleted > 0 then
NCicEnvironment.invalidate_item (HExtlib.list_last to_be_deleted);
- storage := sto; local_aliases := ali; cache := cac; includes := inc
+ storage := sto; local_aliases := ali
;;
-let serialize ~baseuri ~dependencies dump =
- let ch = open_out (ng_path_of_baseuri baseuri) in
- Marshal.to_channel ch (magic,(dependencies,dump)) [];
- close_out ch;
- List.iter
- (function
- | `Obj (uri,obj) ->
- let ch = open_out (ng_path_of_baseuri uri) in
- Marshal.to_channel ch (magic,obj) [];
- close_out ch
- | `Constr _ -> ()
- ) !storage;
- set_global_aliases (!local_aliases @ get_global_aliases ());
- List.iter (fun u -> add_deps u [baseuri]) !includes;
- time_travel (new status)
-;;
-
type obj = string * Obj.t
+(* CSC: includes & dependencies to be unified! *)
+type dump =
+ { objs: obj list ; includes: NUri.uri list; dependencies: string list }
+
+class type g_dumpable_status =
+ object
+ method dump: dump
+ end
class dumpable_status =
object
- val dump = ([] : obj list)
- method dump = dump
- method set_dump v = {< dump = v >}
+ val db = { objs = []; includes = []; dependencies = [] }
+ method dump = db
+ method set_dump v = {< db = v >}
+ method set_dumpable_status
+ : 'status. #g_dumpable_status as 'status -> 'self
+ = fun o -> {< db = o#dump >}
end
+let get_already_included status =
+ status#dump.includes
+;;
+
+let dump_obj status obj =
+ status#set_dump {status#dump with objs = obj::status#dump.objs }
+;;
+
module type SerializerType =
sig
type dumpable_status
dumpable_status -> dumpable_status
val register: < run: 'a. string -> 'a register_type -> ('a -> obj) >
- val serialize: baseuri:NUri.uri -> dependencies:string list -> obj list -> unit
- (* the obj is the "include" command to be added to the dump list *)
- val require: baseuri:
- NUri.uri -> alias_only:bool -> dumpable_status -> dumpable_status * obj
+ val serialize: baseuri:NUri.uri -> dumpable_status -> unit
+ val require:
+ baseuri:NUri.uri -> fname:string -> alias_only:bool ->
+ dumpable_status -> dumpable_status
val dependencies_of: baseuri:NUri.uri -> string list
end
-module Serializer(D: sig type dumpable_status end) =
+module Serializer(D: sig type dumpable_s val get: dumpable_s -> dumpable_status val set: dumpable_s -> dumpable_status -> dumpable_s end) =
struct
- type dumpable_status = D.dumpable_status
+ type dumpable_status = D.dumpable_s
type 'a register_type =
'a ->
refresh_uri_in_universe:(NCic.universe -> NCic.universe) ->
(fun x -> tag,Obj.repr x)
end
- let serialize = serialize
-
- let require2 ~baseuri ~alias_only status =
+ let serialize ~baseuri status =
+ let status = D.get status in
+ let ch = open_out (ng_path_of_baseuri baseuri) in
+ Marshal.to_channel ch (magic,(status#dump.dependencies,status#dump.objs)) [];
+ close_out ch;
+ List.iter
+ (function
+ | `Obj (uri,obj) ->
+ let ch = open_out (ng_path_of_baseuri uri) in
+ Marshal.to_channel ch (magic,obj) [];
+ close_out ch
+ | `Constr _ -> ()
+ ) !storage;
+ set_global_aliases (!local_aliases @ get_global_aliases ());
+ List.iter (fun u -> add_deps u [baseuri]) status#dump.includes;
+ time_travel (new status)
+
+ let require2 ~baseuri ~fname ~alias_only status =
try
- includes := baseuri::!includes;
+ let s = D.get status in
+ let status =
+ D.set status
+ (s#set_dump
+ {s#dump with
+ includes = baseuri::s#dump.includes;
+ dependencies = fname::s#dump.dependencies}) in
let _dependencies,dump = require0 ~baseuri in
List.fold_right (!require1 ~alias_only) dump status
with
let dependencies_of ~baseuri = fst (require0 ~baseuri)
let record_include =
- let aux baseuri ~refresh_uri_in_universe:_ ~refresh_uri_in_term:_
- ~refresh_uri_in_reference:_ ~alias_only =
+ let aux (baseuri,fname) ~refresh_uri_in_universe:_ ~refresh_uri_in_term:_
+ ~refresh_uri_in_reference:_ ~alias_only status =
let alias_only =
- alias_only || List.mem baseuri (get_already_included ())
+ alias_only || List.mem baseuri (get_already_included (D.get status))
in
- require2 ~baseuri ~alias_only
+ require2 ~baseuri ~fname ~alias_only status
in
register#run "include" aux
- let require ~baseuri ~alias_only status =
+ let require ~baseuri ~fname ~alias_only status =
let alias_only =
- alias_only || List.mem baseuri (get_already_included ()) in
- let status = require2 ~baseuri ~alias_only status in
- status,record_include baseuri
+ alias_only || List.mem baseuri (get_already_included (D.get status)) in
+ let status = require2 ~baseuri ~fname ~alias_only status in
+ let s = D.get status in
+ D.set status
+ (s#set_dump
+ {s#dump with
+ objs = record_include (baseuri,fname)::s#dump.objs })
end
-
-let decompile ~baseuri =
- let baseuris = get_deps baseuri in
- List.iter (fun baseuri ->
- remove_deps baseuri;
- HExtlib.safe_remove (ng_path_of_baseuri baseuri);
- let basepath = ng_path_of_baseuri ~no_suffix:true baseuri in
- try
- let od = Unix.opendir basepath in
- let rec aux names =
- try
- let name = Unix.readdir od in
- if name <> "." && name <> ".." then aux (name::names) else aux names
- with
- End_of_file -> names in
- let names = List.map (fun name -> basepath ^ "/" ^ name) (aux []) in
- Unix.closedir od;
- List.iter Unix.unlink names;
- HExtlib.rmdir_descend basepath;
- set_global_aliases
- (List.filter
- (fun (_,_,NReference.Ref (nuri,_)) ->
- Filename.dirname (NUri.string_of_uri nuri) <> NUri.string_of_uri baseuri
- ) (get_global_aliases ()))
- with
- Unix.Unix_error _ -> () (* raised by Unix.opendir, we hope :-) *)
- ) baseuris
-;;
-
-LibraryClean.set_decompile_cb
- (fun ~baseuri -> decompile ~baseuri:(NUri.uri_of_string baseuri));;
-
let fetch_obj uri =
let obj = require0 ~baseuri:uri in
refresh_uri_in_obj obj
) il)
in
local_aliases := references @ !local_aliases;
- status#set_timestamp (!storage,!local_aliases,!cache,!includes)
+ status#set_timestamp (!storage,!local_aliases)
;;
let add_constraint status u1 u2 =
NCicEnvironment.add_lt_constraint u1 u2;
storage := (`Constr (u1,u2)) :: !storage;
- status#set_timestamp (!storage,!local_aliases,!cache,!includes)
+ status#set_timestamp (!storage,!local_aliases)
;;
let get_obj u =
with Not_found ->
try fetch_obj u
with Sys_error _ ->
- try NUri.UriMap.find u !cache
- with Not_found ->
- raise (NCicEnvironment.ObjectNotFound
- (lazy (NUri.string_of_uri u)))
+ raise (NCicEnvironment.ObjectNotFound (lazy (NUri.string_of_uri u)))
;;
-let clear_cache () = cache := NUri.UriMap.empty;;
-
NCicEnvironment.set_get_obj get_obj;;
NCicPp.set_get_obj get_obj;;
(* warning: get_obj may raise (NCicEnvironment.ObjectNotFoud l) *)
val get_obj: NUri.uri -> NCic.obj (* changes the current timestamp *)
-val clear_cache : unit -> unit
-
val time_travel: #status -> unit
-val decompile: baseuri:NUri.uri -> unit
val init: unit -> unit
type obj
+type dump
+
+class type g_dumpable_status =
+ object
+ method dump: dump
+ end
+
+class dumpable_status :
+ object ('self)
+ inherit g_dumpable_status
+ method set_dump: dump -> 'self
+ method set_dumpable_status: #g_dumpable_status -> 'self
+ end
+
+val get_already_included: #dumpable_status -> NUri.uri list
+val dump_obj: #dumpable_status as 'status -> obj -> 'status
module type SerializerType =
sig
dumpable_status -> dumpable_status
val register: < run: 'a. string -> 'a register_type -> ('a -> obj) >
- val serialize: baseuri:NUri.uri -> dependencies:string list -> obj list ->
- unit
- (* the obj is the "include" command to be added to the dump list *)
+ val serialize: baseuri:NUri.uri -> dumpable_status -> unit
val require: baseuri:
- NUri.uri -> alias_only:bool -> dumpable_status -> dumpable_status * obj
+ NUri.uri -> fname:string -> alias_only:bool ->
+ dumpable_status -> dumpable_status
val dependencies_of: baseuri:NUri.uri -> string list
end
-module Serializer(D: sig type dumpable_status end) :
- SerializerType with type dumpable_status = D.dumpable_status
-
-class dumpable_status :
- object ('self)
- method dump: obj list
- method set_dump: obj list -> 'self
- end
+module Serializer(D: sig type dumpable_s val get: dumpable_s -> dumpable_status val set: dumpable_s -> dumpable_status -> dumpable_s end) :
+ SerializerType with type dumpable_status = D.dumpable_s
val refresh_uri: NUri.uri -> NUri.uri
val ng_path_of_baseuri: ?no_suffix:bool -> NUri.uri -> string
-
-(* IMPERATIVE STUFF, TO BE PUT IN THE STATUS *)
-val get_already_included: unit -> NUri.uri list
-
(* EOF *)
-grafitetypes(baseuri,ng_mode,dependencies)
- |--> dumpable(dump)
+grafitetypes(baseuri,ng_mode)
+ |--> dumpable(dump=objs+dependencies+includes)
|--> nciclibrary(timestamp)
|--> grafiteparser(db=ast_statement grammarentry)
| |--> cicnotationparser(db=grammars+keywords+items)
raise (FailureCompiling (baseuri,exn))
;;
+
let pp_times fname rc big_bang big_bang_u big_bang_s =
if not (Helm_registry.get_bool "matita.verbose") then
let { Unix.tms_utime = u ; Unix.tms_stime = s} = Unix.times () in
(GrafiteAst.Executable
(_,GrafiteAst.NCommand (_,GrafiteAst.Include (_,_,mafilename)))) as cmd
->
- ignore (assert_ng ~compiling ~include_paths mafilename);
+ let already_included = NCicLibrary.get_already_included status in
+ ignore(assert_ng ~already_included ~compiling ~include_paths mafilename);
cmd
| cmd -> cmd
let elapsed = Unix.time () -. time in
(if Helm_registry.get_bool "matita.moo" then begin
GrafiteTypes.Serializer.serialize ~baseuri:(NUri.uri_of_string baseuri)
- ~dependencies:grafite_status#dependencies grafite_status#dump
+ grafite_status
end;
let tm = Unix.gmtime elapsed in
let sec = string_of_int tm.Unix.tm_sec ^ "''" in
pp_times fname false big_bang big_bang_u big_bang_s;
clean_exit baseuri exn
-and assert_ng ~compiling ~include_paths mapath =
+and assert_ng ~already_included ~compiling ~include_paths mapath =
let _,baseuri,fullmapath,_ = Librarian.baseuri_of_script ~include_paths mapath in
let baseuri = NUri.uri_of_string baseuri in
let ngtime_of baseuri =
let children_bad =
List.exists
(fun mapath ->
- assert_ng ~compiling ~include_paths mapath
+ assert_ng ~already_included ~compiling ~include_paths mapath
|| let _,baseuri,_,_ =
Librarian.baseuri_of_script ~include_paths mapath in
let baseuri = NUri.uri_of_string baseuri in
in
if not to_be_compiled then false
else
- (* MATITA 1.0: SHOULD TAKE THIS FROM THE STATUS *)
- if List.mem baseuri (NCicLibrary.get_already_included ()) then
+ if List.mem baseuri already_included then
(* maybe recompiling it I would get the same... *)
raise (AlreadyLoaded (lazy mapath))
else
(compile ~compiling ~include_paths fullmapath; true)
;;
-let assert_ng = assert_ng ~compiling:[]
+let assert_ng = assert_ng ~already_included:[] ~compiling:[]
let get_ast = get_ast ~compiling:[]
exception CircularDependency of string
val get_ast:
- GrafiteTypes.status -> include_paths:string list -> GrafiteParser.parsable ->
- GrafiteAst.statement
+ GrafiteTypes.status -> include_paths:string list -> GrafiteParser.parsable ->
+ GrafiteAst.statement
(* heavy checks slow down the compilation process but give you some interesting
* infos like if the theorem is a duplicate *)
(GrafiteTypes.status *
(DisambiguateTypes.domain_item * GrafiteAst.alias_spec) option) list
-val assert_ng : include_paths:string list -> string -> bool
+val assert_ng: include_paths:string list -> string -> bool
| true, _ -> ()
| _, true ->
GrafiteTypes.Serializer.serialize ~baseuri:(NUri.uri_of_string baseuri)
- ~dependencies:grafite_status#dependencies grafite_status#dump
+ grafite_status
| _ -> clean_current_baseuri grafite_status
;;