123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469(************************************************************************)(* * The Rocq Prover / The Rocq 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) *)(************************************************************************)openUtilopenTac2dynopenTac2valtype'arepr={r_of:'a->valexpr;r_to:valexpr->'a;}letrepr_ofrx=r.r_ofxletrepr_torx=r.r_toxletmake_reprr_ofr_to={r_of;r_to;}letmap_reprfgr={r_of=(funx->r.r_of(gx));r_to=(funx->f(r.r_tox));}typeind_data=(Names.Ind.t*Declarations.mutual_inductive_body)typebinder=(Names.Name.tEConstr.binder_annot*EConstr.types)(** Dynamic tags *)letval_exn=Val.create"exn"letval_exninfo=Val.create"exninfo"letval_constr=Val.create"constr"letval_ident=Val.create"ident"letval_pattern=Val.create"pattern"letval_preterm=Val.create"preterm"letval_matching_context=Val.create"matching_context"letval_pp=Val.create"pp"letval_evar=Val.create"evar"letval_sort=Val.create"sort"letval_cast=Val.create"cast"letval_inductive=Val.create"inductive"letval_constant=Val.create"constant"letval_constructor=Val.create"constructor"letval_projection=Val.create"projection"letval_qvar=Val.create"qvar"letval_case=Val.create"case"letval_binder=Val.create"binder"letval_instance=Val.create"instance"letval_free=Val.create"free"letval_uint63=Val.create"uint63"letval_float=Val.create"float"letval_pstring=Val.create"pstring"letval_ind_data:(Names.Ind.t*Declarations.mutual_inductive_body)Val.tag=Val.create"ind_data"letval_transparent_state:TransparentState.tVal.tag=Val.create"transparent_state"letval_pretype_flags=Val.create"pretype_flags"letval_expected_type=Val.create"expected_type"letval_reduction=Val.create"reduction"letval_rewstrategy=Val.create"rewstrategy"letextract_val(typea)(typeb)(tag:aVal.tag)(tag':bVal.tag)(v:b):a=matchVal.eqtagtag'with|None->assertfalse|SomeRefl->v(** Exception *)exceptionLtacErrorofNames.KerName.t*valexprarray(** Conversion functions *)letvalexpr={r_of=(funobj->obj);r_to=(funobj->obj);}letof_unit()=ValInt0letto_unit=function|ValInt0->()|_->assertfalseletunit={r_of=of_unit;r_to=to_unit;}letof_intn=ValIntnletto_int=function|ValIntn->n|_->assertfalseletint={r_of=of_int;r_to=to_int;}letof_boolb=ifbthenValInt0elseValInt1letto_bool=function|ValInt0->true|ValInt1->false|_->assertfalseletbool={r_of=of_bool;r_to=to_bool;}letof_charn=ValInt(Char.coden)letto_char=function|ValIntn->Char.chrn|_->assertfalseletchar={r_of=of_char;r_to=to_char;}letof_bytess=ValStrsletto_bytes=function|ValStrs->s|_->assertfalseletbytes={r_of=of_bytes;r_to=to_bytes;}letof_strings=of_bytes(Bytes.of_strings)letto_strings=Bytes.to_string(to_bytess)letstring={r_of=of_string;r_to=to_string;}letrecof_listf=function|[]->ValInt0|x::l->ValBlk(0,[|fx;of_listfl|])letrecto_listf=function|ValInt0->[]|ValBlk(0,[|v;vl|])->fv::to_listfvl|_->assertfalseletlistr={r_of=(funl->of_listr.r_ofl);r_to=(funl->to_listr.r_tol);}letof_closurecls=ValClsclsletto_closure=Tac2val.to_closureletclosure={r_of=of_closure;r_to=to_closure;}type('a,'b)fun1='a->'bProofview.tacticletof_fun1to_argof_resf=of_closure(mk_closurearity_one(funx->Proofview.Monad.mapof_res@@f(to_argx)))letto_fun1of_argto_resfx=Proofview.Monad.mapto_res@@apply(to_closuref)[of_argx]letfun1argres={r_of=of_fun1arg.r_tores.r_of;r_to=to_fun1arg.r_ofres.r_to;}letthunkr=fun1unitrtype('a,'b,'c)fun2='a->'b->'cProofview.tacticletof_fun2to_arg1to_arg2of_resf=of_closure(mk_closure(arity_sucarity_one)(funxy->Proofview.Monad.mapof_res@@f(to_arg1x)(to_arg2y)))letto_fun2of_arg1of_arg2to_resfxy=Proofview.Monad.mapto_res@@apply(to_closuref)[of_arg1x;of_arg2y]letfun2arg1arg2res={r_of=of_fun2arg1.r_toarg2.r_tores.r_of;r_to=to_fun2arg1.r_ofarg2.r_ofres.r_to;}letof_exttagc=ValExt(tag,c)letto_exttag=function|ValExt(tag',e)->extract_valtagtag'e|_->assertfalseletrepr_exttag={r_of=(fune->of_exttage);r_to=(fune->to_exttage);}letof_constrc=of_extval_constrcletto_constrc=to_extval_constrcletconstr=repr_extval_constrletof_matching_contextc=of_extval_matching_contextcletto_matching_contextc=to_extval_matching_contextcletmatching_context=repr_extval_matching_contextletof_pretermc=of_extval_pretermcletto_pretermc=to_extval_pretermcletpreterm=repr_extval_pretermletof_castc=of_extval_castcletto_castc=to_extval_castcletcast=repr_extval_castletof_identc=of_extval_identcletto_identc=to_extval_identcletident=repr_extval_identletof_patternc=of_extval_patterncletto_patternc=to_extval_patterncletpattern=repr_extval_patternletof_evarev=of_extval_evarevletto_evarev=to_extval_evarevletevar=repr_extval_evarletof_sortev=of_extval_sortevletto_sortev=to_extval_sortevletsort=repr_extval_sortletof_reductionev=of_extval_reductionevletto_reductionev=to_extval_reductionevletreduction=repr_extval_reductionletof_rewstrategyev=of_extval_rewstrategyevletto_rewstrategyev=to_extval_rewstrategyevletrewstrategy=repr_extval_rewstrategyletinternal_err=letopenNamesinletrocq_prefix=MPfile(DirPath.make(List.mapId.of_string["Init";"Ltac2"]))inKerName.makerocq_prefix(Label.of_id(Id.of_string"Internal"))letof_exninfo=of_extval_exninfoletto_exninfo=to_extval_exninfoletexninfo={r_of=of_exninfo;r_to=to_exninfo;}(* Invariant: no [LtacError] should be put into a value with tag [val_exn]. *)letof_erre=of_extval_exneletto_erre=to_extval_exneleterr=repr_extval_exn(** FIXME: handle backtrace in Ltac2 exceptions *)letof_exnc=matchfstcwith|LtacError(kn,c)->ValOpn(kn,c)|_->ValOpn(internal_err,[|of_errc|])letto_exnc=matchcwith|ValOpn(kn,c)->ifNames.KerName.equalkninternal_errthento_errc.(0)else(LtacError(kn,c),Exninfo.null)|_->assertfalseletexn={r_of=of_exn;r_to=to_exn;}letof_resultof_ok=function|Okv->ValBlk(0,[|of_okv|])|Errore->ValBlk(1,[|of_exne|])letto_resultto_ok=function|ValBlk(0,[|v|])->Ok(to_okv)|ValBlk(1,[|e|])->Error(to_exne)|_->assertfalseletresultok={r_of=of_resultok.r_of;r_to=to_resultok.r_to;}letof_optionf=function|None->ValInt0|Somec->ValBlk(0,[|fc|])letto_optionf=function|ValInt0->None|ValBlk(0,[|c|])->Some(fc)|_->assertfalseletoptionr={r_of=(funl->of_optionr.r_ofl);r_to=(funl->to_optionr.r_tol);}letof_ppc=of_extval_ppcletto_ppc=to_extval_ppcletpp=repr_extval_ppletof_tuplecl=ValBlk(0,cl)letto_tuple=function|ValBlk(0,cl)->cl|_->assertfalseletof_pairfg(x,y)=ValBlk(0,[|fx;gy|])letto_pairfg=function|ValBlk(0,[|x;y|])->(fx,gy)|_->assertfalseletpairr0r1={r_of=(funp->of_pairr0.r_ofr1.r_ofp);r_to=(funp->to_pairr0.r_tor1.r_top);}letof_triplefgh(x,y,z)=ValBlk(0,[|fx;gy;hz|])letto_triplefgh=function|ValBlk(0,[|x;y;z|])->(fx,gy,hz)|_->assertfalselettripler0r1r2={r_of=(funp->of_tripler0.r_ofr1.r_ofr2.r_ofp);r_to=(funp->to_tripler0.r_tor1.r_tor2.r_top);}letof_arrayfvl=ValBlk(0,Array.mapfvl)letto_arrayf=function|ValBlk(0,vl)->Array.mapfvl|_->assertfalseletarrayr={r_of=(funl->of_arrayr.r_ofl);r_to=(funl->to_arrayr.r_tol);}letof_block(n,args)=ValBlk(n,args)letto_block=function|ValBlk(n,args)->(n,args)|_->assertfalseletblock={r_of=of_block;r_to=to_block;}letof_open(kn,args)=ValOpn(kn,args)letto_open=function|ValOpn(kn,args)->(kn,args)|_->assertfalseletopen_={r_of=of_open;r_to=to_open;}letof_freen=of_extval_freenletto_freex=to_extval_freexletfree={r_of=of_free;r_to=to_free;}letof_uint63n=of_extval_uint63nletto_uint63x=to_extval_uint63xletuint63={r_of=of_uint63;r_to=to_uint63;}letof_floatf=of_extval_floatfletto_floatx=to_extval_floatxletfloat={r_of=of_float;r_to=to_float;}letof_pstrings=of_extval_pstringsletto_pstringx=to_extval_pstringxletpstring={r_of=of_pstring;r_to=to_pstring;}letof_transparent_statec=of_extval_transparent_statecletto_transparent_statec=to_extval_transparent_stateclettransparent_state=repr_extval_transparent_stateletof_pretype_flagsc=of_extval_pretype_flagscletto_pretype_flagsc=to_extval_pretype_flagscletpretype_flags=repr_extval_pretype_flagsletof_expected_typec=of_extval_expected_typecletto_expected_typec=to_extval_expected_typecletexpected_type=repr_extval_expected_typeletof_ind_datac=of_extval_ind_datacletto_ind_datac=to_extval_ind_datacletind_data=repr_extval_ind_dataletof_inductivec=of_extval_inductivecletto_inductivec=to_extval_inductivecletinductive=repr_extval_inductiveletof_constantc=of_extval_constantcletto_constantc=to_extval_constantcletconstant=repr_extval_constantletof_constructorc=of_extval_constructorcletto_constructorc=to_extval_constructorcletconstructor=repr_extval_constructorletof_projectionc=of_extval_projectioncletto_projectionc=to_extval_projectioncletprojection=repr_extval_projectionletof_qvarc=of_extval_qvarcletto_qvarc=to_extval_qvarcletqvar=repr_extval_qvarletof_casec=of_extval_casecletto_casec=to_extval_casecletcase=repr_extval_caseletof_binderc=of_extval_bindercletto_binderc=to_extval_bindercletbinder=repr_extval_binderletof_instancec=of_extval_instancecletto_instancec=to_extval_instancecletinstance=repr_extval_instanceletof_reference=letopenNames.GlobRefinfunction|VarRefid->ValBlk(0,[|of_identid|])|ConstRefcst->ValBlk(1,[|of_constantcst|])|IndRefind->ValBlk(2,[|of_inductiveind|])|ConstructRefcstr->ValBlk(3,[|of_constructorcstr|])letto_reference=letopenNames.GlobRefinfunction|ValBlk(0,[|id|])->VarRef(to_identid)|ValBlk(1,[|cst|])->ConstRef(to_constantcst)|ValBlk(2,[|ind|])->IndRef(to_inductiveind)|ValBlk(3,[|cstr|])->ConstructRef(to_constructorcstr)|_->assertfalseletreference={r_of=of_reference;r_to=to_reference;}