123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337openBaseopenPpxlibopenAst_builder.Defaultletraise_unsupported~locs=Location.raise_errorf~loc"Unsupported use of %s (you can only use it on records)."stypesimple_processor=Location.t->field_name:string->expressiontyperecursive_processor=Location.t->field_name:string->type_name:string->path:Longident.toption->expressionmoduletypeComplete=sigvalconversion_name:stringvalfunction_name:stringoption->stringvalmerge_recursive:Location.t->field_name:string->tp:core_type->expression->expressionvalunsupported_type_error_msg:name:string->stringvalunit:simple_processorvalbool:simple_processorvalstring:simple_processorvalchar:simple_processorvalint:simple_processorvalfloat:simple_processorvalint32:simple_processorvalint64:simple_processorvalnativeint:simple_processorvalbig_int:simple_processorvalnat:simple_processorvalnum:simple_processorvalratio:simple_processorvallist:simple_processorvalarray:simple_processorvaloption:simple_processorvalref:simple_processorvallazy_t:simple_processorvalrecursive:recursive_processorendmoduletypeComplete_list=sigincludeCompletevalprepend:Location.t->expression->expressionendmoduletypeSimple=sigvalconversion_name:stringvalfunction_name:stringoption->stringvalmerge_recursive:Location.t->field_name:string->tp:core_type->expression->expressionvalunsupported_type_error_msg:name:string->stringvalatoms:simple_processorvalrecursive:recursive_processorendmoduletypeMatcher=sigvalconversion:Location.t->field_name:string->id:Longident.tLocated.t->expressionvalconversion_of_type:Location.t->field_name:string->field_ty:core_type->expressionendletconversion_of_type~conversion~conversion_name~merge_recursive~function_nameloc~field_name~field_ty=letrecauxlocfield_ty=matchfield_ty.ptyp_descwith|Ptyp_constr(id,args)->letid_expr=conversionloc~field_name~idinletargs_expr=List.mapargs~f:(auxloc)inmerge_recursiveloc~field_name~tp:field_ty(eapply~locid_exprargs_expr)|Ptyp_varparam->evar~loc(function_name(Someparam))|_->Location.raise_errorf~loc"%s: unsupported type construct"conversion_nameinauxlocfield_tymoduleOf_simple(S:Simple)=structletconversionloc~field_name~(id:Longident.tLocated.t)=matchid.txtwith|Lident"unit"|Lident"bool"|Lident"string"|Lident"char"|Lident"int"|Lident"float"|Lident"int32"|Lident"int64"|Lident"nativeint"|Ldot(Lident"Big_int","big_int")|Ldot(Lident"Nat","nat")|Ldot(Lident"Num","num")|Ldot(Lident"Ratio","ratio")->S.atomsloc~field_name|Lident"ref"|Ldot(Lident"Lazy","t")|Lident"lazy_t"|Lident"sexp_option"|Lident"option"|Lident"list"|Lident"array"|Ldot(Lident"Hashtbl","t")|Lident"bigstring"|Lident"vec"|Lident"float32_vec"|Lident"float64_vec"|Lident"mat"|Lident"float32_mat"|Lident"float64_mat"|Lident"exn"->letname=Longident.last_exnid.txtinLocation.raise_errorf~loc"%s"(S.unsupported_type_error_msg~name)|Ldot(path,type_name)->S.recursiveloc~field_name~type_name~path:(Somepath)|Lidenttype_name->S.recursiveloc~field_name~type_name~path:None|Lapply_->assertfalseletconversion_of_type=conversion_of_type~conversion~conversion_name:S.conversion_name~function_name:S.function_name~merge_recursive:S.merge_recursiveendmoduleOf_complete(S:Complete)=structletconversionloc~field_name~(id:Longident.tLocated.t)=matchid.txtwith|Lident"unit"->S.unitloc~field_name|Lident"bool"->S.boolloc~field_name|Lident"string"->S.stringloc~field_name|Lident"char"->S.charloc~field_name|Lident"int"->S.intloc~field_name|Lident"decimal"->S.floatloc~field_name|Lident"float"->S.floatloc~field_name|Lident"int32"->S.int32loc~field_name|Lident"int64"->S.int64loc~field_name|Lident"nativeint"->S.nativeintloc~field_name|Ldot(Lident"Big_int","big_int")->S.big_intloc~field_name|Ldot(Lident"Nat","nat")->S.natloc~field_name|Ldot(Lident"Num","num")->S.numloc~field_name|Ldot(Lident"Ratio","ratio")->S.ratioloc~field_name|Lident"list"->S.listloc~field_name|Lident"array"->S.arrayloc~field_name|Lident"sexp_option"|Lident"option"->S.optionloc~field_name|Lident"ref"|Ldot(Lident"Lazy","t")|Lident"lazy_t"|Ldot(Lident"Hashtbl","t")|Lident"bigstring"|Lident"vec"|Lident"float32_vec"|Lident"float64_vec"|Lident"mat"|Lident"float32_mat"|Lident"float64_mat"|Lident"exn"->letname=Longident.last_exnid.txtinLocation.raise_errorf~loc"%s"(S.unsupported_type_error_msg~name)|Ldot(path,type_name)->S.recursiveloc~field_name~type_name~path:(Somepath)|Lidenttype_name->S.recursiveloc~field_name~type_name~path:None|Lapply_->assertfalse(* impossible *)letconversion_of_type=conversion_of_type~conversion~conversion_name:S.conversion_name~function_name:S.function_name~merge_recursive:S.merge_recursiveendmoduleOf_list(P:Complete_list)=structincludeOf_complete(P)letconversion_of_type_loc~field_name~field_ty=P.prepend_loc(conversion_of_type_loc~field_name~field_ty)endletlambdalocpse=eabstract~locpsemoduleGen_sig=struct(*let label_arg _loc name ty = Ast.TyLab (_loc, name, ty)
let rec loop _loc this_type output_type = function
| [] -> <:ctyp< $this_type$ -> $output_type$ >>
| tp :: tps ->
let tp = Gen.drop_variance_annotations tp in
let row_of = loop _loc <:ctyp< $this_type$ $tp$ >> output_type tps in
<:ctyp< ( $tp$ -> $output_type$) -> $row_of$ >>
let row_of_t' ~record_name ~tps _loc =
let t = loop _loc <:ctyp< $lid:record_name$ >> <:ctyp< unit >> tps in
let is_first = label_arg _loc "is_first" <:ctyp< bool >> in
let is_last = label_arg _loc "is_last" <:ctyp< bool >> in
let writer = label_arg _loc "writer" <:ctyp< string -> unit >> in
<:sig_item< value $lid: "write_row_of_" ^ record_name ^ "'"$ :
$is_first$ -> $is_last$ -> $writer$ -> _ -> _ -> $t$ >>
;;
let t_of_row' ~record_name _loc =
let f = <:ctyp< unit -> $lid: record_name$ >> in
let pair = <:ctyp< $f$ * (string list) >> in
<:sig_item< value $lid: record_name ^ "_of_row'"$ : _ -> string list -> $pair$ >>
;;*)letfields_of_tytd~extension_name~nil~record=letloc=td.ptype_locinletunsupported()=raise_unsupported~locextension_nameinlettps=List.maptd.ptype_params~f:fstinmatchtd.ptype_kindwith|Ptype_open|Ptype_variant_->unsupported()|Ptype_recordlds->record~tps~record_name:td.ptype_name.txtloclds|Ptype_abstract->matchtd.ptype_manifestwith|Some{ptyp_desc=Ptyp_variant_;_}->unsupported()|_->nil~tps~record_name:td.ptype_name.txtlocletgenerate~extension_name~nil~record~loc~path:_(_rf,tds)=matchtdswith|[td]->fields_of_tytd~extension_name~nil~record|_->raise_unsupported~locextension_nameendletarg_label_of_strings:Asttypes.arg_label=ifString.is_emptysthenNolabelelseifChar.equals.[0]'?'thenOptional(String.drop_prefixs1)elseLabelledsmoduleGen_struct=struct(*let label_arg ?label _loc name =
let l =
match label with
| None -> name
| Some n -> n in
Ast.PaLab (_loc, l, <:patt< $lid:name$ >> )
;;*)letfieldld=letmutability=matchld.pld_mutablewith|Mutable->`Mutable|Immutable->`Immutablein(ld.pld_name.txt,mutability,ld.pld_type);;letfieldslds=List.maplds~f:fieldletvaluedefaultopt=matchoptwith|None->default|Somev->vletmake_body?unique_f?first_f?last_f~lds~initlocmiddle_f=letunique_f=valuemiddle_funique_finletfirst_f=valuemiddle_ffirst_finletlast_f=valuemiddle_flast_finletadd_one_fieldfacc(field_name,_kind,field_ty)=letf=floc~field_name~field_tyinpexp_apply~locacc[(arg_label_of_stringfield_name,f)]inletfields=fieldsldsinmatchfieldswith|[]->assertfalse|[h]->add_one_fieldunique_finith|first::t->matchList.revtwith|[]->assertfalse|last::t->lett=List.revtinletinit=add_one_fieldfirst_finitfirstinletinit=List.fold_leftt~init~f:(add_one_fieldmiddle_f)inadd_one_fieldlast_finitlastletanonymousloc=[%pat?_]letidentx=xletgenerate_using_fold?(wrap_body=ident)~pass_acc~pass_anonymous~conversion_of_type~name~ldsloc=letacc=[%pat?acc]inletinit=ifpass_accthen[%exprFields.fold~init:acc]else[%exprFields.fold~init:[]]inletbody=make_body~lds~initlocconversion_of_typeinletanonymous=anonymouslocinletfunc=letarguments=ifpass_anonymousthen[anonymous;anonymous;]else[]inletarguments=ifpass_accthenacc::argumentselseargumentsinletbody=wrap_bodybodyinmatchargumentswith|[]->body|arguments->lambdalocargumentsbodyinpstr_value~locNonrecursive[value_binding~loc~pat:name~expr:func]letfields_of_tytd~extension_name~record=letloc=td.ptype_locinletunsupported()=raise_unsupported~locextension_nameinlettps=List.maptd.ptype_params~f:fstinmatchtd.ptype_kindwith|Ptype_open|Ptype_variant_->unsupported()|Ptype_recordlds->record~tps~record_name:td.ptype_name.txtloclds|Ptype_abstract->unsupported()letgenerate~extension_name~record~loc~path:_(_rf,tds)=matchtdswith|[td]->fields_of_tytd~extension_name~record|_->raise_unsupported~locextension_nameend