@@ -29,7 +29,7 @@ type module_bind_name =
29
29
| Phint_nothing
30
30
31
31
32
- type external_module_name = {
32
+ type external_module_name = {
33
33
bundle : string ;
34
34
module_bind_name : module_bind_name
35
35
}
@@ -51,7 +51,7 @@ type external_spec =
51
51
scopes : string list
52
52
}
53
53
| Js_module_as_var of external_module_name
54
- | Js_module_as_fn of {
54
+ | Js_module_as_fn of {
55
55
external_module_name : external_module_name ;
56
56
splice : bool
57
57
}
@@ -72,13 +72,14 @@ type external_spec =
72
72
| Js_new of {
73
73
name : string ;
74
74
external_module_name : external_module_name option ;
75
+ splice : bool ;
75
76
scopes : string list ;
76
77
}
77
- | Js_set of {
78
+ | Js_set of {
78
79
js_set_name : string ;
79
80
js_set_scopes : string list
80
81
}
81
- | Js_get of {
82
+ | Js_get of {
82
83
js_get_name : string ;
83
84
js_get_scopes : string list ;
84
85
}
@@ -119,9 +120,9 @@ type return_wrapper =
119
120
| Return_null_undefined_to_opt
120
121
| Return_replaced_with_unit
121
122
122
- type params =
123
+ type params =
123
124
| Params of External_arg_spec .params
124
- | Param_number of int
125
+ | Param_number of int
125
126
126
127
type t =
127
128
| Ffi_bs of params *
@@ -166,7 +167,7 @@ let valid_ident (s : string) =
166
167
true
167
168
with E -> false )
168
169
169
- let is_package_relative_path (x : string ) =
170
+ let is_package_relative_path (x : string ) =
170
171
Ext_string. starts_with x " ./" ||
171
172
Ext_string. starts_with x " ../"
172
173
@@ -177,7 +178,7 @@ let valid_global_name ?loc txt =
177
178
(fun s ->
178
179
if not (valid_ident s) then
179
180
Location. raise_errorf ?loc " Not a valid global name %s" txt
180
- )
181
+ )
181
182
182
183
(*
183
184
We loose such check (see #2583),
@@ -200,14 +201,14 @@ let check_external_module_name ?loc x =
200
201
201
202
202
203
203
- let check_ffi ?loc ffi : bool =
204
- let xrelative = ref false in
205
- let upgrade bool =
206
- if not (! xrelative) then xrelative := bool in
204
+ let check_ffi ?loc ffi : bool =
205
+ let xrelative = ref false in
206
+ let upgrade bool =
207
+ if not (! xrelative) then xrelative := bool in
207
208
begin match ffi with
208
- | Js_var {name; external_module_name; scopes = _ } ->
209
+ | Js_var {name; external_module_name; scopes = _ } ->
209
210
upgrade (is_package_relative_path name);
210
- Ext_option. iter external_module_name (fun name ->
211
+ Ext_option. iter external_module_name (fun name ->
211
212
upgrade (is_package_relative_path name.bundle));
212
213
valid_global_name ?loc name
213
214
| Js_send {name ; splice = _; js_send_scopes = _}
@@ -221,10 +222,10 @@ let check_ffi ?loc ffi : bool =
221
222
| Js_module_as_var external_module_name
222
223
| Js_module_as_fn {external_module_name; splice = _}
223
224
| Js_module_as_class external_module_name
224
- ->
225
+ ->
225
226
upgrade (is_package_relative_path external_module_name.bundle);
226
227
check_external_module_name external_module_name
227
- | Js_new {external_module_name ; name; scopes = _}
228
+ | Js_new {external_module_name ; name; splice = _; scopes = _}
228
229
| Js_call {external_module_name ; name ; splice = _; scopes = _ }
229
230
->
230
231
Ext_option. iter external_module_name (fun external_module_name ->
@@ -233,8 +234,8 @@ let check_ffi ?loc ffi : bool =
233
234
check_external_module_name ?loc name
234
235
);
235
236
236
- valid_global_name ?loc name
237
- end ;
237
+ valid_global_name ?loc name
238
+ end ;
238
239
! xrelative
239
240
240
241
(* let bs_prefix = "BS:"
@@ -255,119 +256,119 @@ let check_ffi ?loc ffi : bool =
255
256
let to_string (t : t ) =
256
257
Marshal. to_string t []
257
258
258
- (* \132\149\166\190
259
+ (* \132\149\166\190
259
260
0x84 95 A6 BE Intext_magic_small intext.h
260
261
https://github.com/ocaml/merlin/commit/b094c937c3a360eb61054f7652081b88e4f3612f
261
262
*)
262
- let is_bs_primitive s =
263
+ let is_bs_primitive s =
263
264
String. length s > = 20 (* Marshal.header_size*) &&
264
265
String. unsafe_get s 0 = '\132' &&
265
- String. unsafe_get s 1 = '\149'
266
+ String. unsafe_get s 1 = '\149'
266
267
267
- let () = Oprint. map_primitive_name :=
268
+ let () = Oprint. map_primitive_name :=
268
269
269
- # 272 " frontend/external_ffi_types.pp.ml"
270
+ # 273 " frontend/external_ffi_types.pp.ml"
270
271
String. escaped
271
272
272
- # 275 " frontend/external_ffi_types.pp.ml"
273
+ # 276 " frontend/external_ffi_types.pp.ml"
273
274
(* TODO: better error message when version mismatch *)
274
275
let from_string s : t =
275
- if is_bs_primitive s then
276
+ if is_bs_primitive s then
276
277
Ext_marshal. from_string s
277
278
else Ffi_normal
278
279
279
- let () =
280
- Primitive. coerce :=
281
- (fun
282
- ({prim_name; prim_arity; prim_native_name;
283
- prim_alloc = _ ;
284
- prim_native_repr_args = _ ;
285
- prim_native_repr_res = _ } : Primitive. description )
286
- (p2 : Primitive.description ) ->
287
- let p2_native = p2.prim_native_name in
288
- prim_name = p2.prim_name &&
280
+ let () =
281
+ Primitive. coerce :=
282
+ (fun
283
+ ({prim_name; prim_arity; prim_native_name;
284
+ prim_alloc = _ ;
285
+ prim_native_repr_args = _ ;
286
+ prim_native_repr_res = _ } : Primitive. description )
287
+ (p2 : Primitive.description ) ->
288
+ let p2_native = p2.prim_native_name in
289
+ prim_name = p2.prim_name &&
289
290
prim_arity = p2.prim_arity &&
290
291
prim_native_name = p2_native || (
291
- match from_string prim_native_name, from_string p2_native with
292
- | Ffi_obj_create obj_parms , Ffi_obj_create obj_parms2 ->
293
- Ext_list. for_all2_no_exn obj_parms obj_parms2 (fun {obj_arg_type; obj_arg_label} b ->
294
- let b_obj_arg_label = b.obj_arg_label in
292
+ match from_string prim_native_name, from_string p2_native with
293
+ | Ffi_obj_create obj_parms , Ffi_obj_create obj_parms2 ->
294
+ Ext_list. for_all2_no_exn obj_parms obj_parms2 (fun {obj_arg_type; obj_arg_label} b ->
295
+ let b_obj_arg_label = b.obj_arg_label in
295
296
obj_arg_type = b.obj_arg_type &&
296
297
(obj_arg_label = b_obj_arg_label ||
297
- match obj_arg_label, b_obj_arg_label with
298
+ match obj_arg_label, b_obj_arg_label with
298
299
| Obj_optional {name; for_sure_no_nested_option}, Obj_optional p
299
- ->
300
+ ->
300
301
name = p.name &&
301
302
((Obj. magic for_sure_no_nested_option : int ) < = (Obj. magic p.for_sure_no_nested_option))
302
- | _ -> false
303
+ | _ -> false
303
304
)
304
305
)
305
- | Ffi_bs _ , Ffi_bs _ -> false
306
- | _ -> false
306
+ | Ffi_bs _ , Ffi_bs _ -> false
307
+ | _ -> false
307
308
)
308
309
)
309
- let inline_string_primitive (s : string ) (op : string option ) : string list =
310
- let lam : Lam_constant.t =
311
- match op with
310
+ let inline_string_primitive (s : string ) (op : string option ) : string list =
311
+ let lam : Lam_constant.t =
312
+ match op with
312
313
| Some op
313
314
when Ast_utf8_string_interp. is_unicode_string op ->
314
315
Const_unicode s
315
316
| _ ->
316
- (Const_string s) in
317
+ (Const_string s) in
317
318
[" " ; to_string (Ffi_inline_const lam )]
318
319
319
320
(* Let's only do it for string ATM
320
- for boolean, and ints, a good optimizer should
321
+ for boolean, and ints, a good optimizer should
321
322
do it by default?
322
323
But it may not work after layers of indirection
323
324
e.g, submodule
324
325
*)
325
- let inline_bool_primitive b : string list =
326
- let lam : Lam_constant.t =
327
- if b then Lam_constant. Const_js_true
326
+ let inline_bool_primitive b : string list =
327
+ let lam : Lam_constant.t =
328
+ if b then Lam_constant. Const_js_true
328
329
else Lam_constant. Const_js_false
329
- in
330
+ in
330
331
[" " ; to_string (Ffi_inline_const lam )]
331
332
332
333
(* FIXME: check overflow ?*)
333
- let inline_int_primitive (i : int32 ) : string list =
334
- [" " ;
335
- to_string
336
- (Ffi_inline_const
334
+ let inline_int_primitive (i : int32 ) : string list =
335
+ [" " ;
336
+ to_string
337
+ (Ffi_inline_const
337
338
(Const_int {i; comment = None }))
338
339
]
339
340
340
- let inline_int64_primitive (i : int64 ) : string list =
341
- [" " ;
342
- to_string
343
- (Ffi_inline_const
341
+ let inline_int64_primitive (i : int64 ) : string list =
342
+ [" " ;
343
+ to_string
344
+ (Ffi_inline_const
344
345
(Const_int64 i))
345
346
]
346
347
347
348
let inline_float_primitive (i : string ) : string list =
348
349
[" " ;
349
- to_string
350
+ to_string
350
351
(Ffi_inline_const (Const_float i))
351
- ]
352
- let rec ffi_bs_aux acc (params : External_arg_spec.params ) =
353
- match params with
354
- | {arg_type = Nothing ; arg_label = Arg_empty }
352
+ ]
353
+ let rec ffi_bs_aux acc (params : External_arg_spec.params ) =
354
+ match params with
355
+ | {arg_type = Nothing ; arg_label = Arg_empty }
355
356
(* same as External_arg_spec.dummy*)
356
- :: rest ->
357
- ffi_bs_aux (acc + 1 ) rest
358
- | _ :: _ -> - 1
359
- | [] -> acc
357
+ :: rest ->
358
+ ffi_bs_aux (acc + 1 ) rest
359
+ | _ :: _ -> - 1
360
+ | [] -> acc
360
361
361
362
let ffi_bs (params : External_arg_spec.params ) return attr =
362
- let n = ffi_bs_aux 0 params in
363
- if n < 0 then Ffi_bs (Params params,return,attr)
364
- else Ffi_bs (Param_number n, return, attr)
363
+ let n = ffi_bs_aux 0 params in
364
+ if n < 0 then Ffi_bs (Params params,return,attr)
365
+ else Ffi_bs (Param_number n, return, attr)
365
366
366
- let ffi_bs_as_prims params return attr =
367
+ let ffi_bs_as_prims params return attr =
367
368
[" " ; to_string (ffi_bs params return attr)]
368
369
369
370
let ffi_obj_create obj_params =
370
371
Ffi_obj_create obj_params
371
372
372
- let ffi_obj_as_prims obj_params =
373
+ let ffi_obj_as_prims obj_params =
373
374
[" " ;to_string (Ffi_obj_create obj_params)]
0 commit comments