123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)openPpopenNamesmoduleDyn=Dyn.Make()type'asubstitutivity=Dispose|Substituteof'a|Keepof'a|Anticipateof'atypeobject_name=Libnames.full_path*Names.KerName.tmoduleNSet=Globnames.ExtRefSettypeopen_filter=|Unfiltered|NamesofNSet.tletsimple_openffilterio=matchfilterwith|Unfiltered->fio|Names_->()letfilter_andf1f2=matchf1,f2with|Unfiltered,f|f,Unfiltered->Somef|Namesn1,Namesn2->letn=NSet.intern1n2inifNSet.is_emptynthenNoneelseSome(Namesn)letfilter_orf1f2=matchf1,f2with|Unfiltered,f|f,Unfiltered->Unfiltered|Namesn1,Namesn2->Names(NSet.unionn1n2)letin_filter_refgr=function|Unfiltered->true|Namesns->NSet.mem(Globnames.TrueGlobalgr)nstype'aobject_declaration={object_name:string;cache_function:object_name*'a->unit;load_function:int->object_name*'a->unit;open_function:open_filter->int->object_name*'a->unit;classify_function:'a->'asubstitutivity;subst_function:Mod_subst.substitution*'a->'a;discharge_function:object_name*'a->'aoption;rebuild_function:'a->'a}letdefault_objects={object_name=s;cache_function=(fun_->());load_function=(fun__->());open_function=(fun___->());subst_function=(fun_->CErrors.anomaly(str"The object "++strs++str" does not know how to substitute!"));classify_function=(funatomic_obj->Keepatomic_obj);discharge_function=(fun_->None);rebuild_function=(funx->x)}(* The suggested object declaration is the following:
declare_object { (default_object "MY OBJECT") with
cache_function = fun (sp,a) -> Mytbl.add sp a}
and the listed functions are only those which definitions actually
differ from the default.
This helps introducing new functions in objects.
*)letident_subst_function(_,a)=atypeobj=Dyn.t(* persistent dynamic objects *)(** {6 Substitutive objects}
- The list of bound identifiers is nonempty only if the objects
are owned by a functor
- Then comes either the object segment itself (for interactive
modules), or a compact way to store derived objects (path to
a earlier module + substitution).
*)typealgebraic_objects=|Objsofobjects|RefofNames.ModPath.t*Mod_subst.substitutionandt=|ModuleObjectofsubstitutive_objects|ModuleTypeObjectofsubstitutive_objects|IncludeObjectofalgebraic_objects|KeepObjectofobjects|ExportObjectof{mpl:(open_filter*ModPath.t)list}|AtomicObjectofobjandobjects=(Names.Id.t*t)listandsubstitutive_objects=MBId.tlist*algebraic_objectsmoduleDynMap=Dyn.Map(structtype'at='aobject_declarationend)letcache_tab=refDynMap.emptyletdeclare_object_fullodecl=letna=odecl.object_nameinlettag=Dyn.createnainlet()=cache_tab:=DynMap.addtagodecl!cache_tabintagletdeclare_objectodecl=lettag=declare_object_fullodeclinletinfunv=Dyn.Dyn(tag,v)ininfunletcache_object(sp,Dyn.Dyn(tag,v))=letdecl=DynMap.findtag!cache_tabindecl.cache_function(sp,v)letload_objecti(sp,Dyn.Dyn(tag,v))=letdecl=DynMap.findtag!cache_tabindecl.load_functioni(sp,v)letopen_objectfi(sp,Dyn.Dyn(tag,v))=letdecl=DynMap.findtag!cache_tabindecl.open_functionfi(sp,v)letsubst_object(subs,Dyn.Dyn(tag,v))=letdecl=DynMap.findtag!cache_tabinDyn.Dyn(tag,decl.subst_function(subs,v))letclassify_object(Dyn.Dyn(tag,v))=letdecl=DynMap.findtag!cache_tabinmatchdecl.classify_functionvwith|Dispose->Dispose|Substitutev->Substitute(Dyn.Dyn(tag,v))|Keepv->Keep(Dyn.Dyn(tag,v))|Anticipatev->Anticipate(Dyn.Dyn(tag,v))letdischarge_object(sp,Dyn.Dyn(tag,v))=letdecl=DynMap.findtag!cache_tabinmatchdecl.discharge_function(sp,v)with|None->None|Somev->Some(Dyn.Dyn(tag,v))letrebuild_object(Dyn.Dyn(tag,v))=letdecl=DynMap.findtag!cache_tabinDyn.Dyn(tag,decl.rebuild_functionv)letdump=Dyn.dumpletlocal_object_nodischarges~cache={(default_objects)withcache_function=cache;classify_function=(fun_->Dispose);}letlocal_objects~cache~discharge={(local_object_nodischarges~cache)withdischarge_function=discharge}letglobal_object_nodischarges~cache~subst=letimportio=ifInt.equali1thencacheoin{(default_objects)withcache_function=cache;open_function=simple_openimport;subst_function=(matchsubstwith|None->fun_->CErrors.anomaly(str"The object "++strs++str" does not know how to substitute!")|Somesubst->subst;);classify_function=ifOption.has_somesubstthen(funo->Substituteo)else(funo->Keepo);}letglobal_objects~cache~subst~discharge={(global_object_nodischarges~cache~subst)withdischarge_function=discharge}letsuperglobal_object_nodischarges~cache~subst={(default_objects)withload_function=(fun_x->cachex);cache_function=cache;subst_function=(matchsubstwith|None->fun_->CErrors.anomaly(str"The object "++strs++str" does not know how to substitute!")|Somesubst->subst;);classify_function=ifOption.has_somesubstthen(funo->Substituteo)else(funo->Keepo);}letsuperglobal_objects~cache~subst~discharge={(superglobal_object_nodischarges~cache~subst)withdischarge_function=discharge}