@@ -32,32 +32,46 @@ let handleExternalInSig
32
32
let loc = prim.pval_loc in
33
33
let pval_type = self.typ self prim.pval_type in
34
34
let pval_attributes = self.attributes self prim.pval_attributes in
35
- match prim.pval_prim with
36
- | [] ->
37
- Location. raise_errorf
38
- ~loc
39
- " empty primitive string"
40
- | a :: b :: _ ->
41
- Location. raise_errorf
42
- ~loc
43
- " only a single string is allowed in bs external %S %S" a b
44
- | [ v ] ->
45
- match Ast_external_process. handle_attributes_as_string
46
- loc
47
- pval_type
48
- pval_attributes
49
- prim.pval_name.txt
50
- v
51
- with
52
- | {pval_type; pval_prim; pval_attributes; no_inline_cross_module} ->
53
- {sigi with
54
- psig_desc =
55
- Psig_value
56
- {prim with
57
- pval_type ;
58
- pval_prim = if no_inline_cross_module then [] else pval_prim ;
59
- pval_attributes
60
- }}
35
+ match Ast_attributes. process_send_pipe pval_attributes with
36
+ | Some (obj , _ ) ->
37
+ (* has bs.send.pipe: best effort *)
38
+ begin {
39
+ sigi with
40
+ psig_desc = Psig_value {
41
+ prim with
42
+ pval_type = Ast_helper.Typ. arrow ~loc Nolabel obj pval_type ;
43
+ pval_prim = [] ;
44
+ pval_attributes = []
45
+ }
46
+ }
47
+ end
48
+ | None ->
49
+ match prim.pval_prim with
50
+ | [] ->
51
+ Location. raise_errorf
52
+ ~loc
53
+ " empty primitive string"
54
+ | a :: b :: _ ->
55
+ Location. raise_errorf
56
+ ~loc
57
+ " only a single string is allowed in bs external %S %S" a b
58
+ | [ v ] ->
59
+ match Ast_external_process. handle_attributes_as_string
60
+ loc
61
+ pval_type
62
+ pval_attributes
63
+ prim.pval_name.txt
64
+ v
65
+ with
66
+ | {pval_type; pval_prim; pval_attributes; no_inline_cross_module} ->
67
+ {sigi with
68
+ psig_desc =
69
+ Psig_value
70
+ {prim with
71
+ pval_type ;
72
+ pval_prim = if no_inline_cross_module then [] else pval_prim ;
73
+ pval_attributes
74
+ }}
61
75
62
76
let handleExternalInStru
63
77
(self : Bs_ast_mapper.mapper )
@@ -67,6 +81,13 @@ let handleExternalInStru
67
81
let loc = prim.pval_loc in
68
82
let pval_type = self.typ self prim.pval_type in
69
83
let pval_attributes = self.attributes self prim.pval_attributes in
84
+ let send_pipe = ref false in
85
+ let pval_type , pval_attributes =
86
+ match Ast_attributes. process_send_pipe pval_attributes with
87
+ | Some (obj , attrs ) ->
88
+ send_pipe := true ;
89
+ Ast_helper.Typ. arrow ~loc Nolabel obj pval_type, attrs
90
+ | None -> pval_type, pval_attributes in
70
91
match prim.pval_prim with
71
92
| []
72
93
->
@@ -95,6 +116,44 @@ let handleExternalInStru
95
116
pval_prim;
96
117
pval_attributes
97
118
}} in
119
+ if ! send_pipe then
120
+ let [@ warning " -8" ] ((_::params) as args) = Ast_core_type. get_curry_labels pval_type in
121
+ let arity = List. length args in
122
+ let open Ast_helper in
123
+ Str. include_ ~loc
124
+ (Incl. mk ~loc
125
+ (Mod. structure ~loc
126
+ [external_result;
127
+ Str. value
128
+ ~loc Nonrecursive [
129
+ Vb. mk ~loc
130
+ (Pat. var ~loc prim.pval_name)
131
+
132
+ (let body = (Exp. apply ~loc
133
+ (Exp. ident ~loc {txt = Lident prim.pval_name.txt; loc })
134
+ (Ext_list. mapi args (fun i x ->
135
+ match x with
136
+ | Asttypes. Nolabel ->
137
+ Asttypes. Nolabel , Exp. ident {txt = Lident (" arg" ^ string_of_int i); loc}
138
+ | Labelled s
139
+ | Optional s
140
+ ->
141
+ x, Exp. ident {txt = Lident s ; loc}
142
+ ))
143
+ ) in
144
+ snd @@
145
+ Ext_list. fold_right
146
+ params (0 , Exp. fun_ Nolabel None (Pat. var ~loc { txt = " arg0" ; loc} ) body) (
147
+ fun arg (i , obj ) ->
148
+ i + 1 , Exp. fun_ arg None
149
+ (Pat. var ~loc {txt = (match arg with | Labelled s | Optional s -> s
150
+ | Nolabel -> " arg" ^ string_of_int (arity - i - 1 )); loc}) obj
151
+ )
152
+ )
153
+ ]
154
+ ])
155
+ )
156
+ else
98
157
if not no_inline_cross_module then
99
158
external_result
100
159
else
0 commit comments