Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ast_external_mk.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
* Copyright (C) 2017 - Hongbo Zhang, Authors of ReScript
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)openPpxlibopenAst_helperletlocal_external_applyloc?(pval_attributes=[])~(pval_prim:stringlist)~(pval_type:Parsetree.core_type)?(local_module_name="J")?(local_fun_name="unsafe_expr")(args:Parsetree.expressionlist):Parsetree.expression_desc=Pexp_letmodule({txt=Somelocal_module_name;loc},{pmod_desc=Pmod_structure[{pstr_desc=Pstr_primitive{pval_name={txt=local_fun_name;loc};pval_type;pval_loc=loc;pval_prim;pval_attributes;};pstr_loc=loc;};];pmod_loc=loc;pmod_attributes=[];},Exp.apply({pexp_desc=Pexp_ident{txt=Ldot(Lidentlocal_module_name,local_fun_name);loc};pexp_attributes=[];pexp_loc=loc;pexp_loc_stack=[loc];}:Parsetree.expression)(List.map(funx->(Asttypes.Nolabel,x))args)~loc)letlocal_external_objloc?(pval_attributes=[])~pval_prim~pval_type?(local_module_name="J")?(local_fun_name="unsafe_expr")args:Parsetree.expression_desc=Pexp_letmodule({txt=Somelocal_module_name;loc},{pmod_desc=Pmod_structure[{pstr_desc=Pstr_primitive{pval_name={txt=local_fun_name;loc};pval_type;pval_loc=loc;pval_prim;pval_attributes;};pstr_loc=loc;};];pmod_loc=loc;pmod_attributes=[];},Exp.apply({pexp_desc=Pexp_ident{txt=Ldot(Lidentlocal_module_name,local_fun_name);loc};pexp_attributes=[];pexp_loc=loc;pexp_loc_stack=[loc];}:Parsetree.expression)(List.map(fun(l,a)->(Asttypes.Labelledl,a))args)~loc)letlocal_extern_cont_to_objloc?(pval_attributes=[])~pval_prim~pval_type?(local_module_name="J")?(local_fun_name="unsafe_expr")(cb:Parsetree.expression->'a):Parsetree.expression_desc=Pexp_letmodule({txt=Somelocal_module_name;loc},{pmod_desc=Pmod_structure[{pstr_desc=Pstr_primitive{pval_name={txt=local_fun_name;loc};pval_type;pval_loc=loc;pval_prim;pval_attributes;};pstr_loc=loc;};];pmod_loc=loc;pmod_attributes=[];},cb{pexp_desc=Pexp_ident{txt=Ldot(Lidentlocal_module_name,local_fun_name);loc};pexp_attributes=[];pexp_loc=loc;pexp_loc_stack=[loc];})typelabel_exprs=(Longident.tAsttypes.loc*Parsetree.expression)list(* Note that OCaml type checker will not allow arbitrary
name as type variables, for example:
{[
'_x'_
]}
will be recognized as a invalid program
*)letfrom_labels~locaritylabels:Parsetree.core_type=lettyvars=List.initarity(funi->Typ.var~loc("a"^string_of_inti))inletresult_type=Ast_comb.to_js_type~loc(Typ.object_~loc(List.map2(funxy->Of.tagxy)labelstyvars)Closed)inList.fold_right2(funlabel(* {loc ; txt = label }*)tyvaracc->Typ.arrow~loc:label.loc(Labelledlabel.txt)tyvaracc)labelstyvarsresult_typeletpval_prim_of_labels(labels:stringAsttypes.loclist)=letarg_kinds=List.fold_right(funparg_kinds->letobj_arg_label=External_arg_spec.obj_label(Lam_methname.translatep.txt)in{External_arg_spec.obj_arg_type=Nothing;obj_arg_label}::arg_kinds)labels[]inExternal_ffi_types.ffi_obj_as_primsarg_kindsletpval_prim_of_option_labels(labels:(bool*stringAsttypes.loc)list)(ends_with_unit:bool)=letarg_kinds=List.fold_right(fun(is_option,p)arg_kinds->letlabel_name=Lam_methname.translatep.txtinletobj_arg_label=ifis_optionthenExternal_arg_spec.optionalfalselabel_nameelseExternal_arg_spec.obj_labellabel_namein{External_arg_spec.obj_arg_type=Nothing;obj_arg_label}::arg_kinds)labels(ifends_with_unitthen[External_arg_spec.empty_kindExtern_unit]else[])inExternal_ffi_types.ffi_obj_as_primsarg_kindsletrecord_as_js_objectloc(label_exprs:label_exprs):Parsetree.expression_desc=letlabels,args,arity=List.fold_right(fun({txt;loc},e)(labels,args,i)->matchtxtwith|Lidentx->({Asttypes.loc;txt=x}::labels,(x,e)::args,i+1)|Ldot_|Lapply_->Location.raise_errorf~loc"invalid js label ")label_exprs([],[],0)inlocal_external_objloc~pval_prim:(pval_prim_of_labelslabels)~pval_type:(from_labels~locaritylabels)args