1
- (* * Bundled by bspack 08/24-11:29 *)
1
+ (* * Bundled by bspack 08/25-10:52 *)
2
2
module String_map : sig
3
3
#1 " string_map.mli"
4
4
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -115,7 +115,8 @@ type action =
115
115
val is_single_string : t -> string option
116
116
val is_single_int : t -> int option
117
117
118
- val as_string_exp : t -> Parsetree .expression option
118
+ val as_string_exp : t -> Parsetree .expression option
119
+ val as_core_type : Location .t -> t -> Parsetree .core_type
119
120
val as_empty_structure : t -> bool
120
121
val as_ident : t -> lid option
121
122
val raw_string_payload : Location .t -> string -> t
@@ -203,6 +204,11 @@ let as_string_exp (x : t ) =
203
204
_}] -> Some e
204
205
| _ -> None
205
206
207
+ let as_core_type loc x =
208
+ match x with
209
+ | Parsetree. PTyp x -> x
210
+ | _ -> Location. raise_errorf ~loc " except a core type"
211
+
206
212
let as_ident (x : t ) =
207
213
match x with
208
214
| PStr [
@@ -1393,7 +1399,7 @@ val init : int -> (int -> 'a) -> 'a list
1393
1399
val take : int -> 'a list -> 'a list * 'a list
1394
1400
val try_take : int -> 'a list -> 'a list * int * 'a list
1395
1401
1396
- val exclude_tail : 'a list -> 'a list
1402
+ val exclude_tail : 'a list -> 'a * 'a list
1397
1403
1398
1404
val filter_map2 : ('a -> 'b -> 'c option ) -> 'a list -> 'b list -> 'c list
1399
1405
@@ -1457,6 +1463,8 @@ val ref_push : 'a -> 'a t -> unit
1457
1463
1458
1464
val ref_pop : 'a t -> 'a
1459
1465
1466
+ val rev_except_last : 'a list -> 'a list * 'a
1467
+
1460
1468
end = struct
1461
1469
#1 " ext_list.ml"
1462
1470
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -1645,11 +1653,11 @@ let try_take n l =
1645
1653
l, arr_length, []
1646
1654
else Array. to_list (Array. sub arr 0 n ), n, (Array. to_list (Array. sub arr n (arr_length - n)))
1647
1655
1648
- let exclude_tail (x : 'a list ) : 'a list =
1656
+ let exclude_tail (x : 'a list ) =
1649
1657
let rec aux acc x =
1650
1658
match x with
1651
1659
| [] -> invalid_arg " Ext_list.exclude_tail"
1652
- | [ _ ] -> List. rev acc
1660
+ | [ x ] -> x, List. rev acc
1653
1661
| y0 ::ys -> aux (y0::acc) ys in
1654
1662
aux [] x
1655
1663
@@ -1794,6 +1802,14 @@ let ref_pop refs =
1794
1802
refs := rest ;
1795
1803
x
1796
1804
1805
+ let rev_except_last xs =
1806
+ let rec aux acc xs =
1807
+ match xs with
1808
+ | [ ] -> invalid_arg " Ext_list.rev_except_last"
1809
+ | [ x ] -> acc ,x
1810
+ | x :: xs -> aux (x::acc) xs in
1811
+ aux [] xs
1812
+
1797
1813
end
1798
1814
module Ast_comb : sig
1799
1815
#1 " ast_comb.mli"
@@ -4218,10 +4234,11 @@ type js_call = {
4218
4234
splice : bool ;
4219
4235
name : string ;
4220
4236
}
4221
-
4237
+ type pipe = bool
4222
4238
type js_send = {
4223
4239
splice : bool ;
4224
- name : string
4240
+ name : string ;
4241
+ pipe : pipe
4225
4242
} (* we know it is a js send, but what will happen if you pass an ocaml objct *)
4226
4243
4227
4244
type js_val = string external_module
@@ -4260,7 +4277,9 @@ type t =
4260
4277
4261
4278
4262
4279
4263
-
4280
+ (* *
4281
+ return value is of [pval_type, pval_prim]
4282
+ *)
4264
4283
val handle_attributes_as_string :
4265
4284
Bs_loc .t ->
4266
4285
string ->
@@ -4269,6 +4288,7 @@ val handle_attributes_as_string :
4269
4288
string ->
4270
4289
Ast_core_type .t * string list
4271
4290
4291
+
4272
4292
val bs_external : string
4273
4293
val to_string : t -> string
4274
4294
val from_string : string -> t
@@ -4313,15 +4333,16 @@ type 'a external_module = {
4313
4333
external_module_name : external_module_name option ;
4314
4334
}
4315
4335
4316
-
4336
+ type pipe = bool
4317
4337
type js_call = {
4318
4338
splice : bool ;
4319
4339
name : string ;
4320
4340
}
4321
4341
4322
4342
type js_send = {
4323
4343
splice : bool ;
4324
- name : string
4344
+ name : string ;
4345
+ pipe : bool
4325
4346
} (* we know it is a js send, but what will happen if you pass an ocaml objct *)
4326
4347
4327
4348
type js_val = string external_module
@@ -4345,6 +4366,8 @@ type ffi =
4345
4366
| Js_module_as_class of external_module_name
4346
4367
| Js_call of js_call external_module
4347
4368
| Js_send of js_send
4369
+ (* Note how we encode it will have a semantic difference
4370
+ *)
4348
4371
| Js_new of js_val
4349
4372
| Js_set of string
4350
4373
| Js_get of string
@@ -4460,7 +4483,8 @@ type st =
4460
4483
{ val_name : name_source ;
4461
4484
external_module_name : external_module_name option ;
4462
4485
module_as_val : external_module_name option ;
4463
- val_send : name_source ;
4486
+ val_send : name_source ;
4487
+ val_send_pipe : [`Nm_na | `Type of Ast_core_type .t ];
4464
4488
splice : bool ; (* mutable *)
4465
4489
set_index : bool ; (* mutable *)
4466
4490
get_index : bool ;
@@ -4478,6 +4502,7 @@ let init_st =
4478
4502
external_module_name = None ;
4479
4503
module_as_val = None ;
4480
4504
val_send = `Nm_na ;
4505
+ val_send_pipe = `Nm_na ;
4481
4506
splice = false ;
4482
4507
set_index = false ;
4483
4508
get_index = false ;
@@ -4516,7 +4541,8 @@ let handle_attributes
4516
4541
(loc : Bs_loc.t )
4517
4542
(pval_prim : string )
4518
4543
(type_annotation : Parsetree.core_type )
4519
- (prim_attributes : Ast_attributes.t ) (prim_name : string ) =
4544
+ (prim_attributes : Ast_attributes.t ) (prim_name : string )
4545
+ : Ast_core_type.t * string * t =
4520
4546
let prim_name_or_pval_prim =
4521
4547
if String. length prim_name = 0 then `Nm_val pval_prim
4522
4548
else `Nm_external prim_name (* need check name *)
@@ -4573,6 +4599,9 @@ let handle_attributes
4573
4599
| "bs.splice" -> {st with splice = true }
4574
4600
| "bs.send" ->
4575
4601
{ st with val_send = name_from_payload_or_prim payload}
4602
+ | " bs.send.pipe"
4603
+ ->
4604
+ { st with val_send_pipe = `Type (Ast_payload. as_core_type loc payload)}
4576
4605
| "bs.set" ->
4577
4606
{st with set_name = name_from_payload_or_prim payload}
4578
4607
| "bs.get" -> {st with get_name = name_from_payload_or_prim payload}
@@ -4591,12 +4620,15 @@ let handle_attributes
4591
4620
if Ast_core_type. is_array ty then Array
4592
4621
else if Ast_core_type. is_unit ty then Unit
4593
4622
else (Ast_core_type. string_type ty :> arg_type ) in
4623
+ let translate_arg_type =
4624
+ (fun (label , ty ) ->
4625
+ { arg_label = Ast_core_type. label_name label ;
4626
+ arg_type = aux ty
4627
+ }) in
4594
4628
let arg_types =
4595
- List. map (fun (label , ty ) ->
4596
- { arg_label = Ast_core_type. label_name label ;
4597
- arg_type = aux ty
4598
- }) arg_types_ty in
4599
- let result_type = aux result_type_ty in
4629
+ List. map translate_arg_type arg_types_ty in
4630
+ let result_type = aux result_type_ty in
4631
+ let object_type = ref None in
4600
4632
let ffi =
4601
4633
match st with
4602
4634
| {mk_obj = true ;
@@ -4605,12 +4637,13 @@ let handle_attributes
4605
4637
external_module_name = None ;
4606
4638
module_as_val = None ;
4607
4639
val_send = `Nm_na ;
4640
+ val_send_pipe = `Nm_na ;
4608
4641
splice = false ;
4609
4642
new_name = `Nm_na ;
4610
4643
call_name = `Nm_na ;
4611
4644
set_name = `Nm_na ;
4612
4645
get_name = `Nm_na ;
4613
- get_index = false ;
4646
+ get_index = false ;
4614
4647
} ->
4615
4648
let labels = List. map (function
4616
4649
| {arg_type = Unit ; arg_label = (Empty as l)}
@@ -4633,6 +4666,7 @@ let handle_attributes
4633
4666
external_module_name = None ;
4634
4667
module_as_val = None ;
4635
4668
val_send = `Nm_na ;
4669
+ val_send_pipe = `Nm_na ;
4636
4670
splice = false ;
4637
4671
get_index = false ;
4638
4672
new_name = `Nm_na ;
@@ -4661,6 +4695,8 @@ let handle_attributes
4661
4695
external_module_name = None ;
4662
4696
module_as_val = None ;
4663
4697
val_send = `Nm_na ;
4698
+ val_send_pipe = `Nm_na ;
4699
+
4664
4700
splice = false ;
4665
4701
new_name = `Nm_na ;
4666
4702
call_name = `Nm_na ;
@@ -4692,6 +4728,8 @@ let handle_attributes
4692
4728
*)
4693
4729
external_module_name = None ;
4694
4730
val_send = `Nm_na ;
4731
+ val_send_pipe = `Nm_na ;
4732
+
4695
4733
splice = false ;
4696
4734
call_name = `Nm_na ;
4697
4735
set_name = `Nm_na ;
@@ -4720,6 +4758,8 @@ let handle_attributes
4720
4758
val_name = `Nm_na ;
4721
4759
module_as_val = None ;
4722
4760
val_send = `Nm_na ;
4761
+ val_send_pipe = `Nm_na ;
4762
+
4723
4763
set_index = false ;
4724
4764
get_index = false ;
4725
4765
new_name = `Nm_na ;
@@ -4736,6 +4776,7 @@ let handle_attributes
4736
4776
call_name = `Nm_na ;
4737
4777
module_as_val = None ;
4738
4778
val_send = `Nm_na ;
4779
+ val_send_pipe = `Nm_na ;
4739
4780
set_index = false ;
4740
4781
get_index = false ;
4741
4782
new_name = `Nm_na ;
@@ -4754,6 +4795,7 @@ let handle_attributes
4754
4795
call_name = `Nm_na ;
4755
4796
module_as_val = None ;
4756
4797
val_send = `Nm_na ;
4798
+ val_send_pipe = `Nm_na ;
4757
4799
set_index = false ;
4758
4800
get_index = false ;
4759
4801
new_name = `Nm_na ;
@@ -4770,7 +4812,7 @@ let handle_attributes
4770
4812
4771
4813
| {val_send = (`Nm_val name | `Nm_external name | `Nm_payload name);
4772
4814
splice;
4773
-
4815
+ val_send_pipe = `Nm_na ;
4774
4816
val_name = `Nm_na ;
4775
4817
call_name = `Nm_na ;
4776
4818
module_as_val = None ;
@@ -4783,13 +4825,38 @@ let handle_attributes
4783
4825
} ->
4784
4826
begin match arg_types with
4785
4827
| _self :: _args ->
4786
- Js_send {splice ; name}
4828
+ Js_send {splice ; name; pipe = false }
4787
4829
| _ ->
4788
4830
Location. raise_errorf ~loc " Ill defined attribute [@@bs.send] (at least one argument)"
4789
4831
end
4790
4832
| {val_send = #bundle_source }
4791
4833
-> Location. raise_errorf ~loc " conflict attributes found"
4792
4834
4835
+ | {val_send_pipe = `Type typ;
4836
+ splice = (false as splice);
4837
+ val_send = `Nm_na ;
4838
+ val_name = `Nm_na ;
4839
+ call_name = `Nm_na ;
4840
+ module_as_val = None ;
4841
+ set_index = false ;
4842
+ get_index = false ;
4843
+ new_name = `Nm_na ;
4844
+ set_name = `Nm_na ;
4845
+ get_name = `Nm_na ;
4846
+ external_module_name = None ;
4847
+ } ->
4848
+ begin match arg_types with
4849
+ | _self :: _args ->
4850
+ object_type := Some typ ;
4851
+ Js_send {splice ;
4852
+ name = string_of_bundle_source prim_name_or_pval_prim;
4853
+ pipe = true }
4854
+ | _ ->
4855
+ Location. raise_errorf ~loc " Ill defined attribute [@@bs.send] (at least one argument)"
4856
+ end
4857
+ | {val_send_pipe = `Type _ }
4858
+ -> Location. raise_errorf ~loc " conflict attributes found"
4859
+
4793
4860
| {new_name = (`Nm_val name | `Nm_external name | `Nm_payload name);
4794
4861
external_module_name;
4795
4862
@@ -4799,6 +4866,7 @@ let handle_attributes
4799
4866
set_index = false ;
4800
4867
get_index = false ;
4801
4868
val_send = `Nm_na ;
4869
+ val_send_pipe = `Nm_na ;
4802
4870
set_name = `Nm_na ;
4803
4871
get_name = `Nm_na
4804
4872
}
@@ -4814,6 +4882,7 @@ let handle_attributes
4814
4882
set_index = false ;
4815
4883
get_index = false ;
4816
4884
val_send = `Nm_na ;
4885
+ val_send_pipe = `Nm_na ;
4817
4886
new_name = `Nm_na ;
4818
4887
get_name = `Nm_na ;
4819
4888
external_module_name = None
@@ -4835,6 +4904,7 @@ let handle_attributes
4835
4904
set_index = false ;
4836
4905
get_index = false ;
4837
4906
val_send = `Nm_na ;
4907
+ val_send_pipe = `Nm_na ;
4838
4908
new_name = `Nm_na ;
4839
4909
set_name = `Nm_na ;
4840
4910
external_module_name = None
@@ -4871,12 +4941,28 @@ let handle_attributes
4871
4941
end
4872
4942
| (_ , _ ), Ast_core_type. Empty -> acc
4873
4943
) arg_types_ty arg_labels [] ) in
4874
- Ast_core_type. replace_result type_annotation result
4875
- | _ , _ -> type_annotation) ,
4944
+ Ast_core_type. replace_result type_annotation result
4945
+ | Js_send {pipe = true } , _ ->
4946
+ begin match ! object_type with
4947
+ | Some obj ->
4948
+ Ast_core_type. replace_result type_annotation
4949
+ (Ast_helper.Typ. arrow ~loc " " obj result_type_ty)
4950
+ | None -> assert false
4951
+ end
4952
+ | _ , _ -> type_annotation
4953
+ ) ,
4954
+
4955
+ (* TODO: document *)
4876
4956
(match ffi , prim_name with
4877
- | Obj_create _ , _ -> prim_name
4878
- | _ , "" -> pval_prim
4879
- | _ , _ -> prim_name), Bs (arg_types, result_type, ffi)
4957
+ | Obj_create _ , _ -> prim_name
4958
+ | _ , "" -> pval_prim
4959
+ | _ , _ -> prim_name),
4960
+ (match ! object_type with
4961
+ | None ->
4962
+ Bs (arg_types, result_type, ffi)
4963
+ | Some obj ->
4964
+ Bs (arg_types @ [translate_arg_type (" " , obj) ], result_type, ffi)
4965
+ )
4880
4966
4881
4967
4882
4968
let handle_attributes_as_string
0 commit comments