@@ -488,12 +488,7 @@ let obj ?comment properties : t =
488488
489489(* Dot .....................**)
490490
491- (* * Convert a javascript boolean to ocaml bool
492- It's necessary for return value
493- this should be optmized away for [if] ,[cond] to produce
494- more readable code
495- *)
496- let bool_of_boolean ?comment (e : t ) : t = e
491+
497492
498493
499494(* var (Jident.create_js "true") *)
@@ -549,7 +544,7 @@ let rec triple_equal ?comment (e0 : t) (e1 : t ) : t =
549544 | Char_of_int a , Char_of_int b ->
550545 triple_equal ?comment a b
551546 | _ ->
552- bool_of_boolean {expression_desc = Bin (EqEqEq , e0,e1); comment}
547+ {expression_desc = Bin (EqEqEq , e0,e1); comment}
553548
554549let bin ?comment (op : J.binop ) e0 e1 : t =
555550 match op with
@@ -627,8 +622,7 @@ let rec or_ ?comment (e1 : t) (e2 : t) =
627622let rec not ({expression_desc; comment} as e : t ) : t =
628623 match expression_desc with
629624 | Number (Int {i; _} ) ->
630- if i <> 0l then caml_false else caml_true
631- | Caml_not e -> e
625+ bool (i = 0l )
632626 | Js_not e -> e
633627 (* match expression_desc with *)
634628 (* can still hapen after some optimizations *)
@@ -640,42 +634,11 @@ let rec not ({expression_desc; comment} as e : t) : t =
640634 | Bin (Le,a ,b ) -> {e with expression_desc = Bin (Gt ,a,b)}
641635 | Bin (Gt,a ,b ) -> {e with expression_desc = Bin (Le ,a,b)}
642636 | Bool b -> if b then caml_false else caml_true
643- | x -> {expression_desc = Caml_not e ; comment = None }
644-
645- let rec ocaml_boolean_under_condition (b : t ) =
646- match b.expression_desc with
647- | Bin (And, x ,y ) ->
648- let x' = ocaml_boolean_under_condition x in
649- let y' = ocaml_boolean_under_condition y in
650- if x == x' && y== y' then b
651- else {b with expression_desc = Bin (And ,x',y')}
652- | Bin (Or,x ,y ) ->
653- let x' = ocaml_boolean_under_condition x in
654- let y' = ocaml_boolean_under_condition y in
655- if x == x' && y == y' then b
656- else {b with expression_desc = Bin (Or ,x',y')}
657- (* * TODO: settle down Not semantics *)
658- | Caml_not u
659- | Js_not u
660- ->
661- let u' = ocaml_boolean_under_condition u in
662- if u' == u then b
663- else {b with expression_desc = Js_not u'}
664- | _ -> b
665-
666- (* TODO: could be more non undefined cases
667- check [caml_obj_is_block]
668- acutally we should avoid introducing undefined
669- as much as we can, this kind of inlining and mirco-optimization
670- can be done after we can inline runtime in the future
671- *)
672- (* | Bin (NotEqEq, ({expression_desc = Length _; _} as e1) , *)
673- (* {expression_desc = Var (Id ({name = "undefined"; _} as id))}), *)
674- (* _, _ *)
675- (* when Ext_ident.is_js id -> *)
676- (* econd e1 t f *)
677- (* | (Bin (Bor, v , {expression_desc = Number (Int {i = 0l ; _})})), _, _
678- -> econd v t f *)
637+ | x -> {expression_desc = Js_not e ; comment = None }
638+
639+
640+
641+
679642
680643let rec econd ?comment (b : t ) (t : t ) (f : t ) : t =
681644 match b.expression_desc , t.expression_desc, f.expression_desc with
@@ -736,12 +699,10 @@ let rec econd ?comment (b : t) (t : t) (f : t) : t =
736699 (* the same as above except we revert the [cond] expression *)
737700 econd (or_ b (not p1')) t branch_code0
738701
739- | Caml_not e, _, _
740702 | Js_not e, _, _
741703 ->
742704 econd ?comment e f t
743705 | _ ->
744- let b = ocaml_boolean_under_condition b in
745706 if Js_analyzer. eq_expression t f then
746707 if no_side_effect b then t else seq ?comment b t
747708 else
@@ -793,7 +754,7 @@ let rec float_equal ?comment (e0 : t) (e1 : t) : t =
793754 float_equal ?comment a b
794755
795756 | _ ->
796- bool_of_boolean {expression_desc = Bin (EqEqEq , e0,e1); comment}
757+ {expression_desc = Bin (EqEqEq , e0,e1); comment}
797758
798759
799760let int_equal = float_equal
@@ -807,7 +768,7 @@ let rec string_equal ?comment (e0 : t) (e1 : t) : t =
807768 | Unicode a0 , Unicode b0 -> bool (Ext_string. equal a0 b0)
808769 | _ , _
809770 ->
810- bool_of_boolean {expression_desc = Bin (EqEqEq , e0,e1); comment}
771+ {expression_desc = Bin (EqEqEq , e0,e1); comment}
811772
812773
813774let is_type_number ?comment (e : t ) : t =
@@ -935,7 +896,7 @@ let uint32 ?comment n : J.expression =
935896
936897
937898let string_comp cmp ?comment e0 e1 =
938- bool_of_boolean @@ bin ?comment cmp e0 e1
899+ bin ?comment cmp e0 e1
939900
940901let set_length ?comment e tag : t =
941902 seq {expression_desc = Caml_block_set_length (e,tag); comment } unit
@@ -967,7 +928,7 @@ let rec int_comp (cmp : Lambda.comparison) ?comment (e0 : t) (e1 : t) =
967928 } , args, call_info)}
968929 | Ceq , _ , _ -> int_equal e0 e1
969930 | _ ->
970- bool_of_boolean @@ bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
931+ bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
971932
972933let bool_comp (cmp : Lambda.comparison ) ?comment (e0 : t ) (e1 : t ) =
973934 match e0.expression_desc, e1.expression_desc with
@@ -1001,10 +962,10 @@ let bool_comp (cmp : Lambda.comparison) ?comment (e0 : t) (e1 : t) =
1001962 | _ , _ ->
1002963 bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
1003964let float_comp cmp ?comment e0 e1 =
1004- bool_of_boolean @@ bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
965+ bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
1005966
1006967let js_comp cmp ?comment e0 e1 =
1007- bool_of_boolean @@ bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
968+ bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
1008969
1009970
1010971let rec int32_lsr ?comment
@@ -1286,17 +1247,13 @@ let of_block ?comment ?e block : t =
12861247
12871248let is_null ?comment x = triple_equal ?comment x nil
12881249
1289- let js_true : t = caml_true
1290- let js_false : t = caml_false
1291- let js_bool = bool
12921250
12931251let is_undef ?comment x = triple_equal ?comment x undefined
12941252
1295- let for_sure_js_null_undefined_boolean (x : t ) =
1253+ let for_sure_js_null_undefined (x : t ) =
12961254 match x.expression_desc with
12971255 | Var (Id ({name = " undefined" | " null" } as id))
12981256 -> Ext_ident. is_js id
1299- | Bool _ -> true
13001257 | _ -> false
13011258
13021259let is_null_undefined ?comment (x : t ) : t =
@@ -1306,7 +1263,7 @@ let is_null_undefined ?comment (x: t) : t =
13061263 -> caml_true
13071264 | Number _ | Array _ | Caml_block _ -> caml_false
13081265 | _ ->
1309- bool_of_boolean
1266+
13101267 { comment ;
13111268 expression_desc = Is_null_undefined_to_boolean x
13121269 }
@@ -1328,10 +1285,9 @@ let eq_null_undefined_boolean ?comment (a : t) (b : t) =
13281285 | Var (Id ({name = " null" | " undefined" as n1 } as id1) ),
13291286 Var (Id ({name = " null" | " undefined" as n2 } as id2) )
13301287 when Ext_ident. is_js id1 && Ext_ident. is_js id2
1331- ->
1332- if n1 = n2 then caml_true else caml_false
1288+ -> bool (n1 = n2)
13331289 | _ ->
1334- bool_of_boolean {expression_desc = Bin (EqEqEq , a, b); comment}
1290+ {expression_desc = Bin (EqEqEq , a, b); comment}
13351291
13361292
13371293
@@ -1355,7 +1311,7 @@ let neq_null_undefined_boolean ?comment (a : t) (b : t) =
13551311 ->
13561312 if n1 <> n2 then caml_true else caml_false
13571313 | _ ->
1358- bool_of_boolean {expression_desc = Bin (NotEqEq , a, b); comment}
1314+ {expression_desc = Bin (NotEqEq , a, b); comment}
13591315
13601316
13611317
0 commit comments