@@ -37,6 +37,16 @@ let change_tail_type_in_try
37
37
| Not_tail | Maybe_tail_is_return Tail_in_try
38
38
-> x
39
39
40
+ let change_tail_type_in_static
41
+ (x : Lam_compile_context.tail_type )
42
+ : Lam_compile_context.tail_type =
43
+ match x with
44
+ | Maybe_tail_is_return (Tail_with_name ({in_staticcatch =false } as z ) ) ->
45
+ Maybe_tail_is_return (Tail_with_name {z with in_staticcatch= true })
46
+ | Maybe_tail_is_return (Tail_with_name {in_staticcatch= true } )
47
+ | Not_tail | Maybe_tail_is_return Tail_in_try
48
+ -> x
49
+
40
50
(* assume outer is [Lstaticcatch] *)
41
51
let rec flat_catches
42
52
(acc : Lam_compile_context.handler list ) (x : Lam.t )
@@ -262,7 +272,7 @@ and compile_recursive_let ~all_bindings
262
272
let output =
263
273
compile_lambda
264
274
{ cxt with
265
- continuation = EffectCall (Maybe_tail_is_return (Tail_with_name ( Some ret ) ));
275
+ continuation = EffectCall (Maybe_tail_is_return (Tail_with_name {label = Some ret; in_staticcatch = false } ));
266
276
jmp_table = Lam_compile_context. empty_handler_map} body in
267
277
let result =
268
278
if ret.triggered then
@@ -640,13 +650,16 @@ and compile_stringswitch l cases default (lambda_cxt : Lam_compile_context.t) =
640
650
default: (exit 1))
641
651
with (1) 2))
642
652
*)
643
- and compile_staticraise i (largs : Lam.t list ) lambda_cxt =
653
+ and compile_staticraise i (largs : Lam.t list ) ( lambda_cxt : Lam_compile_context.t ) =
644
654
(* [i] is the jump table, [largs] is the arguments passed to [Lstaticcatch]*)
645
655
match Lam_compile_context. find_exn lambda_cxt i with
646
656
| {exit_id; bindings ; order_id} ->
647
657
Ext_list. fold_right2 largs bindings
648
- (Js_output. make [S. assign exit_id (E. small_int order_id)]
649
- ~value: E. undefined)
658
+ (
659
+ Js_output. make
660
+ (if order_id > = 0 then [S. assign exit_id (E. small_int order_id)]
661
+ else [] )
662
+ )
650
663
(fun larg bind acc ->
651
664
let new_output =
652
665
match larg with
@@ -695,6 +708,31 @@ and compile_staticraise i (largs : Lam.t list) lambda_cxt =
695
708
and compile_staticcatch (lam : Lam.t ) (lambda_cxt : Lam_compile_context.t )=
696
709
let code_table, body = flatten_nested_caches lam in
697
710
let exit_id = Ext_ident. create_tmp ~name: " exit" () in
711
+ match lambda_cxt.continuation, code_table with
712
+ | EffectCall (Maybe_tail_is_return (Tail_with_name ({in_staticcatch = false } as z))),
713
+ [ code_table ] (* tail position and only one exit code *)
714
+ ->
715
+ let jmp_table, handler =
716
+ Lam_compile_context. add_pseudo_jmp
717
+ lambda_cxt.jmp_table
718
+ exit_id code_table in
719
+ let new_cxt =
720
+ {lambda_cxt with
721
+ jmp_table = jmp_table ;
722
+ continuation =
723
+ EffectCall (Maybe_tail_is_return (Tail_with_name { z with in_staticcatch = true }))
724
+ } in
725
+
726
+ let lbody = compile_lambda new_cxt body in
727
+ let declares =
728
+ Ext_list. map code_table.bindings
729
+ (fun x -> S. declare_variable ~kind: Variable x) in
730
+ Js_output. append_output (Js_output. make declares)
731
+ (Js_output. append_output lbody
732
+ (compile_lambda lambda_cxt handler ))
733
+ | _ ->
734
+
735
+
698
736
let exit_expr = E. var exit_id in
699
737
let jmp_table, handlers =
700
738
Lam_compile_context. add_jmps lambda_cxt.jmp_table exit_id code_table in
@@ -1256,7 +1294,7 @@ and compile_apply
1256
1294
) in
1257
1295
match fn, lambda_cxt.continuation with
1258
1296
| (Lvar fn_id,
1259
- (EffectCall (Maybe_tail_is_return (Tail_with_name (Some ret))) | NeedValue (Maybe_tail_is_return (Tail_with_name (Some ret)))))
1297
+ (EffectCall (Maybe_tail_is_return (Tail_with_name ( {label = Some ret} ))) | NeedValue (Maybe_tail_is_return (Tail_with_name ( {label = Some ret} )))))
1260
1298
when Ident. same ret.id fn_id ->
1261
1299
ret.triggered < - true ;
1262
1300
(* Here we mark [finished] true, since the continuation
@@ -1439,7 +1477,7 @@ and compile_prim (prim_info : Lam.prim_info) (lambda_cxt : Lam_compile_context.t
1439
1477
*)
1440
1478
(Js_output. output_as_block
1441
1479
( compile_lambda
1442
- { lambda_cxt with continuation = EffectCall ( Maybe_tail_is_return (Tail_with_name None ));
1480
+ { lambda_cxt with continuation = EffectCall ( Maybe_tail_is_return (Tail_with_name {label = None ; in_staticcatch = false } ));
1443
1481
jmp_table = Lam_compile_context. empty_handler_map}
1444
1482
body)))
1445
1483
| _ -> assert false )
@@ -1492,7 +1530,7 @@ and compile_lambda
1492
1530
(Js_output. output_as_block
1493
1531
( compile_lambda
1494
1532
{ lambda_cxt with
1495
- continuation = EffectCall (Maybe_tail_is_return (Tail_with_name None ));
1533
+ continuation = EffectCall (Maybe_tail_is_return (Tail_with_name {label = None ; in_staticcatch = false } ));
1496
1534
jmp_table = Lam_compile_context. empty_handler_map}
1497
1535
body)))
1498
1536
| Lapply appinfo ->
0 commit comments