@@ -154,6 +154,16 @@ let default_action ~saturated failaction =
154
154
if saturated then Complete
155
155
else Default x
156
156
157
+ let get_const_name i (sw_names : Lambda.switch_names option ) =
158
+ match sw_names with
159
+ | None -> None
160
+ | Some {consts} -> Some consts.(i)
161
+
162
+ let get_block_name i (sw_names : Lambda.switch_names option ) =
163
+ match sw_names with
164
+ | None -> None
165
+ | Some {blocks} -> Some blocks.(i)
166
+
157
167
let no_effects_const = lazy true
158
168
(* let has_effects_const = lazy false *)
159
169
@@ -599,12 +609,8 @@ and compile_switch
599
609
default_action ~saturated: sw_consts_full sw_failaction in
600
610
let sw_blocks_default =
601
611
default_action ~saturated: sw_blocks_full sw_failaction in
602
-
603
- let get_name is_const i =
604
- match sw_names with
605
- | None -> None
606
- | Some {blocks; consts} ->
607
- Some (if is_const then consts.(i) else blocks.(i)) in
612
+ let get_const_name i = get_const_name i sw_names in
613
+ let get_block_name i = get_block_name i sw_names in
608
614
let compile_whole (cxt : Lam_compile_context.t ) =
609
615
match compile_lambda
610
616
{cxt with continuation = NeedValue Not_tail }
@@ -614,20 +620,20 @@ and compile_switch
614
620
| { block; value = Some e } ->
615
621
block @
616
622
(if sw_consts_full && sw_consts = [] then
617
- compile_cases cxt (E. tag e) sw_blocks sw_blocks_default (get_name false )
623
+ compile_cases cxt (E. tag e) sw_blocks sw_blocks_default get_block_name
618
624
else if sw_blocks_full && sw_blocks = [] then
619
- compile_cases cxt e sw_consts sw_num_default (get_name true )
625
+ compile_cases cxt e sw_consts sw_num_default get_const_name
620
626
else
621
627
(* [e] will be used twice *)
622
628
let dispatch e =
623
629
S. if_
624
630
(E. is_type_number e )
625
- (compile_cases cxt e sw_consts sw_num_default (get_name true )
631
+ (compile_cases cxt e sw_consts sw_num_default get_const_name
626
632
)
627
633
(* default still needed, could simplified*)
628
634
~else_:
629
635
(compile_cases cxt (E. tag e ) sw_blocks
630
- sw_blocks_default (get_name false ) ) in
636
+ sw_blocks_default get_block_name ) in
631
637
match e.expression_desc with
632
638
| J. Var _ -> [ dispatch e]
633
639
| _ ->
0 commit comments