442
442
(* External function calll *)
443
443
| Lapply (Lprim(Pfield n , [ Lprim(Pgetglobal id ,[] )]), args_lambda ,_info ) ->
444
444
445
- get_exp_with_args cxt lam args_lambda(* args_code *) id n env (* args *)
445
+ get_exp_with_args cxt lam args_lambda id n env
446
446
447
447
448
448
| Lapply (fn ,args_lambda , info ) ->
@@ -451,31 +451,31 @@ and
451
451
2. no need create names
452
452
*)
453
453
begin
454
- let [@ warning " -8" (* non-exhaustive pattern*) ] (args_code, fn_code::args) =
455
- (fn::args_lambda)
456
- |> List. map
457
- (
458
- fun (x : Lambda.lambda ) ->
459
- match x with
460
- | Lprim (Pgetglobal ident , [] ) ->
461
- (* when module is passed as an argument - unpack to an array
462
- for the function, generative module or functor can be a function,
463
- however it can not be global -- global can only module
464
- *)
465
- [] , Lam_compile_global. get_exp (ident, env,true )
466
- | _ ->
467
- begin
468
- match compile_lambda
469
- {cxt with st = NeedValue ; should_return = False } x with
470
- | {block = a ; value = Some b } -> a,b
471
- | _ -> assert false
472
- end )
473
- |> List. split in
454
+ let [@ warning " -8" (* non-exhaustive pattern*) ] (args_code, fn_code:: args) =
455
+ List. fold_right (fun (x : Lambda.lambda ) (args_code , fn_code )->
456
+ match x with
457
+ | Lprim (Pgetglobal ident , [] ) ->
458
+ (* when module is passed as an argument - unpack to an array
459
+ for the function, generative module or functor can be a function,
460
+ however it can not be global -- global can only module
461
+ *)
462
+ args_code, Lam_compile_global. get_exp (ident, env,true ) :: fn_code
463
+ | _ ->
464
+ begin
465
+ match compile_lambda
466
+ {cxt with st = NeedValue ; should_return = False } x with
467
+ | {block = a ; value = Some b } -> a @ args_code , b:: fn_code
468
+ | _ -> assert false
469
+ end
470
+ ) (fn::args_lambda) ([] ,[] ) in
471
+
472
+
474
473
begin
475
474
match fn, should_return with
476
475
| (Lvar id',
477
476
True (Some ({id;label; params; _} as ret))) when Ident. same id id' ->
478
477
478
+
479
479
(* Ext_log.err "@[ %s : %a tailcall @]@." cxt.meta.filename Ident.print id; *)
480
480
ret.triggered < - true ;
481
481
(* Here we mark [finished] true, since the continuation
492
492
493
493
*)
494
494
(* TODO: use [fold]*)
495
- let block = List. concat args_code @
495
+ let block = args_code @
496
496
(
497
497
let (_,assigned_params,new_params) =
498
498
List. fold_left2 (fun (i ,assigns ,new_params ) param (arg : J.expression ) ->
546
546
(* (E.call fn_code args) *)
547
547
| _ ->
548
548
549
- Js_output. handle_block_return st should_return lam ( List. concat args_code )
549
+ Js_output. handle_block_return st should_return lam args_code
550
550
(E. call ~info: (match fn, info with
551
551
| _ , { apply_status = Full } -> {arity = Full }
552
552
| _ , { apply_status = NA } -> {arity = NA } ) fn_code args)
0 commit comments