@@ -673,8 +673,6 @@ let compile output_prefix =
673
673
also if last statement is throw -- should we drop remaining
674
674
statement?
675
675
*)
676
- (* Printf.eprintf "XXX switch_arg: %s\n\n"
677
- (Lam_print.lambda_to_string switch_arg); *)
678
676
let ({
679
677
sw_consts_full;
680
678
sw_consts;
@@ -715,55 +713,42 @@ let compile output_prefix =
715
713
block
716
714
@
717
715
if sw_consts_full && sw_consts = [] then
718
- (* let _ = Printf.eprintf "QQQ sw_consts_full\n\n" in *)
719
716
compile_cases ~block_cases ~untagged ~cxt
720
717
~switch_exp: (if untagged then e else E. tag ~name: tag_name e)
721
718
~default: sw_blocks_default ~get_tag: get_block_tag sw_blocks
722
719
else if sw_blocks_full && sw_blocks = [] then
723
- (* let _ = Printf.eprintf "QQQ sw_blocks_full\n\n" in *)
724
720
compile_cases ~cxt ~switch_exp: e ~block_cases ~default: sw_num_default
725
721
~get_tag: get_const_tag sw_consts
726
722
else
727
- (* let _ = Printf.eprintf "QQQ else\n\n" in *)
728
723
(* [e] will be used twice *)
729
724
let dispatch e =
730
725
let is_a_literal_case =
731
726
if untagged then
732
- let literal_case =
733
- E. is_a_literal_case
734
- ~literal_cases: (get_literal_cases sw_names)
735
- ~block_cases e
736
- in
737
- (* Printf.eprintf "LLL literal_case: %s\n\n"
738
- (Js_dump.string_of_expression literal_case); *)
739
- literal_case
727
+ E. is_a_literal_case
728
+ ~literal_cases: (get_literal_cases sw_names)
729
+ ~block_cases e
740
730
else
741
731
E. is_int_tag
742
732
~has_null_undefined_other: (has_null_undefined_other sw_names)
743
733
e
744
734
in
745
- let qconsts =
746
- use_compile_literal_cases sw_consts ~get_tag: get_const_tag
747
- in
748
- let qblocks =
749
- use_compile_literal_cases sw_blocks ~get_tag: get_block_tag
750
- in
751
735
let eq_default d1 d2 =
752
736
match (d1, d2) with
753
737
| Default lam1 , Default lam2 -> Lam. eq_approx lam1 lam2
754
738
| Complete , Complete -> true
755
739
| NonComplete , NonComplete -> true
756
740
| _ -> false
757
741
in
758
- match (qconsts, qblocks) with
759
- | Some consts_cases, Some blocks_cases
760
- when untagged
761
- && List. length blocks_cases > = 1
762
- && List. length consts_cases = 0
763
- && eq_default sw_num_default sw_blocks_default ->
764
- compile_cases ~untagged ~cxt ~switch_exp: e ~block_cases
765
- ~default: sw_blocks_default ~get_tag: get_block_tag sw_blocks
766
- | _ ->
742
+ if
743
+ untagged
744
+ && List. length sw_consts = 0
745
+ && eq_default sw_num_default sw_blocks_default
746
+ then
747
+ compile_cases ~untagged ~cxt
748
+ ~switch_exp: (if untagged then e else E. tag ~name: tag_name e)
749
+ ~block_cases ~default: sw_blocks_default ~get_tag: get_block_tag
750
+ sw_blocks
751
+ else
767
752
[
768
753
S. if_ is_a_literal_case
769
754
(compile_cases ~cxt ~switch_exp: e ~block_cases
@@ -781,7 +766,7 @@ let compile output_prefix =
781
766
| _ ->
782
767
let v = Ext_ident. create_tmp () in
783
768
(* Necessary avoid duplicated computation*)
784
- [ S. define_variable ~kind: Variable v e] @ dispatch (E. var v))
769
+ S. define_variable ~kind: Variable v e :: dispatch (E. var v))
785
770
in
786
771
match lambda_cxt.continuation with
787
772
(* Needs declare first *)
@@ -791,19 +776,15 @@ let compile output_prefix =
791
776
when branches are minimial (less than 2)
792
777
*)
793
778
let v = Ext_ident. create_tmp () in
794
- let res = compile_whole {lambda_cxt with continuation = Assign v} in
795
- (* Printf.eprintf "XXX res 1: %s\n\n" (Js_dump.string_of_block res); *)
796
779
Js_output. make
797
- (S. declare_variable ~kind: Variable v :: res)
780
+ (S. declare_variable ~kind: Variable v
781
+ :: compile_whole {lambda_cxt with continuation = Assign v})
798
782
~value: (E. var v)
799
783
| Declare (kind , id ) ->
800
- let res = compile_whole {lambda_cxt with continuation = Assign id} in
801
- (* Printf.eprintf "XXX res 2: %s\n\n" (Js_dump.string_of_block res); *)
802
- Js_output. make (S. declare_variable ~kind id :: res) ~value: (E. var id)
803
- | EffectCall _ | Assign _ ->
804
- let res = compile_whole lambda_cxt in
805
- (* Printf.eprintf "XXX res 3: %s\n\n" (Js_dump.string_of_block res); *)
806
- Js_output. make res
784
+ Js_output. make
785
+ (S. declare_variable ~kind id
786
+ :: compile_whole {lambda_cxt with continuation = Assign id})
787
+ | EffectCall _ | Assign _ -> Js_output. make (compile_whole lambda_cxt)
807
788
and compile_string_cases ~cxt ~switch_exp ~default cases : initialization =
808
789
cases
809
790
|> compile_general_cases ~make_exp: E. tag_type
0 commit comments