@@ -23701,6 +23701,8 @@ let is_single_int (x : t ) =
23701
23701
_}] -> Some name
23702
23702
| _ -> None
23703
23703
23704
+
23705
+
23704
23706
let as_string_exp (x : t ) =
23705
23707
match x with (** TODO also need detect empty phrase case *)
23706
23708
| PStr [ {
@@ -25334,8 +25336,8 @@ type derive_attr = {
25334
25336
explict_nonrec : bool;
25335
25337
bs_deriving : [`Has_deriving of Ast_payload.action list | `Nothing ]
25336
25338
}
25337
- val process_bs_string_int :
25338
- t -> [`Nothing | `String | `Int | `Ignore] * t
25339
+ val process_bs_string_int_uncurry :
25340
+ t -> [`Nothing | `String | `Int | `Ignore | `Uncurry of int option ] * t
25339
25341
25340
25342
val process_bs_string_as :
25341
25343
t -> string option * t
@@ -25359,6 +25361,9 @@ val bs_method : attr
25359
25361
25360
25362
25361
25363
val warn_unused_attributes : t -> unit
25364
+
25365
+
25366
+
25362
25367
end = struct
25363
25368
#1 "ast_attributes.ml"
25364
25369
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -25509,17 +25514,24 @@ let process_derive_type attrs =
25509
25514
25510
25515
25511
25516
25512
- let process_bs_string_int attrs =
25517
+ let process_bs_string_int_uncurry attrs =
25513
25518
List.fold_left
25514
25519
(fun (st,attrs)
25515
- (({txt ; loc}, payload ) as attr : attr) ->
25520
+ (({txt ; loc}, ( payload : _ ) ) as attr : attr) ->
25516
25521
match txt, st with
25517
25522
| "bs.string", (`Nothing | `String)
25518
25523
-> `String, attrs
25519
25524
| "bs.int", (`Nothing | `Int)
25520
25525
-> `Int, attrs
25521
25526
| "bs.ignore", (`Nothing | `Ignore)
25522
25527
-> `Ignore, attrs
25528
+
25529
+ | "bs.uncurry", `Nothing
25530
+ ->
25531
+ `Uncurry (Ast_payload.is_single_int payload), attrs
25532
+ (* Don't allow duplicated [bs.uncurry] since
25533
+ it may introduce inconsistency in arity
25534
+ *)
25523
25535
| "bs.int", _
25524
25536
| "bs.string", _
25525
25537
| "bs.ignore", _
@@ -27300,8 +27312,8 @@ val is_unit : t -> bool
27300
27312
val is_array : t -> bool
27301
27313
type arg_label =
27302
27314
| Label of string
27303
- (*| Label_int_lit of string * int
27304
- | Label_string_lit of string * string *)
27315
+ (*| Label_int_lit of string * int
27316
+ | Label_string_lit of string * string *)
27305
27317
| Optional of string
27306
27318
| Empty
27307
27319
type arg_type =
@@ -27310,6 +27322,7 @@ type arg_type =
27310
27322
| Int of (int * int ) list
27311
27323
| Arg_int_lit of int
27312
27324
| Arg_string_lit of string
27325
+ | Fn_uncurry_arity of int (* annotated with [@bs.uncurry ] or [@bs.uncurry 2]*)
27313
27326
| Array
27314
27327
| Extern_unit
27315
27328
| Nothing
@@ -27339,6 +27352,19 @@ val make_obj :
27339
27352
t
27340
27353
27341
27354
val is_optional_label : string -> bool
27355
+
27356
+ (**
27357
+ returns 0 when it can not tell arity from the syntax
27358
+ *)
27359
+ val get_arity : t -> int
27360
+
27361
+
27362
+ (** fails when Ptyp_poly *)
27363
+ val list_of_arrow :
27364
+ t ->
27365
+ t * (Asttypes.label * t * Parsetree.attributes * Location.t) list
27366
+
27367
+
27342
27368
end = struct
27343
27369
#1 "ast_core_type.ml"
27344
27370
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -27378,6 +27404,7 @@ type arg_type =
27378
27404
| Int of (int * int ) list (* ([`a | `b ] [@bs.int])*)
27379
27405
| Arg_int_lit of int
27380
27406
| Arg_string_lit of string
27407
+ | Fn_uncurry_arity of int (* annotated with [@bs.uncurry ] or [@bs.uncurry 2]*)
27381
27408
(* maybe we can improve it as a combination of {!Asttypes.constant} and tuple *)
27382
27409
| Array
27383
27410
| Extern_unit
@@ -27475,6 +27502,35 @@ let make_obj ~loc xs =
27475
27502
Ast_comb.to_js_type loc @@
27476
27503
Ast_helper.Typ.object_ ~loc xs Closed
27477
27504
27505
+
27506
+
27507
+ (**
27508
+
27509
+ {[ 'a . 'a -> 'b ]}
27510
+ OCaml does not support such syntax yet
27511
+ {[ 'a -> ('a. 'a -> 'b) ]}
27512
+
27513
+ *)
27514
+ let get_arity (ty : t) =
27515
+ let rec aux (ty : t) acc =
27516
+ match ty.ptyp_desc with
27517
+ | Ptyp_arrow(_, _ , new_ty) ->
27518
+ aux new_ty (succ acc)
27519
+ | Ptyp_poly (_,ty) ->
27520
+ aux ty acc
27521
+ | _ -> acc in
27522
+ aux ty 0
27523
+
27524
+ let list_of_arrow (ty : t) =
27525
+ let rec aux (ty : t) acc =
27526
+ match ty.ptyp_desc with
27527
+ | Ptyp_arrow(label,t1,t2) ->
27528
+ aux t2 ((label,t1,ty.ptyp_attributes,ty.ptyp_loc) ::acc)
27529
+ | Ptyp_poly(_, ty) -> (* should not happen? *)
27530
+ Location.raise_errorf ~loc:ty.ptyp_loc "Unhandled poly type"
27531
+ | return_type -> ty, List.rev acc
27532
+ in aux ty []
27533
+
27478
27534
end
27479
27535
module Ast_ffi_types : sig
27480
27536
#1 "ast_ffi_types.mli"
@@ -27656,11 +27712,14 @@ type arg_type = Ast_core_type.arg_type =
27656
27712
| Int of (int * int ) list (* ([`a | `b ] [@bs.int])*)
27657
27713
| Arg_int_lit of int
27658
27714
| Arg_string_lit of string
27715
+ | Fn_uncurry_arity of int (* annotated with [@bs.uncurry ] or [@bs.uncurry 2]*)
27659
27716
(* maybe we can improve it as a combination of {!Asttypes.constant} and tuple *)
27660
27717
| Array
27661
27718
| Extern_unit
27662
27719
| Nothing
27663
- | Ignore
27720
+
27721
+
27722
+ | Ignore (* annotated with [@bs.ignore] *)
27664
27723
27665
27724
type arg_label =
27666
27725
| Label of string
@@ -28624,7 +28683,7 @@ let get_arg_type ~nolabel optional
28624
28683
Arg_string_lit i, Ast_literal.type_string ~loc:ptyp.ptyp_loc ()
28625
28684
end
28626
28685
else
28627
- match Ast_attributes.process_bs_string_int ptyp.ptyp_attributes, ptyp.ptyp_desc with
28686
+ match Ast_attributes.process_bs_string_int_uncurry ptyp.ptyp_attributes, ptyp.ptyp_desc with
28628
28687
| (`String, ptyp_attributes), Ptyp_variant ( row_fields, Closed, None)
28629
28688
->
28630
28689
let case, result, row_fields =
@@ -28689,6 +28748,27 @@ let get_arg_type ~nolabel optional
28689
28748
}
28690
28749
28691
28750
| (`Int, _), _ -> Location.raise_errorf ~loc:ptyp.ptyp_loc "Not a valid string type"
28751
+ | (`Uncurry opt_arity, ptyp_attributes), ptyp_desc ->
28752
+ let real_arity = Ast_core_type.get_arity ptyp in
28753
+ (begin match opt_arity, real_arity with
28754
+ | Some arity, 0 ->
28755
+ Fn_uncurry_arity arity
28756
+ | None, 0 ->
28757
+ Location.raise_errorf
28758
+ ~loc:ptyp.ptyp_loc
28759
+ "Can not infer the arity by syntax, either [@bs.uncurry n] or \n\
28760
+ write it in arrow syntax
28761
+ "
28762
+ | None, arity ->
28763
+ Fn_uncurry_arity arity
28764
+ | Some arity, n ->
28765
+ if n <> arity then
28766
+ Location.raise_errorf
28767
+ ~loc:ptyp.ptyp_loc
28768
+ "Inconsistent arity %d vs %d" arity n
28769
+ else Fn_uncurry_arity arity
28770
+
28771
+ end, {ptyp with ptyp_attributes})
28692
28772
| (`Nothing, ptyp_attributes), ptyp_desc ->
28693
28773
begin match ptyp_desc with
28694
28774
| Ptyp_constr ({txt = Lident "bool"}, [])
@@ -28836,15 +28916,6 @@ let process_external_attributes
28836
28916
(init_st, []) prim_attributes
28837
28917
28838
28918
28839
- let list_of_arrow (ty : Parsetree.core_type) =
28840
- let rec aux (ty : Parsetree.core_type) acc =
28841
- match ty.ptyp_desc with
28842
- | Ptyp_arrow(label,t1,t2) ->
28843
- aux t2 ((label,t1,ty.ptyp_attributes,ty.ptyp_loc) ::acc)
28844
- | Ptyp_poly(_, ty) -> (* should not happen? *)
28845
- Location.raise_errorf ~loc:ty.ptyp_loc "Unhandled poly type"
28846
- | return_type -> ty, List.rev acc
28847
- in aux ty []
28848
28919
28849
28920
28850
28921
(** Note that the passed [type_annotation] is already processed by visitor pattern before
@@ -28860,7 +28931,7 @@ let handle_attributes
28860
28931
else `Nm_external prim_name (* need check name *)
28861
28932
in
28862
28933
let result_type, arg_types_ty =
28863
- list_of_arrow type_annotation in
28934
+ Ast_core_type. list_of_arrow type_annotation in
28864
28935
28865
28936
let (st, left_attrs) =
28866
28937
process_external_attributes
@@ -28930,6 +29001,9 @@ let handle_attributes
28930
29001
{arg_label = Label s; arg_type},
28931
29002
(label,new_ty,attr,loc)::arg_types,
28932
29003
((name, [], Ast_literal.type_string ~loc ()) :: result_types)
29004
+ | Fn_uncurry_arity _ ->
29005
+ Location.raise_errorf ~loc
29006
+ "The combination of [@@bs.obj], [@@bs.uncurry] is not supported yet"
28933
29007
| Extern_unit -> assert false
28934
29008
| NonNullString _
28935
29009
->
@@ -28962,6 +29036,9 @@ let handle_attributes
28962
29036
| Arg_int_lit _
28963
29037
| Arg_string_lit _ ->
28964
29038
Location.raise_errorf ~loc "bs.as is not supported with optional yet"
29039
+ | Fn_uncurry_arity _ ->
29040
+ Location.raise_errorf ~loc
29041
+ "The combination of [@@bs.obj], [@@bs.uncurry] is not supported yet"
28965
29042
| Extern_unit -> assert false
28966
29043
| NonNullString _
28967
29044
->
0 commit comments