1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072(* Utility Module for S-expression Conversions *)openStdLabelsopenMoreLabelsopenBasementopenOr_null_shim.ExportopenPrintfopenSexp(* A miniature subset of the [Capsule] api with [Sync_blocking]; defined locally to avoid
dependency issues. *)moduleWith_mutex:sig@@portabletype'at:valuemodcontendedportablevalcreate:(unit->'a)@portable->'atvalwith_lock:'at->f:('a->'b@portable)@portable->'b@contendedend=structmoduleMutex=Basement.Blocking_sync.Mutex[@@alert"-deprecated"]type'at:valuemodcontendedportable=Tof('a*Mutex.t)[@@unboxed][@@unsafe_allow_any_mode_crossing]letcreatef=T(f(),Mutex.create())type'abox={box:'a@@aliasedmany}[@@unboxed]letwith_lock(T(a,mutex))~f=(Mutex.with_lockmutex~f:(fun()->{box=fa})).box;;end(* Conversion of OCaml-values to S-expressions *)externalglobalize_float:local_float->float@@portable="%obj_dup"externalbytes_length:local_bytes->int@@portable="%bytes_length"openBasement.Primitivesexternalcreate_local_bytes:int->local_bytes@@portable="caml_create_local_bytes"externalunsafe_blit_bytes:src:local_bytes->src_pos:int->dst:local_bytes->dst_pos:int->len:int->unit@@portable="caml_blit_bytes"[@@noalloc]externalunsafe_bytes_to_string:local_bytes->local_string@@portable="%bytes_to_string"letbytes_to_string_localb=exclave_letlen=bytes_lengthbinlets=create_local_bytesleninunsafe_blit_bytes~src:b~src_pos:0~dst:s~dst_pos:0~len;unsafe_bytes_to_strings;;externalunsafe_fill_bytes:local_bytes->pos:int->len:int->char->unit@@portable="caml_fill_bytes"[@@noalloc]letstring_make_localnc=exclave_lets=create_local_bytesninunsafe_fill_bytess~pos:0~len:nc;unsafe_bytes_to_strings;;externalformat_float:string->local_float->string@@portable="caml_format_float"externalformat_int32:string->local_int32->string@@portable="caml_int32_format"externalformat_int64:string->local_int64->string@@portable="caml_int64_format"externalformat_nativeint:string->local_nativeint->string@@portable="caml_nativeint_format"externallazy_force:('alazy_t[@local_opt])->('a[@local_opt])@@portable="%lazy_force"letstring_of_int32n=format_int32"%d"nletstring_of_int64n=format_int64"%d"nletstring_of_nativeintn=format_nativeint"%d"n(* '%.17g' is guaranteed to be round-trippable.
'%.15g' will be round-trippable and not have noise at the last digit or two for a float
which was converted from a decimal (string) with <= 15 significant digits. So it's
worth trying first to avoid things like "3.1400000000000001".
See comment above [to_string_round_trippable] in {!Core.Float} for detailed explanation
and examples. *)letdefault_string_of_float=Dynamic.make(funx->lety=format_float"%.15G"xiniffloat_of_stringy=xthenyelseformat_float"%.17G"x);;letread_old_option_format=Dynamic.maketrueletwrite_old_option_format=Dynamic.maketrueletlist_mapfl=List.mapl~fletlist_map__stackflst=exclave_letrecrevlstacc=exclave_matchlstwith|[]->acc|hd::tl->revtl(hd::acc)inletrecrev_maplstacc=exclave_matchlstwith|[]->acc|hd::tl->rev_maptl(fhd::acc)inrev(rev_maplst[])[];;let[@zero_alloc]sexp_of_unit_u#()=List[]letsexp_of_unit_u__stack=sexp_of_unit_uletsexp_of_unit()=(sexp_of_unit_u[@inlined])#()letsexp_of_unit__stack()=exclave_(sexp_of_unit_u__stack[@inlined])#()let[@zero_alloc]sexp_of_bool_u=function|#false->Atom"false"|#true->Atom"true";;letsexp_of_bool_u__stack=sexp_of_bool_uletsexp_of_boolb=(sexp_of_bool_u[@inlined])(unbox_boolb)letsexp_of_bool__stackb=exclave_(sexp_of_bool_u__stack[@inlined])(unbox_boolb)letsexp_of_stringstr=Atomstrletsexp_of_string__stackstr=exclave_Atomstrletsexp_of_bytesbytes=Atom(Bytes.to_stringbytes)letsexp_of_bytes__stackbytes=exclave_Atom(bytes_to_string_localbytes)letsexp_of_intn=Atom(string_of_intn)letsexp_of_int__stackn=exclave_Atom(string_of_intn)letsexp_of_floatn=Atom((Dynamic.getdefault_string_of_float)n)letsexp_of_float__stackn=exclave_Atom((Dynamic.getdefault_string_of_float)(globalize_floatn));;letsexp_of_float_un=(sexp_of_float[@inlined])(box_floatn)letsexp_of_float_u__stackn=exclave_(sexp_of_float__stack[@inlined])(box_floatn)letsexp_of_int32n=Atom(Int32.to_stringn)letsexp_of_int32__stackn=exclave_Atom(string_of_int32n)letsexp_of_int32_un=(sexp_of_int32[@inlined])(box_int32n)letsexp_of_int32_u__stackn=exclave_(sexp_of_int32__stack[@inlined])(box_int32n)letsexp_of_int64n=Atom(Int64.to_stringn)letsexp_of_int64__stackn=exclave_Atom(string_of_int64n)letsexp_of_int64_un=(sexp_of_int64[@inlined])(box_int64n)letsexp_of_int64_u__stackn=exclave_(sexp_of_int64__stack[@inlined])(box_int64n)letsexp_of_nativeintn=Atom(Nativeint.to_stringn)letsexp_of_nativeint__stackn=exclave_Atom(string_of_nativeintn)letsexp_of_nativeint_un=(sexp_of_nativeint[@inlined])(box_nativeintn)letsexp_of_nativeint_u__stackn=exclave_(sexp_of_nativeint__stack[@inlined])(box_nativeintn);;letsexp_of_refsexp_of__arf=sexp_of__a!rfletsexp_of_ref__stacksexp_of__arf=exclave_sexp_of__a!rfletsexp_of_lazy_tsexp_of__alv=sexp_of__a(Lazy.forcelv)letsexp_of_lazy_t__stacksexp_of__alv=exclave_sexp_of__a(lazy_forcelv)letsexp_of_optionsexp_of__aoption=letwrite_old_option_format=Dynamic.getwrite_old_option_formatinmatchoptionwith|Somexwhenwrite_old_option_format->List[sexp_of__ax]|Somex->List[Atom"some";sexp_of__ax]|Nonewhenwrite_old_option_format->List[]|None->Atom"none";;letsexp_of_option__stacksexp_of__aoption=letwrite_old_option_format=Dynamic.getwrite_old_option_formatinmatchoptionwith|Somexwhenwrite_old_option_format->exclave_List[sexp_of__ax]|Somex->exclave_List[Atom"some";sexp_of__ax]|Nonewhenwrite_old_option_format->exclave_List[]|None->exclave_Atom"none";;letsexp_of_or_nullsexp_of__aor_null=letwrite_old_option_format=Dynamic.getwrite_old_option_formatinmatchor_nullwith|Thisxwhenwrite_old_option_format->List[sexp_of__ax]|Thisx->List[Atom"this";sexp_of__ax]|Nullwhenwrite_old_option_format->List[]|Null->Atom"null";;letsexp_of_or_null__stacksexp_of__aor_null=letwrite_old_option_format=Dynamic.getwrite_old_option_formatinmatchor_nullwith|Thisxwhenwrite_old_option_format->exclave_List[sexp_of__ax]|Thisx->exclave_List[Atom"this";sexp_of__ax]|Nullwhenwrite_old_option_format->exclave_List[]|Null->exclave_Atom"null";;letsexp_of_pairsexp_of__asexp_of__b(a,b)=List[sexp_of__aa;sexp_of__bb]letsexp_of_triplesexp_of__asexp_of__bsexp_of__c(a,b,c)=List[sexp_of__aa;sexp_of__bb;sexp_of__cc];;letsexp_of_listsexp_of__alst=List(List.maplst~f:sexp_of__a)letsexp_of_list__stacksexp_of__alst=exclave_List(list_map__stacksexp_of__alst)(* Rebind basic [Array] primitives over [value_or_null mod separable] *)moduleArray=structexternallength:('a:value_or_nullmodseparable).('aarray[@local_opt])@immutable->int@@stateless="%array_length"externalget:('a:value_or_nullmodseparable).('aarray[@local_opt])->int->'a@@portable="%array_safe_get"externalset:('a:value_or_nullmodseparable).('aarray[@local_opt])->int->'a->unit@@portable="%array_safe_set"externalmake:('a:value_or_nullmodseparable).int->'a->'aarray@@portable="caml_array_make"endletsexp_of_array:type(a:value_or_nullmodseparable).(a->Sexp.t)->aarray->Sexp.t=funsexp_of__aar->letlst_ref=ref[]infori=Array.lengthar-1downto0dolst_ref:=sexp_of__aar.(i)::!lst_refdone;List!lst_ref;;letsexp_of_array__stack:('a:value_or_nullmodseparable).(local_'a->local_Sexp.t)->local_'aarray->local_Sexp.t=funsexp_of__aar->exclave_letrecloopiacc=exclave_ifi<0thenListaccelseloop(i-1)(sexp_of__aar.(i)::acc)inloop(Array.lengthar-1)[];;letsexp_of_floatarrayar=letlst_ref=ref[]infori=Float.Array.lengthar-1downto0dolst_ref:=sexp_of_float(Float.Array.unsafe_getari)::!lst_refdone;List!lst_ref;;letsexp_of_floatarray__stack(local_ar)=exclave_letopenstructexternalunsafe_get:floatarray@local->int->float@@portable="%floatarray_unsafe_get"externallength:floatarray@local->int@@portable="%floatarray_length"endinletrecloopiacc=exclave_ifi<0thenListaccelseloop(i-1)(sexp_of_float__stack(unsafe_getari)::acc)inloop(lengthar-1)[];;letsexp_of_hashtblsexp_of_keysexp_of_valhtbl=letcoll~key:k~data:vacc=List[sexp_of_keyk;sexp_of_valv]::accinList(Hashtbl.foldhtbl~init:[]~f:coll);;letsexp_of_opaque_=Atom"<opaque>"letsexp_of_fun_=Atom"<fun>"(* Exception converter registration and lookup *)moduleExn_converter=struct(* Fast and automatic exception registration *)moduleRegistration=structtypet:valuemodcontendedportable={sexp_of_exn:exn->Sexp.t@@portable;(* If [printexc = true] then this sexp converter is used for Printexc.to_string *)printexc:bool}[@@unsafe_allow_any_mode_crossing]endmoduleExn_table=Basement.Stdlib_shim.Ephemeron.K1.MakePortable(structtypet=extension_constructorletequal=(==)lethash=Obj.Extension_constructor.idend)letthe_exn_table:Registration.tExn_table.tWith_mutex.t=With_mutex.create(fun()->Exn_table.create17);;(* Ephemerons are used so that [sexp_of_exn] closure don't keep the
extension_constructor live. *)letadd?(printexc=true)?finalise:_extension_constructorsexp_of_exn=With_mutex.with_lockthe_exn_table~f:(funthe_exn_table->Exn_table.addthe_exn_tableextension_constructor({sexp_of_exn;printexc}:Registration.t));;letfind_auto~for_printexcexn=letextension_constructor=Obj.Extension_constructor.of_valexninletextension_constructor=Portability_hacks.Cross.Portable.(crossextension_constructor)extension_constructorinmatchWith_mutex.with_lockthe_exn_table~f:(funthe_exn_table->letextension_constructor=Portability_hacks.Cross.Contended.(crossextension_constructor)extension_constructorin{Stdlib_shim.Modes.Aliased.aliased=(Exn_table.find_optthe_exn_tableextension_constructor:Registration.toption)})with|{aliased=None}->None|{aliased=Some{sexp_of_exn;printexc}}->(matchfor_printexc,printexcwith|false,_|_,true->Some(sexp_of_exnexn)|true,false->None);;moduleFor_unit_tests_only=structletsize()=With_mutex.with_lockthe_exn_table~f:(funthe_exn_table->(Exn_table.stats_alivethe_exn_table).num_bindings);;endendletsexp_of_exn_opt_for_printexcexn=Exn_converter.find_auto~for_printexc:trueexnletsexp_of_exn_optexn=Exn_converter.find_auto~for_printexc:falseexnletsexp_of_exnexn=matchsexp_of_exn_optexnwith|None->List[Atom(Printexc.to_stringexn)]|Somesexp->sexp;;letexn_to_stringe=Sexp.to_string_hum(sexp_of_exne)(* {[
exception Blah [@@deriving sexp]
]}
generates a call to the function [Exn_converter.add] defined in this file. So we are
guaranted that as soon as we mark an exception as sexpable, this module will be linked
in and this printer will be registered, which is what we want. *)let()=Stdlib_shim.Printexc.Safe.register_printer(funexn->matchsexp_of_exn_opt_for_printexcexnwith|None->None|Somesexp->Some(Sexp.to_string_hum~indent:2sexp));;letprintexc_prefer_sexpexn=matchsexp_of_exn_optexnwith|None->Printexc.to_stringexn|Somesexp->Sexp.to_string_hum~indent:2sexp;;(* Conversion of S-expressions to OCaml-values *)exceptionOf_sexp_error=Sexp.Of_sexp_errorletrecord_check_extra_fields=Dynamic.maketrueletof_sexp_error_exnexcsexp=raise(Of_sexp_error(exc,sexp))letof_sexp_errorwhatsexp=raise(Of_sexp_error(Failurewhat,sexp))letunit_of_sexpsexp=matchsexpwith|List[]->()|Atom_|List_->of_sexp_error"unit_of_sexp: empty list needed"sexp;;letunit_u_of_sexpsexp=matchsexpwith|List[]->#()|Atom_|List_->(matchof_sexp_error"unit_u_of_sexp: empty list needed"sexpwith|(_:nothing)->.);;letbool_of_sexpsexp=matchsexpwith|Atom("true"|"True")->true|Atom("false"|"False")->false|Atom_->of_sexp_error"bool_of_sexp: unknown string"sexp|List_->of_sexp_error"bool_of_sexp: atom needed"sexp;;letbool_u_of_sexpsexp=matchsexpwith|Atom("true"|"True")->#true|Atom("false"|"False")->#false|Atom_->(matchof_sexp_error"bool_of_sexp: unknown string"sexpwith|(_:nothing)->.)|List_->(matchof_sexp_error"bool_of_sexp: atom needed"sexpwith|(_:nothing)->.);;letstring_of_sexpsexp=matchsexpwith|Atomstr->str|List_->of_sexp_error"string_of_sexp: atom needed"sexp;;letbytes_of_sexpsexp=matchsexpwith|Atomstr->Bytes.of_stringstr|List_->of_sexp_error"bytes_of_sexp: atom needed"sexp;;letchar_of_sexpsexp=matchsexpwith|Atomstr->ifString.lengthstr<>1thenof_sexp_error"char_of_sexp: atom string must contain one character only"sexp;str.[0]|List_->of_sexp_error"char_of_sexp: atom needed"sexp;;letchar_u_of_sexpsexp=unbox_char((char_of_sexp[@inlined])sexp)letint_of_sexpsexp=matchsexpwith|Atomstr->(tryint_of_stringstrwith|exc->of_sexp_error("int_of_sexp: "^exn_to_stringexc)sexp)|List_->of_sexp_error"int_of_sexp: atom needed"sexp;;letfloat_of_sexpsexp=matchsexpwith|Atomstr->(tryfloat_of_stringstrwith|exc->of_sexp_error("float_of_sexp: "^exn_to_stringexc)sexp)|List_->of_sexp_error"float_of_sexp: atom needed"sexp;;letfloat_u_of_sexpsexp=unbox_float((float_of_sexp[@inlined])sexp)letint32_of_sexpsexp=matchsexpwith|Atomstr->(tryInt32.of_stringstrwith|exc->of_sexp_error("int32_of_sexp: "^exn_to_stringexc)sexp)|List_->of_sexp_error"int32_of_sexp: atom needed"sexp;;letint32_u_of_sexpsexp=unbox_int32((int32_of_sexp[@inlined])sexp)letint64_of_sexpsexp=matchsexpwith|Atomstr->(tryInt64.of_stringstrwith|exc->of_sexp_error("int64_of_sexp: "^exn_to_stringexc)sexp)|List_->of_sexp_error"int64_of_sexp: atom needed"sexp;;letint64_u_of_sexpsexp=unbox_int64((int64_of_sexp[@inlined])sexp)letnativeint_of_sexpsexp=matchsexpwith|Atomstr->(tryNativeint.of_stringstrwith|exc->of_sexp_error("nativeint_of_sexp: "^exn_to_stringexc)sexp)|List_->of_sexp_error"nativeint_of_sexp: atom needed"sexp;;letnativeint_u_of_sexpsexp=unbox_nativeint((nativeint_of_sexp[@inlined])sexp)letref_of_sexpa__of_sexpsexp=ref(a__of_sexpsexp)letlazy_t_of_sexpa__of_sexpsexp=Lazy.from_val(a__of_sexpsexp)letoption_of_sexpa__of_sexpsexp=ifDynamic.getread_old_option_formatthen(matchsexpwith|List[]|Atom("none"|"None")->None|List[el]|List[Atom("some"|"Some");el]->Some(a__of_sexpel)|List_->of_sexp_error"option_of_sexp: list must represent optional value"sexp|Atom_->of_sexp_error"option_of_sexp: only none can be atom"sexp)else(matchsexpwith|Atom("none"|"None")->None|List[Atom("some"|"Some");el]->Some(a__of_sexpel)|Atom_->of_sexp_error"option_of_sexp: only none can be atom"sexp|List_->of_sexp_error"option_of_sexp: list must be (some el)"sexp);;letor_null_of_sexpa__of_sexpsexp=ifDynamic.getread_old_option_formatthen(matchsexpwith|List[]|Atom("null"|"Null")->Null|List[el]|List[Atom("this"|"This");el]->This(a__of_sexpel)|List_->of_sexp_error"or_null_of_sexp: list must represent or_null value"sexp|Atom_->of_sexp_error"or_null_of_sexp: only null can be atom"sexp)else(matchsexpwith|Atom("null"|"Null")->Null|List[Atom("this"|"This");el]->This(a__of_sexpel)|Atom_->of_sexp_error"or_null_of_sexp: only null can be atom"sexp|List_->of_sexp_error"or_null_of_sexp: list must be (this el)"sexp);;letpair_of_sexpa__of_sexpb__of_sexpsexp=matchsexpwith|List[a_sexp;b_sexp]->leta=a__of_sexpa_sexpinletb=b__of_sexpb_sexpina,b|List_->of_sexp_error"pair_of_sexp: list must contain exactly two elements only"sexp|Atom_->of_sexp_error"pair_of_sexp: list needed"sexp;;lettriple_of_sexpa__of_sexpb__of_sexpc__of_sexpsexp=matchsexpwith|List[a_sexp;b_sexp;c_sexp]->leta=a__of_sexpa_sexpinletb=b__of_sexpb_sexpinletc=c__of_sexpc_sexpina,b,c|List_->of_sexp_error"triple_of_sexp: list must contain exactly three elements only"sexp|Atom_->of_sexp_error"triple_of_sexp: list needed"sexp;;letlist_of_sexpa__of_sexpsexp=matchsexpwith|Listlst->List.maplst~f:a__of_sexp|Atom_->of_sexp_error"list_of_sexp: list needed"sexp;;letarray_of_sexpa__of_sexpsexp=matchsexpwith|List[]->[||]|List(h::t)->letlen=List.lengtht+1inletres=Array.makelen(a__of_sexph)inletrecloopi=function|[]->res|h::t->res.(i)<-a__of_sexph;loop(i+1)tinloop1t|Atom_->of_sexp_error"array_of_sexp: list needed"sexp;;letfloatarray_of_sexpsexp=matchsexpwith|List[]->Float.Array.create0|List(h::t)->letlen=List.lengtht+1inletres=Float.Array.makelen(float_of_sexph)inletrecloopi=function|[]->res|h::t->Float.Array.unsafe_setresi(float_of_sexph);loop(i+1)tinloop1t|Atom_->of_sexp_error"array_of_sexp: list needed"sexp;;lethashtbl_of_sexpkey_of_sexpval_of_sexpsexp=matchsexpwith|Listlst->lethtbl=Hashtbl.create0inletact=function|List[k_sexp;v_sexp]->Hashtbl.addhtbl~key:(key_of_sexpk_sexp)~data:(val_of_sexpv_sexp)|List_|Atom_->of_sexp_error"hashtbl_of_sexp: tuple list needed"sexpinList.iterlst~f:act;htbl|Atom_->of_sexp_error"hashtbl_of_sexp: list needed"sexp;;letopaque_of_sexpsexp=of_sexp_error"opaque_of_sexp: cannot convert opaque values"sexp;;letfun_of_sexpsexp=of_sexp_error"fun_of_sexp: cannot convert function values"sexp(* Sexp Grammars *)includeSexp_conv_grammar(* Registering default exception printers *)letget_flc_errorname(file,line,chr)=Atom(sprintf"%s %s:%d:%d"namefilelinechr)typehandler:valuemodportable={h:exn->Sexp.t@@portable}[@@unboxed][@@unsafe_allow_any_mode_crossing]let()=List.iter~f:(fun(extension_constructor,handler)->Exn_converter.add~printexc:false~finalise:falseextension_constructorhandler.h)[([%extension_constructorAssert_failure],{h=(function|Assert_failurearg->get_flc_error"Assert_failure"arg|_->assertfalse)});([%extension_constructorExit],{h=(function|Exit->Atom"Exit"|_->assertfalse)});([%extension_constructorEnd_of_file],{h=(function|End_of_file->Atom"End_of_file"|_->assertfalse)});([%extension_constructorFailure],{h=(function|Failurearg->List[Atom"Failure";Atomarg]|_->assertfalse)});([%extension_constructorNot_found],{h=(function|Not_found->Atom"Not_found"|_->assertfalse)});([%extension_constructorInvalid_argument],{h=(function|Invalid_argumentarg->List[Atom"Invalid_argument";Atomarg]|_->assertfalse)});([%extension_constructorMatch_failure],{h=(function|Match_failurearg->get_flc_error"Match_failure"arg|_->assertfalse)});([%extension_constructorNot_found_s],{h=(function|Not_found_sarg->List[Atom"Not_found_s";arg]|_->assertfalse)});([%extension_constructorSys_error],{h=(function|Sys_errorarg->List[Atom"Sys_error";Atomarg]|_->assertfalse)});([%extension_constructorArg.Help],{h=(function|Arg.Helparg->List[Atom"Arg.Help";Atomarg]|_->assertfalse)});([%extension_constructorArg.Bad],{h=(function|Arg.Badarg->List[Atom"Arg.Bad";Atomarg]|_->assertfalse)});([%extension_constructorLazy.Undefined],{h=(function|Lazy.Undefined->Atom"Lazy.Undefined"|_->assertfalse)});([%extension_constructorParsing.Parse_error],{h=(function|Parsing.Parse_error->Atom"Parsing.Parse_error"|_->assertfalse)});([%extension_constructorQueue.Empty],{h=(function|Queue.Empty->Atom"Queue.Empty"|_->assertfalse)});([%extension_constructorScanf.Scan_failure],{h=(function|Scanf.Scan_failurearg->List[Atom"Scanf.Scan_failure";Atomarg]|_->assertfalse)});([%extension_constructorStack.Empty],{h=(function|Stack.Empty->Atom"Stack.Empty"|_->assertfalse)});([%extension_constructorSys.Break],{h=(function|Sys.Break->Atom"Sys.Break"|_->assertfalse)})];;let()=List.iter~f:(fun(extension_constructor,handler)->Exn_converter.add~printexc:true~finalise:falseextension_constructorhandler.h)[([%extension_constructorOf_sexp_error],{h=(function|Of_sexp_error(exc,sexp)->List[Atom"Sexplib.Conv.Of_sexp_error";sexp_of_exnexc;sexp]|_->assertfalse)})];;externalignore:('a:value_or_null).('a[@local_opt])->unit@@portable="%ignore"external(=):('a:value_or_null).('a[@local_opt])->('a[@local_opt])->bool@@portable="%equal"(* The compiler generates *catastrophically* bad code if you let it inline this function.
But with that prevented, the compiler reliably optimizes this to a load from a
statically allocated array. *)let[@zero_alloc][@inlinenever][@localnever][@specialisenever]sexp_of_char_statically_allocated=function(*$
for i = 0 to 255 do
Printf.printf "| '\\x%02x' -> Atom \"\\x%02x\"\n" i i
done
*)|'\x00'->Atom"\x00"|'\x01'->Atom"\x01"|'\x02'->Atom"\x02"|'\x03'->Atom"\x03"|'\x04'->Atom"\x04"|'\x05'->Atom"\x05"|'\x06'->Atom"\x06"|'\x07'->Atom"\x07"|'\x08'->Atom"\x08"|'\x09'->Atom"\x09"|'\x0a'->Atom"\x0a"|'\x0b'->Atom"\x0b"|'\x0c'->Atom"\x0c"|'\x0d'->Atom"\x0d"|'\x0e'->Atom"\x0e"|'\x0f'->Atom"\x0f"|'\x10'->Atom"\x10"|'\x11'->Atom"\x11"|'\x12'->Atom"\x12"|'\x13'->Atom"\x13"|'\x14'->Atom"\x14"|'\x15'->Atom"\x15"|'\x16'->Atom"\x16"|'\x17'->Atom"\x17"|'\x18'->Atom"\x18"|'\x19'->Atom"\x19"|'\x1a'->Atom"\x1a"|'\x1b'->Atom"\x1b"|'\x1c'->Atom"\x1c"|'\x1d'->Atom"\x1d"|'\x1e'->Atom"\x1e"|'\x1f'->Atom"\x1f"|'\x20'->Atom"\x20"|'\x21'->Atom"\x21"|'\x22'->Atom"\x22"|'\x23'->Atom"\x23"|'\x24'->Atom"\x24"|'\x25'->Atom"\x25"|'\x26'->Atom"\x26"|'\x27'->Atom"\x27"|'\x28'->Atom"\x28"|'\x29'->Atom"\x29"|'\x2a'->Atom"\x2a"|'\x2b'->Atom"\x2b"|'\x2c'->Atom"\x2c"|'\x2d'->Atom"\x2d"|'\x2e'->Atom"\x2e"|'\x2f'->Atom"\x2f"|'\x30'->Atom"\x30"|'\x31'->Atom"\x31"|'\x32'->Atom"\x32"|'\x33'->Atom"\x33"|'\x34'->Atom"\x34"|'\x35'->Atom"\x35"|'\x36'->Atom"\x36"|'\x37'->Atom"\x37"|'\x38'->Atom"\x38"|'\x39'->Atom"\x39"|'\x3a'->Atom"\x3a"|'\x3b'->Atom"\x3b"|'\x3c'->Atom"\x3c"|'\x3d'->Atom"\x3d"|'\x3e'->Atom"\x3e"|'\x3f'->Atom"\x3f"|'\x40'->Atom"\x40"|'\x41'->Atom"\x41"|'\x42'->Atom"\x42"|'\x43'->Atom"\x43"|'\x44'->Atom"\x44"|'\x45'->Atom"\x45"|'\x46'->Atom"\x46"|'\x47'->Atom"\x47"|'\x48'->Atom"\x48"|'\x49'->Atom"\x49"|'\x4a'->Atom"\x4a"|'\x4b'->Atom"\x4b"|'\x4c'->Atom"\x4c"|'\x4d'->Atom"\x4d"|'\x4e'->Atom"\x4e"|'\x4f'->Atom"\x4f"|'\x50'->Atom"\x50"|'\x51'->Atom"\x51"|'\x52'->Atom"\x52"|'\x53'->Atom"\x53"|'\x54'->Atom"\x54"|'\x55'->Atom"\x55"|'\x56'->Atom"\x56"|'\x57'->Atom"\x57"|'\x58'->Atom"\x58"|'\x59'->Atom"\x59"|'\x5a'->Atom"\x5a"|'\x5b'->Atom"\x5b"|'\x5c'->Atom"\x5c"|'\x5d'->Atom"\x5d"|'\x5e'->Atom"\x5e"|'\x5f'->Atom"\x5f"|'\x60'->Atom"\x60"|'\x61'->Atom"\x61"|'\x62'->Atom"\x62"|'\x63'->Atom"\x63"|'\x64'->Atom"\x64"|'\x65'->Atom"\x65"|'\x66'->Atom"\x66"|'\x67'->Atom"\x67"|'\x68'->Atom"\x68"|'\x69'->Atom"\x69"|'\x6a'->Atom"\x6a"|'\x6b'->Atom"\x6b"|'\x6c'->Atom"\x6c"|'\x6d'->Atom"\x6d"|'\x6e'->Atom"\x6e"|'\x6f'->Atom"\x6f"|'\x70'->Atom"\x70"|'\x71'->Atom"\x71"|'\x72'->Atom"\x72"|'\x73'->Atom"\x73"|'\x74'->Atom"\x74"|'\x75'->Atom"\x75"|'\x76'->Atom"\x76"|'\x77'->Atom"\x77"|'\x78'->Atom"\x78"|'\x79'->Atom"\x79"|'\x7a'->Atom"\x7a"|'\x7b'->Atom"\x7b"|'\x7c'->Atom"\x7c"|'\x7d'->Atom"\x7d"|'\x7e'->Atom"\x7e"|'\x7f'->Atom"\x7f"|'\x80'->Atom"\x80"|'\x81'->Atom"\x81"|'\x82'->Atom"\x82"|'\x83'->Atom"\x83"|'\x84'->Atom"\x84"|'\x85'->Atom"\x85"|'\x86'->Atom"\x86"|'\x87'->Atom"\x87"|'\x88'->Atom"\x88"|'\x89'->Atom"\x89"|'\x8a'->Atom"\x8a"|'\x8b'->Atom"\x8b"|'\x8c'->Atom"\x8c"|'\x8d'->Atom"\x8d"|'\x8e'->Atom"\x8e"|'\x8f'->Atom"\x8f"|'\x90'->Atom"\x90"|'\x91'->Atom"\x91"|'\x92'->Atom"\x92"|'\x93'->Atom"\x93"|'\x94'->Atom"\x94"|'\x95'->Atom"\x95"|'\x96'->Atom"\x96"|'\x97'->Atom"\x97"|'\x98'->Atom"\x98"|'\x99'->Atom"\x99"|'\x9a'->Atom"\x9a"|'\x9b'->Atom"\x9b"|'\x9c'->Atom"\x9c"|'\x9d'->Atom"\x9d"|'\x9e'->Atom"\x9e"|'\x9f'->Atom"\x9f"|'\xa0'->Atom"\xa0"|'\xa1'->Atom"\xa1"|'\xa2'->Atom"\xa2"|'\xa3'->Atom"\xa3"|'\xa4'->Atom"\xa4"|'\xa5'->Atom"\xa5"|'\xa6'->Atom"\xa6"|'\xa7'->Atom"\xa7"|'\xa8'->Atom"\xa8"|'\xa9'->Atom"\xa9"|'\xaa'->Atom"\xaa"|'\xab'->Atom"\xab"|'\xac'->Atom"\xac"|'\xad'->Atom"\xad"|'\xae'->Atom"\xae"|'\xaf'->Atom"\xaf"|'\xb0'->Atom"\xb0"|'\xb1'->Atom"\xb1"|'\xb2'->Atom"\xb2"|'\xb3'->Atom"\xb3"|'\xb4'->Atom"\xb4"|'\xb5'->Atom"\xb5"|'\xb6'->Atom"\xb6"|'\xb7'->Atom"\xb7"|'\xb8'->Atom"\xb8"|'\xb9'->Atom"\xb9"|'\xba'->Atom"\xba"|'\xbb'->Atom"\xbb"|'\xbc'->Atom"\xbc"|'\xbd'->Atom"\xbd"|'\xbe'->Atom"\xbe"|'\xbf'->Atom"\xbf"|'\xc0'->Atom"\xc0"|'\xc1'->Atom"\xc1"|'\xc2'->Atom"\xc2"|'\xc3'->Atom"\xc3"|'\xc4'->Atom"\xc4"|'\xc5'->Atom"\xc5"|'\xc6'->Atom"\xc6"|'\xc7'->Atom"\xc7"|'\xc8'->Atom"\xc8"|'\xc9'->Atom"\xc9"|'\xca'->Atom"\xca"|'\xcb'->Atom"\xcb"|'\xcc'->Atom"\xcc"|'\xcd'->Atom"\xcd"|'\xce'->Atom"\xce"|'\xcf'->Atom"\xcf"|'\xd0'->Atom"\xd0"|'\xd1'->Atom"\xd1"|'\xd2'->Atom"\xd2"|'\xd3'->Atom"\xd3"|'\xd4'->Atom"\xd4"|'\xd5'->Atom"\xd5"|'\xd6'->Atom"\xd6"|'\xd7'->Atom"\xd7"|'\xd8'->Atom"\xd8"|'\xd9'->Atom"\xd9"|'\xda'->Atom"\xda"|'\xdb'->Atom"\xdb"|'\xdc'->Atom"\xdc"|'\xdd'->Atom"\xdd"|'\xde'->Atom"\xde"|'\xdf'->Atom"\xdf"|'\xe0'->Atom"\xe0"|'\xe1'->Atom"\xe1"|'\xe2'->Atom"\xe2"|'\xe3'->Atom"\xe3"|'\xe4'->Atom"\xe4"|'\xe5'->Atom"\xe5"|'\xe6'->Atom"\xe6"|'\xe7'->Atom"\xe7"|'\xe8'->Atom"\xe8"|'\xe9'->Atom"\xe9"|'\xea'->Atom"\xea"|'\xeb'->Atom"\xeb"|'\xec'->Atom"\xec"|'\xed'->Atom"\xed"|'\xee'->Atom"\xee"|'\xef'->Atom"\xef"|'\xf0'->Atom"\xf0"|'\xf1'->Atom"\xf1"|'\xf2'->Atom"\xf2"|'\xf3'->Atom"\xf3"|'\xf4'->Atom"\xf4"|'\xf5'->Atom"\xf5"|'\xf6'->Atom"\xf6"|'\xf7'->Atom"\xf7"|'\xf8'->Atom"\xf8"|'\xf9'->Atom"\xf9"|'\xfa'->Atom"\xfa"|'\xfb'->Atom"\xfb"|'\xfc'->Atom"\xfc"|'\xfd'->Atom"\xfd"|'\xfe'->Atom"\xfe"|'\xff'->Atom"\xff";;(*$*)let[@inlinealways]is_valid_char(char:char):bool=Char.codecharlandlnot0xff=0let[@inlinenever][@localnever][@specialisenever]fallback_sexp_of_char(char:char)=Atom((String.make[@inlinednever])1char);;let[@inlinealways]sexp_of_char(char:char)=ifis_valid_charcharthensexp_of_char_statically_allocatedchar[@tail]elsefallback_sexp_of_charchar[@tail];;let[@inlinenever][@localnever][@specialisenever]fallback_sexp_of_char__stack(char:char)=exclave_Atom((string_make_local[@inlinednever])1char);;let[@inlinealways]sexp_of_char__stack(char:char)=exclave_ifis_valid_charcharthensexp_of_char_statically_allocatedcharelsefallback_sexp_of_char__stackchar;;letsexp_of_char_uchar=(sexp_of_char[@inlined])(box_charchar)letsexp_of_char_u__stackchar=exclave_(sexp_of_char__stack[@inlined])(box_charchar)