@@ -30,6 +30,10 @@ let splice_fn_apply fn args =
3030 E. runtime_call Js_runtime_modules. caml_splice_call " spliceApply"
3131 [ fn; E. array Immutable args ]
3232
33+ let splice_fn_new_apply fn args =
34+ E. runtime_call Js_runtime_modules. caml_splice_call " spliceNewApply"
35+ [ fn; E. array Immutable args ]
36+
3337let splice_obj_fn_apply obj name args =
3438 E. runtime_call Js_runtime_modules. caml_splice_call " spliceObjApply"
3539 [ obj; E. str name; E. array Immutable args ]
@@ -271,7 +275,7 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
271275 let args, eff = assemble_args_no_splice arg_types args in
272276 (* TODO: fix in rest calling convention *)
273277 add_eff eff (E. call ~info: { arity = Full ; call_info = Call_na } fn args)
274- | Js_new { external_module_name = module_name ; name = fn ; scopes } ->
278+ | Js_new { external_module_name = module_name ; name = fn ; splice; scopes } ->
275279 (* handle [@@new]*)
276280 (* This has some side effect, it will
277281 mark its identifier (If it has) as an object,
@@ -281,15 +285,24 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
281285 TODO: we should propagate this property
282286 as much as we can(in alias table)
283287 *)
284- let args, eff = assemble_args_no_splice arg_types args in
285- let fn = translate_scoped_module_val module_name fn scopes in
286- add_eff eff
287- ((match cxt.continuation with
288+ let mark () =
289+ match cxt.continuation with
288290 | Declare (_ , id ) | Assign id ->
289291 (* Format.fprintf Format.err_formatter "%a@."Ident.print id; *)
290292 Ext_ident. make_js_object id
291- | EffectCall _ | NeedValue _ -> () );
292- E. new_ fn args)
293+ | EffectCall _ | NeedValue _ -> ()
294+ in
295+ let fn = translate_scoped_module_val module_name fn scopes in
296+ if splice then
297+ let args, eff, dynamic = assemble_args_has_splice arg_types args in
298+ add_eff eff
299+ (mark () ;
300+ if dynamic then splice_fn_new_apply fn args
301+ else E. new_ fn args)
302+ else
303+ let args, eff = assemble_args_no_splice arg_types args in
304+ add_eff eff
305+ (mark () ; E. new_ fn args)
293306 | Js_send { splice; name; js_send_scopes } -> (
294307 match args with
295308 | self :: args ->
0 commit comments