123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210(************************************************************************)(* v * The Coq Proof Assistant / The Coq Development Team *)(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2016 *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(************************************************************************)(************************************************************************)(* Coq serialization API/Plugin *)(* Copyright 2016-2019 MINES ParisTech *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)(* Status: Very Experimental *)(************************************************************************)(* Example of serialization to a sexp:
Coq's main datatype, constr, is a private type so we need to define
a serializable clone. Unfortunately, its main view is "zippy" so we
need to recurse throu the constr to build the clone.
*)openSexplibopenSexplib.StdmoduleNames=Ser_namesmoduleSorts=Ser_sortsmoduleEvar=Ser_evarmoduleUniv=Ser_univmoduleContext=Ser_contextmoduleUint63=Ser_uint63typepconstant=[%import:Constr.pconstant][@@derivingsexp,yojson]typepinductive=[%import:Constr.pinductive][@@derivingsexp,yojson]typepconstructor=[%import:Constr.pconstructor][@@derivingsexp,yojson]typecast_kind=[%import:Constr.cast_kind][@@derivingsexp,yojson]typecase_style=[%import:Constr.case_style][@@derivingsexp,yojson]typecase_printing=[%import:Constr.case_printing][@@derivingsexp,yojson]typecase_info=[%import:Constr.case_info][@@derivingsexp,yojson]type'constrpexistential=[%import:'constrConstr.pexistential][@@derivingsexp,yojson]type('constr,'types)prec_declaration=[%import:('constr,'types)Constr.prec_declaration][@@derivingsexp,yojson]type('constr,'types)pfixpoint=[%import:('constr,'types)Constr.pfixpoint][@@derivingsexp,yojson]type('constr,'types)pcofixpoint=[%import:('constr,'types)Constr.pcofixpoint][@@derivingsexp,yojson]typeconstr=Constr.constrtypetypes=Constr.constrtype_constr=|Relofint|VarofNames.Id.t|Metaofint|Evarof_constrpexistential|SortofSorts.t|Castof_constr*cast_kind*_types|ProdofNames.Name.tContext.binder_annot*_types*_types|LambdaofNames.Name.tContext.binder_annot*_types*_constr|LetInofNames.Name.tContext.binder_annot*_constr*_types*_constr|Appof_constr*_constrarray|Constofpconstant|Indofpinductive|Constructofpconstructor|Caseofcase_info*_constr*_constr*_constrarray|Fixof(_constr,_types)pfixpoint|CoFixof(_constr,_types)pcofixpoint|ProjofNames.Projection.t*_constr|IntofUint63.t[@@derivingsexp,yojson]and_types=_constr[@@derivingsexp,yojson]letrec_constr_put(c:constr):_constr=letcr=_constr_putinletcra=Array.map_constr_putinletmoduleC=ConstrinmatchC.kindcwith|C.Reli->Rel(i)|C.Varv->Var(v)|C.Meta(mv)->Metamv|C.Evar(ek,csa)->Evar(ek,cracsa)|C.Sort(st)->Sort(st)|C.Cast(cs,k,ty)->Cast(crcs,k,crty)|C.Prod(n,tya,tyr)->Prod(n,crtya,crtyr)|C.Lambda(n,ab,bd)->Lambda(n,crab,crbd)|C.LetIn(n,u,ab,bd)->LetIn(n,cru,crab,crbd)|C.App(hd,al)->App(crhd,craal)|C.Constp->Constp|C.Ind(p,q)->Ind(p,q)|C.Construct(p)->Construct(p)|C.Case(ci,d,c,ca)->Case(ci,crd,crc,craca)(* (int array * int) * (Name.t array * 'types array * 'constr array)) *)|C.Fix(p,(na,u1,u2))->Fix(p,(na,crau1,crau2))|C.CoFix(p,(na,u1,u2))->CoFix(p,(na,crau1,crau2))|C.Proj(p,c)->Proj(p,crc)|C.Inti->Intiletrec_constr_get(c:_constr):constr=letcr=_constr_getinletcra=Array.map_constr_getinletmoduleC=Constrinmatchcwith|Reli->C.mkReli|Varv->C.mkVarv|Meta(mv)->C.mkMetamv|Evar(ek,csa)->C.mkEvar(ek,cracsa)|Sort(st)->C.mkSort(st)|Cast(cs,k,ty)->C.mkCast(crcs,k,crty)|Prod(n,tya,tyr)->C.mkProd(n,crtya,crtyr)|Lambda(n,ab,bd)->C.mkLambda(n,crab,crbd)|LetIn(n,u,ab,bd)->C.mkLetIn(n,cru,crab,crbd)|App(hd,al)->C.mkApp(crhd,craal)|Constp->C.mkConstU(p)|Ind(p,q)->C.mkIndU(p,q)|Construct(p)->C.mkConstructU(p)|Case(ci,d,c,ca)->C.mkCase(ci,crd,crc,craca)|Fix(p,(na,u1,u2))->C.mkFix(p,(na,crau1,crau2))|CoFix(p,(na,u1,u2))->C.mkCoFix(p,(na,crau1,crau2))|Proj(p,c)->C.mkProj(p,crc)|Inti->C.mkIntiletconstr_of_sexp(c:Sexp.t):constr=_constr_get(_constr_of_sexpc)letsexp_of_constr(c:constr):Sexp.t=sexp_of__constr(_constr_putc)letconstr_of_yojsonjson=Ppx_deriving_yojson_runtime.(_constr_of_yojsonjson>|=_constr_get)letconstr_to_yojsonlevel=_constr_to_yojson(_constr_putlevel)lettypes_of_sexp=constr_of_sexpletsexp_of_types=sexp_of_constrlettypes_of_yojson=constr_of_yojsonlettypes_to_yojson=constr_to_yojsontypet=constrlett_of_sexp=constr_of_sexpletsexp_of_t=sexp_of_constrletof_yojson=constr_of_yojsonletto_yojson=constr_to_yojsontyperec_declaration=[%import:Constr.rec_declaration][@@derivingsexp]typefixpoint=[%import:Constr.fixpoint][@@derivingsexp]typecofixpoint=[%import:Constr.cofixpoint][@@derivingsexp]typeexistential=[%import:Constr.existential][@@derivingsexp]typesorts_family=Sorts.familyletsorts_family_of_sexp=Sorts.family_of_sexpletsexp_of_sorts_family=Sorts.sexp_of_familytypenamed_declaration=[%import:Constr.named_declaration][@@derivingsexp]typenamed_context=[%import:Constr.named_context][@@derivingsexp]typerel_declaration=[%import:Constr.rel_declaration][@@derivingsexp]typerel_context=[%import:Constr.rel_context][@@derivingsexp]