1
- (* * Bundled by bspack 08/24-11:29 *)
1
+ (* * Bundled by bspack 08/24-16:25 *)
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 [
@@ -4218,10 +4224,11 @@ type js_call = {
4218
4224
splice : bool ;
4219
4225
name : string ;
4220
4226
}
4221
-
4227
+ type pipe = bool
4222
4228
type js_send = {
4223
4229
splice : bool ;
4224
- name : string
4230
+ name : string ;
4231
+ pipe : pipe
4225
4232
} (* we know it is a js send, but what will happen if you pass an ocaml objct *)
4226
4233
4227
4234
type js_val = string external_module
@@ -4313,15 +4320,16 @@ type 'a external_module = {
4313
4320
external_module_name : external_module_name option ;
4314
4321
}
4315
4322
4316
-
4323
+ type pipe = bool
4317
4324
type js_call = {
4318
4325
splice : bool ;
4319
4326
name : string ;
4320
4327
}
4321
4328
4322
4329
type js_send = {
4323
4330
splice : bool ;
4324
- name : string
4331
+ name : string ;
4332
+ pipe : bool
4325
4333
} (* we know it is a js send, but what will happen if you pass an ocaml objct *)
4326
4334
4327
4335
type js_val = string external_module
@@ -4345,6 +4353,8 @@ type ffi =
4345
4353
| Js_module_as_class of external_module_name
4346
4354
| Js_call of js_call external_module
4347
4355
| Js_send of js_send
4356
+ (* Note how we encode it will have a semantic difference
4357
+ *)
4348
4358
| Js_new of js_val
4349
4359
| Js_set of string
4350
4360
| Js_get of string
@@ -4460,7 +4470,8 @@ type st =
4460
4470
{ val_name : name_source ;
4461
4471
external_module_name : external_module_name option ;
4462
4472
module_as_val : external_module_name option ;
4463
- val_send : name_source ;
4473
+ val_send : name_source ;
4474
+ val_send_pipe : [`Nm_na | `Type of Ast_core_type .t ];
4464
4475
splice : bool ; (* mutable *)
4465
4476
set_index : bool ; (* mutable *)
4466
4477
get_index : bool ;
@@ -4478,6 +4489,7 @@ let init_st =
4478
4489
external_module_name = None ;
4479
4490
module_as_val = None ;
4480
4491
val_send = `Nm_na ;
4492
+ val_send_pipe = `Nm_na ;
4481
4493
splice = false ;
4482
4494
set_index = false ;
4483
4495
get_index = false ;
@@ -4516,7 +4528,8 @@ let handle_attributes
4516
4528
(loc : Bs_loc.t )
4517
4529
(pval_prim : string )
4518
4530
(type_annotation : Parsetree.core_type )
4519
- (prim_attributes : Ast_attributes.t ) (prim_name : string ) =
4531
+ (prim_attributes : Ast_attributes.t ) (prim_name : string )
4532
+ : Ast_core_type.t * string * t =
4520
4533
let prim_name_or_pval_prim =
4521
4534
if String. length prim_name = 0 then `Nm_val pval_prim
4522
4535
else `Nm_external prim_name (* need check name *)
@@ -4573,6 +4586,9 @@ let handle_attributes
4573
4586
| "bs.splice" -> {st with splice = true }
4574
4587
| "bs.send" ->
4575
4588
{ st with val_send = name_from_payload_or_prim payload}
4589
+ | " bs.send.pipe"
4590
+ ->
4591
+ { st with val_send_pipe = `Type (Ast_payload. as_core_type loc payload)}
4576
4592
| "bs.set" ->
4577
4593
{st with set_name = name_from_payload_or_prim payload}
4578
4594
| "bs.get" -> {st with get_name = name_from_payload_or_prim payload}
@@ -4591,12 +4607,15 @@ let handle_attributes
4591
4607
if Ast_core_type. is_array ty then Array
4592
4608
else if Ast_core_type. is_unit ty then Unit
4593
4609
else (Ast_core_type. string_type ty :> arg_type ) in
4610
+ let translate_arg_type =
4611
+ (fun (label , ty ) ->
4612
+ { arg_label = Ast_core_type. label_name label ;
4613
+ arg_type = aux ty
4614
+ }) in
4594
4615
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
4616
+ List. map translate_arg_type arg_types_ty in
4617
+ let result_type = aux result_type_ty in
4618
+ let object_type = ref None in
4600
4619
let ffi =
4601
4620
match st with
4602
4621
| {mk_obj = true ;
@@ -4605,12 +4624,13 @@ let handle_attributes
4605
4624
external_module_name = None ;
4606
4625
module_as_val = None ;
4607
4626
val_send = `Nm_na ;
4627
+ val_send_pipe = `Nm_na ;
4608
4628
splice = false ;
4609
4629
new_name = `Nm_na ;
4610
4630
call_name = `Nm_na ;
4611
4631
set_name = `Nm_na ;
4612
4632
get_name = `Nm_na ;
4613
- get_index = false ;
4633
+ get_index = false ;
4614
4634
} ->
4615
4635
let labels = List. map (function
4616
4636
| {arg_type = Unit ; arg_label = (Empty as l)}
@@ -4633,6 +4653,7 @@ let handle_attributes
4633
4653
external_module_name = None ;
4634
4654
module_as_val = None ;
4635
4655
val_send = `Nm_na ;
4656
+ val_send_pipe = `Nm_na ;
4636
4657
splice = false ;
4637
4658
get_index = false ;
4638
4659
new_name = `Nm_na ;
@@ -4661,6 +4682,8 @@ let handle_attributes
4661
4682
external_module_name = None ;
4662
4683
module_as_val = None ;
4663
4684
val_send = `Nm_na ;
4685
+ val_send_pipe = `Nm_na ;
4686
+
4664
4687
splice = false ;
4665
4688
new_name = `Nm_na ;
4666
4689
call_name = `Nm_na ;
@@ -4692,6 +4715,8 @@ let handle_attributes
4692
4715
*)
4693
4716
external_module_name = None ;
4694
4717
val_send = `Nm_na ;
4718
+ val_send_pipe = `Nm_na ;
4719
+
4695
4720
splice = false ;
4696
4721
call_name = `Nm_na ;
4697
4722
set_name = `Nm_na ;
@@ -4720,6 +4745,8 @@ let handle_attributes
4720
4745
val_name = `Nm_na ;
4721
4746
module_as_val = None ;
4722
4747
val_send = `Nm_na ;
4748
+ val_send_pipe = `Nm_na ;
4749
+
4723
4750
set_index = false ;
4724
4751
get_index = false ;
4725
4752
new_name = `Nm_na ;
@@ -4736,6 +4763,7 @@ let handle_attributes
4736
4763
call_name = `Nm_na ;
4737
4764
module_as_val = None ;
4738
4765
val_send = `Nm_na ;
4766
+ val_send_pipe = `Nm_na ;
4739
4767
set_index = false ;
4740
4768
get_index = false ;
4741
4769
new_name = `Nm_na ;
@@ -4754,6 +4782,7 @@ let handle_attributes
4754
4782
call_name = `Nm_na ;
4755
4783
module_as_val = None ;
4756
4784
val_send = `Nm_na ;
4785
+ val_send_pipe = `Nm_na ;
4757
4786
set_index = false ;
4758
4787
get_index = false ;
4759
4788
new_name = `Nm_na ;
@@ -4770,7 +4799,7 @@ let handle_attributes
4770
4799
4771
4800
| {val_send = (`Nm_val name | `Nm_external name | `Nm_payload name);
4772
4801
splice;
4773
-
4802
+ val_send_pipe = `Nm_na ;
4774
4803
val_name = `Nm_na ;
4775
4804
call_name = `Nm_na ;
4776
4805
module_as_val = None ;
@@ -4783,13 +4812,38 @@ let handle_attributes
4783
4812
} ->
4784
4813
begin match arg_types with
4785
4814
| _self :: _args ->
4786
- Js_send {splice ; name}
4815
+ Js_send {splice ; name; pipe = false }
4787
4816
| _ ->
4788
4817
Location. raise_errorf ~loc " Ill defined attribute [@@bs.send] (at least one argument)"
4789
4818
end
4790
4819
| {val_send = #bundle_source }
4791
4820
-> Location. raise_errorf ~loc " conflict attributes found"
4792
4821
4822
+ | {val_send_pipe = `Type typ;
4823
+ splice = (false as splice);
4824
+ val_send = `Nm_na ;
4825
+ val_name = `Nm_na ;
4826
+ call_name = `Nm_na ;
4827
+ module_as_val = None ;
4828
+ set_index = false ;
4829
+ get_index = false ;
4830
+ new_name = `Nm_na ;
4831
+ set_name = `Nm_na ;
4832
+ get_name = `Nm_na ;
4833
+ external_module_name = None ;
4834
+ } ->
4835
+ begin match arg_types with
4836
+ | _self :: _args ->
4837
+ object_type := Some typ ;
4838
+ Js_send {splice ;
4839
+ name = string_of_bundle_source prim_name_or_pval_prim;
4840
+ pipe = true }
4841
+ | _ ->
4842
+ Location. raise_errorf ~loc " Ill defined attribute [@@bs.send] (at least one argument)"
4843
+ end
4844
+ | {val_send_pipe = `Type _ }
4845
+ -> Location. raise_errorf ~loc " conflict attributes found"
4846
+
4793
4847
| {new_name = (`Nm_val name | `Nm_external name | `Nm_payload name);
4794
4848
external_module_name;
4795
4849
@@ -4799,6 +4853,7 @@ let handle_attributes
4799
4853
set_index = false ;
4800
4854
get_index = false ;
4801
4855
val_send = `Nm_na ;
4856
+ val_send_pipe = `Nm_na ;
4802
4857
set_name = `Nm_na ;
4803
4858
get_name = `Nm_na
4804
4859
}
@@ -4814,6 +4869,7 @@ let handle_attributes
4814
4869
set_index = false ;
4815
4870
get_index = false ;
4816
4871
val_send = `Nm_na ;
4872
+ val_send_pipe = `Nm_na ;
4817
4873
new_name = `Nm_na ;
4818
4874
get_name = `Nm_na ;
4819
4875
external_module_name = None
@@ -4835,6 +4891,7 @@ let handle_attributes
4835
4891
set_index = false ;
4836
4892
get_index = false ;
4837
4893
val_send = `Nm_na ;
4894
+ val_send_pipe = `Nm_na ;
4838
4895
new_name = `Nm_na ;
4839
4896
set_name = `Nm_na ;
4840
4897
external_module_name = None
@@ -4871,12 +4928,28 @@ let handle_attributes
4871
4928
end
4872
4929
| (_ , _ ), Ast_core_type. Empty -> acc
4873
4930
) arg_types_ty arg_labels [] ) in
4874
- Ast_core_type. replace_result type_annotation result
4875
- | _ , _ -> type_annotation) ,
4931
+ Ast_core_type. replace_result type_annotation result
4932
+ | Js_send {pipe = true } , _ ->
4933
+ begin match ! object_type with
4934
+ | Some obj ->
4935
+ Ast_core_type. replace_result type_annotation
4936
+ (Ast_helper.Typ. arrow ~loc " " obj result_type_ty)
4937
+ | None -> assert false
4938
+ end
4939
+ | _ , _ -> type_annotation
4940
+ ) ,
4941
+
4942
+ (* TODO: document *)
4876
4943
(match ffi , prim_name with
4877
- | Obj_create _ , _ -> prim_name
4878
- | _ , "" -> pval_prim
4879
- | _ , _ -> prim_name), Bs (arg_types, result_type, ffi)
4944
+ | Obj_create _ , _ -> prim_name
4945
+ | _ , "" -> pval_prim
4946
+ | _ , _ -> prim_name),
4947
+ (match ! object_type with
4948
+ | None ->
4949
+ Bs (arg_types, result_type, ffi)
4950
+ | Some obj ->
4951
+ Bs (arg_types @ [translate_arg_type (" " , obj) ], result_type, ffi)
4952
+ )
4880
4953
4881
4954
4882
4955
let handle_attributes_as_string
0 commit comments