Skip to content

Commit 35a6543

Browse files
committed
clean up code
1 parent 0ccd292 commit 35a6543

File tree

1 file changed

+20
-39
lines changed

1 file changed

+20
-39
lines changed

compiler/core/lam_compile.ml

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,6 @@ let compile output_prefix =
673673
also if last statement is throw -- should we drop remaining
674674
statement?
675675
*)
676-
(* Printf.eprintf "XXX switch_arg: %s\n\n"
677-
(Lam_print.lambda_to_string switch_arg); *)
678676
let ({
679677
sw_consts_full;
680678
sw_consts;
@@ -715,55 +713,42 @@ let compile output_prefix =
715713
block
716714
@
717715
if sw_consts_full && sw_consts = [] then
718-
(* let _ = Printf.eprintf "QQQ sw_consts_full\n\n" in *)
719716
compile_cases ~block_cases ~untagged ~cxt
720717
~switch_exp:(if untagged then e else E.tag ~name:tag_name e)
721718
~default:sw_blocks_default ~get_tag:get_block_tag sw_blocks
722719
else if sw_blocks_full && sw_blocks = [] then
723-
(* let _ = Printf.eprintf "QQQ sw_blocks_full\n\n" in *)
724720
compile_cases ~cxt ~switch_exp:e ~block_cases ~default:sw_num_default
725721
~get_tag:get_const_tag sw_consts
726722
else
727-
(* let _ = Printf.eprintf "QQQ else\n\n" in *)
728723
(* [e] will be used twice *)
729724
let dispatch e =
730725
let is_a_literal_case =
731726
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
740730
else
741731
E.is_int_tag
742732
~has_null_undefined_other:(has_null_undefined_other sw_names)
743733
e
744734
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
751735
let eq_default d1 d2 =
752736
match (d1, d2) with
753737
| Default lam1, Default lam2 -> Lam.eq_approx lam1 lam2
754738
| Complete, Complete -> true
755739
| NonComplete, NonComplete -> true
756740
| _ -> false
757741
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
767752
[
768753
S.if_ is_a_literal_case
769754
(compile_cases ~cxt ~switch_exp:e ~block_cases
@@ -781,7 +766,7 @@ let compile output_prefix =
781766
| _ ->
782767
let v = Ext_ident.create_tmp () in
783768
(* 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))
785770
in
786771
match lambda_cxt.continuation with
787772
(* Needs declare first *)
@@ -791,19 +776,15 @@ let compile output_prefix =
791776
when branches are minimial (less than 2)
792777
*)
793778
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); *)
796779
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})
798782
~value:(E.var v)
799783
| 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)
807788
and compile_string_cases ~cxt ~switch_exp ~default cases : initialization =
808789
cases
809790
|> compile_general_cases ~make_exp:E.tag_type

0 commit comments

Comments
 (0)