Skip to content

Commit aed245e

Browse files
committed
Compiler: refactor compile_block
1 parent 7c3ee56 commit aed245e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

compiler/lib/generate.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,14 +1437,15 @@ and compile_block st queue (pc : Addr.t) frontier interm =
14371437
assert (Addr.Set.cardinal handler_frontier_cont <= 1);
14381438
let try_catch_frontier = Addr.Set.union new_frontier handler_frontier_cont in
14391439
if debug () then Format.eprintf "@[<2>try {@,";
1440+
if Addr.Map.mem pc1 handler_interm then decr_preds st pc1;
14401441
let body =
14411442
prefix
14421443
@ compile_branch
14431444
st
14441445
[]
14451446
(pc1, args1)
14461447
None
1447-
Addr.Set.empty
1448+
backs
14481449
try_catch_frontier
14491450
handler_interm
14501451
in
@@ -1454,7 +1455,10 @@ and compile_block st queue (pc : Addr.t) frontier interm =
14541455
let m = Subst.build_mapping args2 block2.params in
14551456
try Var.Map.find x m with Not_found -> x
14561457
in
1457-
let handler = compile_block st [] pc2 try_catch_frontier handler_interm in
1458+
if Addr.Map.mem pc2 handler_interm then decr_preds st pc2;
1459+
let handler =
1460+
compile_branch st [] (pc2, args2) None backs try_catch_frontier handler_interm
1461+
in
14581462
if debug () then Format.eprintf "}@]@ ";
14591463
Addr.Set.iter (decr_preds st) handler_frontier;
14601464

@@ -1528,6 +1532,8 @@ and compile_block st queue (pc : Addr.t) frontier interm =
15281532
colapse_frontier st new_frontier interm
15291533
in
15301534
assert (Addr.Set.cardinal frontier_cont <= 1);
1535+
List.iter succs ~f:(fun (pc, _) ->
1536+
if Addr.Map.mem pc new_interm then decr_preds st pc);
15311537
(* Beware evaluation order! *)
15321538
let cond =
15331539
compile_conditional
@@ -1616,7 +1622,7 @@ and colapse_frontier st new_frontier interm =
16161622
of the frontier. *)
16171623
Addr.Set.iter (fun pc -> incr_preds st pc) new_frontier;
16181624
(* Put a limit: we are going to remove other branches
1619-
to the members of the frontier (in compile_conditional),
1625+
to the members of the frontier (in compile_block),
16201626
but they should remain in the frontier. *)
16211627
Addr.Set.iter (fun pc -> protect_preds st pc) new_frontier;
16221628
Hashtbl.add st.succs idx (Addr.Set.elements new_frontier);
@@ -1695,7 +1701,6 @@ and compile_decision_tree st _queue handler backs frontier interm succs loc cx d
16951701
binds @ snd (loop cx dtree)
16961702

16971703
and compile_conditional st queue pc last handler backs frontier interm succs =
1698-
List.iter succs ~f:(fun (pc, _) -> if Addr.Map.mem pc interm then decr_preds st pc);
16991704
(if debug ()
17001705
then
17011706
match last with

0 commit comments

Comments
 (0)