123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293openPpopenUtilopenNamesopenTableopenMinimlopenMlutilopenCommonletjson_strs=qssletjson_inti=intiletjson_boolb=ifbthenstr"true"elsestr"false"letjson_globaltypref=ifis_customrefthenjson_str(find_customref)elsejson_str(Common.pp_globaltypref)letjson_idid=json_str(Id.to_stringid)letjson_dict_one(k,v)=json_strk++str(": ")++vletjson_dict_openl=str("{")++fnl()++str(" ")++hov0(prlist_with_seppr_commajson_dict_onel)letjson_dictl=json_dict_openl++fnl()++str("}")letjson_listl=str("[")++fnl()++str(" ")++hov0(prlist_with_seppr_comma(funx->x)l)++fnl()++str("]")letjson_listarra=str("[")++fnl()++str(" ")++hov0(prvect_with_seppr_comma(funx->x)a)++fnl()++str("]")letpreamblemod_namecommentused_modulesusf=(matchcommentwith|None->mt()|Somes->str"/* "++hov0s++str" */"++fnl())++json_dict_open[("what",json_str"module");("name",json_idmod_name);("need_magic",json_bool(usf.magic));("need_dummy",json_bool(usf.mldummy));("used_modules",json_list(List.map(funmf->json_str(file_of_modfilemf))used_modules))](*s Pretty-printing of types. *)letrecjson_typevl=function|Tmeta_|Tvar'_->assertfalse|Tvari->(tryletvarid=List.nthvl(predi)injson_dict[("what",json_str"type:var");("name",json_idvarid)]withFailure_->json_dict[("what",json_str"type:varidx");("name",json_inti)])|Tglob(r,l)->json_dict[("what",json_str"type:glob");("name",json_globalTyper);("args",json_list(List.map(json_typevl)l))]|Tarr(t1,t2)->json_dict[("what",json_str"type:arrow");("left",json_typevlt1);("right",json_typevlt2)]|Tdummy_->json_dict[("what",json_str"type:dummy")]|Tunknown->json_dict[("what",json_str"type:unknown")]|Taxiom->json_dict[("what",json_str"type:axiom")](*s Pretty-printing of expressions. *)letrecjson_exprenv=function|MLreln->json_dict[("what",json_str"expr:rel");("name",json_id(get_db_namenenv))]|MLapp(f,args)->json_dict[("what",json_str"expr:apply");("func",json_exprenvf);("args",json_list(List.map(json_exprenv)args))]|MLlam_asa->letfl,a'=collect_lamsainletfl,env'=push_vars(List.mapid_of_mlidfl)envinjson_dict[("what",json_str"expr:lambda");("argnames",json_list(List.mapjson_id(List.revfl)));("body",json_exprenv'a')]|MLletin(id,a1,a2)->leti,env'=push_vars[id_of_mlidid]envinjson_dict[("what",json_str"expr:let");("name",json_id(List.hdi));("nameval",json_exprenva1);("body",json_exprenv'a2)]|MLglobr->json_dict[("what",json_str"expr:global");("name",json_globalTermr)]|MLcons(_,r,a)->json_dict[("what",json_str"expr:constructor");("name",json_globalConsr);("args",json_list(List.map(json_exprenv)a))]|MLtuplel->json_dict[("what",json_str"expr:tuple");("items",json_list(List.map(json_exprenv)l))]|MLcase(typ,t,pv)->json_dict[("what",json_str"expr:case");("expr",json_exprenvt);("cases",json_listarr(Array.map(funx->json_one_patenvx)pv))]|MLfix(i,ids,defs)->letids',env'=push_vars(List.rev(Array.to_listids))envinletids'=Array.of_list(List.revids')injson_dict[("what",json_str"expr:fix");("funcs",json_listarr(Array.map(fun(fi,ti)->json_dict[("what",json_str"fix:item");("name",json_idfi);("body",json_functionenv'ti)])(Array.map2(funab->a,b)ids'defs)));("for",json_inti);]|MLexns->json_dict[("what",json_str"expr:exception");("msg",json_strs)]|MLdummy_->json_dict[("what",json_str"expr:dummy")]|MLmagica->json_dict[("what",json_str"expr:coerce");("value",json_exprenva)]|MLaxiom_->json_dict[("what",json_str"expr:axiom")]|MLuinti->json_dict[("what",json_str"expr:int");("int",json_str(Uint63.to_stringi))]|MLfloatf->json_dict[("what",json_str"expr:float");("float",json_str(Float64.to_stringf))]|MLstrings->json_dict[("what",json_str"expr:string");("string",json_str(Pstring.to_strings))]|MLparray(t,def)->json_dict[("what",json_str"expr:array");("elems",json_listarr(Array.map(json_exprenv)t));("default",json_exprenvdef)]andjson_one_patenv(ids,p,t)=letids',env'=push_vars(List.rev_mapid_of_mlidids)envinjson_dict[("what",json_str"case");("pat",json_gen_pat(List.revids')env'p);("body",json_exprenv't)]andjson_gen_patidsenv=function|Pcons(r,l)->json_cons_patr(List.map(json_gen_patidsenv)l)|Pusualr->json_cons_patr(List.mapjson_idids)|Ptuplel->json_dict[("what",json_str"pat:tuple");("items",json_list(List.map(json_gen_patidsenv)l))]|Pwild->json_dict[("what",json_str"pat:wild")]|Preln->json_dict[("what",json_str"pat:rel");("name",json_id(get_db_namenenv))]andjson_cons_patrppl=json_dict[("what",json_str"pat:constructor");("name",json_globalConsr);("argnames",json_listppl)]andjson_functionenvt=letbl,t'=collect_lamstinletbl,env'=push_vars(List.mapid_of_mlidbl)envinjson_dict[("what",json_str"expr:lambda");("argnames",json_list(List.mapjson_id(List.revbl)));("body",json_exprenv't')](*s Pretty-printing of inductive types declaration. *)letjson_indipplcv=json_dict[("what",json_str"decl:ind");("name",json_globalType(GlobRef.IndRefip));("argnames",json_list(List.mapjson_idpl));("constructors",json_listarr(Array.mapi(funidxc->json_dict[("name",json_globalCons(GlobRef.ConstructRef(ip,idx+1)));("argtypes",json_list(List.map(json_typepl)c))])cv))](*s Pretty-printing of a declaration. *)letpp_decl=function|Dind(kn,defs)->prvecti_with_seppr_comma(funip->ifp.ip_logicalthenstr""elsejson_ind(kn,i)p.ip_varsp.ip_types)defs.ind_packets|Dtype(r,l,t)->json_dict[("what",json_str"decl:type");("name",json_globalTyper);("argnames",json_list(List.mapjson_idl));("value",json_typelt)]|Dfix(rv,defs,typs)->json_dict[("what",json_str"decl:fixgroup");("fixlist",json_listarr(Array.mapi(funir->json_dict[("what",json_str"fixgroup:item");("name",json_globalTermrv.(i));("type",json_type[]typs.(i));("value",json_function(empty_env())defs.(i))])rv))]|Dterm(r,a,t)->json_dict[("what",json_str"decl:term");("name",json_globalTermr);("type",json_type[]t);("value",json_function(empty_env())a)]letrecpp_structure_elem=function|(l,SEdecld)->[pp_decld]|(l,SEmodulem)->pp_module_exprm.ml_mod_expr|(l,SEmodtypem)->[](* for the moment we simply discard module type *)andpp_module_expr=function|MEstruct(mp,sel)->List.concat(List.mappp_structure_elemsel)|MEfunctor_->[](* for the moment we simply discard unapplied functors *)|MEident_|MEapply_->assertfalse(* should be expansed in extract_env *)letpp_structmls=letpp_sel(mp,sel)=push_visiblemp[];letp=prlist_with_seppr_commaidentity(List.concat(List.mappp_structure_elemsel))inpop_visible();pinstr","++fnl()++str" "++qs"declarations"++str": ["++fnl()++str" "++hov0(prlist_with_seppr_commapp_selmls)++fnl()++str" ]"++fnl()++str"}"++fnl()letjson_descr={keywords=Id.Set.empty;file_suffix=".json";file_naming=file_of_modfile;preamble=preamble;pp_struct=pp_struct;sig_suffix=None;sig_preamble=(fun____->mt());pp_sig=(fun_->mt());pp_decl=pp_decl;}