123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * INRIA, CNRS and contributors - Copyright 1999-2018 *)(* <O___,, * (see CREDITS file for the list of authors) *)(* \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) *)(************************************************************************)(************************************************************************)(* Coq serialization API/Plugin *)(* Copyright 2016-2019 MINES ParisTech *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)(* Status: Very Experimental *)(************************************************************************)openSexplibopenSexplib.StdmoduleCEphemeron=Ser_cEphemeronmoduleDeclarations=Ser_declarationsmoduleEntries=Ser_entriesmoduleCooking=Ser_cooking(* Side_effects *)typeside_effect={from_env:Declarations.structure_bodyCEphemeron.key;eff:Entries.side_efflist;}[@@derivingsexp]moduleSeffOrd=structtypet=side_effectletcomparee1e2=letopenNamesinletopenEntriesinletcmpe1e2=Constant.CanOrd.comparee1.seff_constante2.seff_constantinUtil.List.comparecmpe1.effe2.efflett_of_sexp=side_effect_of_sexpletsexp_of_t=sexp_of_side_effectendmoduleSeffSet=Set.Make(SeffOrd)moduleSerSeffSet=Ser_cSet.Make(SeffSet)(SeffOrd)type_t={seff:side_effectlist;elts:SerSeffSet.t}[@@derivingsexp]type_private_constants=_t[@@derivingsexp]typeprivate_constants=Safe_typing.private_constantsletsexp_of_private_constantsx=sexp_of__private_constants(Obj.magicx)letprivate_constants_of_sexpx=Obj.magic(_private_constants_of_sexpx)type'aeffect_entry=[%import:'aSafe_typing.effect_entry][@@derivingsexp_of](* XXX: Typical GADT Problem *)let_effect_entry_of_sexp(_f:Sexp.t->'a)(x:Sexp.t):'aeffect_entry=letopenSexpinmatchxwith|Atom"PureEntry"->Obj.magicPureEntry|Atom"EffectEntry"->Obj.magicEffectEntry|_->Sexplib.Conv_error.no_variant_match()typeglobal_declaration=[%import:Safe_typing.global_declaration](* [@@deriving sexp_of] *)letsexp_of_global_declaration(x:global_declaration):Sexp.t=letopenSexpinmatchxwith|ConstantEntry(d,ce)->(matchdwith|PureEntry->letsce=Entries.sexp_of_constant_entry(fun_->List[])ceinList[Atom"ConstantEntry";Atom"PureEntry";sce]|EffectEntry->letsce=Entries.sexp_of_constant_entrysexp_of_private_constantsceinList[Atom"ConstantEntry";Atom"EffectEntry";sce])|GlobalReciperecipe->List[Atom"GlobalRecipe";Cooking.sexp_of_reciperecipe](* XXX: Typical existential type problem *)letglobal_declaration_of_sexp(x:Sexp.t)=letopenSexpinmatchxwith|List[Atom"ConstantEntry";ef;ce]->(* This not sound, we should match on ef and pass the right
serializer for the private constants *)beginmatchefwith|Atom"PureEntry"->ConstantEntry(PureEntry,Entries.constant_entry_of_sexp(fun_->())ce)|Atom"EffectEntry"->ConstantEntry(EffectEntry,Entries.constant_entry_of_sexpprivate_constants_of_sexpce)|_->Sexplib.Conv_error.no_variant_match()end|List[Atom"GlobalRecipe";cr]->GlobalRecipe(Cooking.recipe_of_sexpcr)|exp->Format.eprintf"no for: %a@\n%!"Sexp.pp_humexp;Sexplib.Conv_error.no_variant_match()