diff --git a/jscomp/core/js_exp_make.ml b/jscomp/core/js_exp_make.ml index 55adc03e8f..c69b589c8a 100644 --- a/jscomp/core/js_exp_make.ml +++ b/jscomp/core/js_exp_make.ml @@ -265,7 +265,7 @@ let rec seq ?comment (e0 : t) (e1 : t) : t = | _, ( Seq(a,( {expression_desc = Number _ ; } as v ) ))-> (* Return value could not be changed*) seq ?comment (seq e0 a) v - + | (Number _ | Var _) , _ -> e1 | _ -> {expression_desc = Seq(e0,e1); comment} @@ -901,8 +901,8 @@ let rec int_comp (cmp : Lambda.comparison) ?comment (e0 : t) (e1 : t) = bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1 let bool_comp (cmp : Lambda.comparison) ?comment (e0 : t) (e1 : t) = - match e0.expression_desc, e1.expression_desc with - | Bool l, Bool r -> + match e0, e1 with + | {expression_desc = Bool l}, {expression_desc = Bool r} -> bool (match cmp with | Ceq -> l = r | Cneq -> l <> r @@ -911,19 +911,22 @@ let bool_comp (cmp : Lambda.comparison) ?comment (e0 : t) (e1 : t) = | Cle -> l <= r | Cge -> l >= r ) - | Bool l, _ -> + | {expression_desc = Bool true}, rest + | rest, {expression_desc = Bool false} -> begin match cmp with - | Clt -> seq e1 caml_false - | Cge -> seq e1 caml_true + | Clt -> seq rest caml_false + | Cge -> seq rest caml_true | Cle | Cgt | Ceq | Cneq -> bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1 end - | _, Bool r -> + | rest, {expression_desc = Bool true} + | {expression_desc = Bool false}, rest + -> begin match cmp with - | Cle -> seq e0 caml_true - | Cgt -> seq e0 caml_false + | Cle -> seq rest caml_true + | Cgt -> seq rest caml_false | Clt | Cge | Ceq diff --git a/jscomp/core/lam_dispatch_primitive.ml b/jscomp/core/lam_dispatch_primitive.ml index ed743d3aea..451e875255 100644 --- a/jscomp/core/lam_dispatch_primitive.ml +++ b/jscomp/core/lam_dispatch_primitive.ml @@ -370,6 +370,14 @@ let translate loc (prim_name : string) E.string_comp Ge e0 e1 | _ -> assert false end + | "caml_string_greaterthan" + -> + begin match args with + | [e0; e1] + -> + E.string_comp Gt e0 e1 + | _ -> assert false + end | "caml_bool_notequal" -> begin match args with @@ -402,7 +410,13 @@ let translate loc (prim_name : string) E.bool_comp Cge e0 e1 | _ -> assert false end - + | "caml_bool_greaterthan" + -> + begin match args with + | [e0;e1] -> + E.bool_comp Cgt e0 e1 + | _ -> assert false + end | "caml_bool_equal" | "caml_bool_equal_null" | "caml_bool_equal_nullable" @@ -451,14 +465,7 @@ let translate loc (prim_name : string) | _ -> assert false end - | "caml_string_greaterthan" - -> - begin match args with - | [e0; e1] - -> - E.string_comp Gt e0 e1 - | _ -> assert false - end + | "caml_create_string" -> (* Bytes.create *) (* Note that for invalid range, JS raise an Exception RangeError, diff --git a/jscomp/test/js_bool_test.js b/jscomp/test/js_bool_test.js index 8d20be309e..ec397aca8c 100644 --- a/jscomp/test/js_bool_test.js +++ b/jscomp/test/js_bool_test.js @@ -96,6 +96,23 @@ function ffadd(x, y) { return x + y; } +function ss(x) { + return "xx" > x; +} + +function bb(x) { + return /* tuple */[ + true > x, + false, + true, + true <= x, + false, + false < x, + false >= x, + true + ]; +} + var bool_array = /* array */[ true, false @@ -115,5 +132,7 @@ exports.fi = fi; exports.fb = fb; exports.fadd = fadd; exports.ffadd = ffadd; +exports.ss = ss; +exports.bb = bb; exports.bool_array = bool_array; /* u Not a pure module */ diff --git a/jscomp/test/js_bool_test.ml b/jscomp/test/js_bool_test.ml index 1b5a991794..3664d822c7 100644 --- a/jscomp/test/js_bool_test.ml +++ b/jscomp/test/js_bool_test.ml @@ -32,5 +32,19 @@ let fb (x : bool) y = x = y let fadd (x : int) y = x + y let ffadd (x : float) y = x +. y +let ss x = "xx" > x + +let bb x = + ( true > x, + true < x, + true >= x , + true <= x, + false > x , + false < x , + false >= x, + false <= x + ) + + let bool_array = [|true; false|] ;; Mt.from_pair_suites __FILE__ suites diff --git a/lib/whole_compiler.ml b/lib/whole_compiler.ml index 4ba0f25a58..8041641d4f 100644 --- a/lib/whole_compiler.ml +++ b/lib/whole_compiler.ml @@ -71276,7 +71276,7 @@ let rec seq ?comment (e0 : t) (e1 : t) : t = | _, ( Seq(a,( {expression_desc = Number _ ; } as v ) ))-> (* Return value could not be changed*) seq ?comment (seq e0 a) v - + | (Number _ | Var _) , _ -> e1 | _ -> {expression_desc = Seq(e0,e1); comment} @@ -71912,8 +71912,8 @@ let rec int_comp (cmp : Lambda.comparison) ?comment (e0 : t) (e1 : t) = bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1 let bool_comp (cmp : Lambda.comparison) ?comment (e0 : t) (e1 : t) = - match e0.expression_desc, e1.expression_desc with - | Bool l, Bool r -> + match e0, e1 with + | {expression_desc = Bool l}, {expression_desc = Bool r} -> bool (match cmp with | Ceq -> l = r | Cneq -> l <> r @@ -71922,19 +71922,22 @@ let bool_comp (cmp : Lambda.comparison) ?comment (e0 : t) (e1 : t) = | Cle -> l <= r | Cge -> l >= r ) - | Bool l, _ -> + | {expression_desc = Bool true}, rest + | rest, {expression_desc = Bool false} -> begin match cmp with - | Clt -> seq e1 caml_false - | Cge -> seq e1 caml_true + | Clt -> seq rest caml_false + | Cge -> seq rest caml_true | Cle | Cgt | Ceq | Cneq -> bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1 end - | _, Bool r -> + | rest, {expression_desc = Bool true} + | {expression_desc = Bool false}, rest + -> begin match cmp with - | Cle -> seq e0 caml_true - | Cgt -> seq e0 caml_false + | Cle -> seq rest caml_true + | Cgt -> seq rest caml_false | Clt | Cge | Ceq @@ -94941,6 +94944,14 @@ let translate loc (prim_name : string) E.string_comp Ge e0 e1 | _ -> assert false end + | "caml_string_greaterthan" + -> + begin match args with + | [e0; e1] + -> + E.string_comp Gt e0 e1 + | _ -> assert false + end | "caml_bool_notequal" -> begin match args with @@ -94973,7 +94984,13 @@ let translate loc (prim_name : string) E.bool_comp Cge e0 e1 | _ -> assert false end - + | "caml_bool_greaterthan" + -> + begin match args with + | [e0;e1] -> + E.bool_comp Cgt e0 e1 + | _ -> assert false + end | "caml_bool_equal" | "caml_bool_equal_null" | "caml_bool_equal_nullable" @@ -95022,14 +95039,7 @@ let translate loc (prim_name : string) | _ -> assert false end - | "caml_string_greaterthan" - -> - begin match args with - | [e0; e1] - -> - E.string_comp Gt e0 e1 - | _ -> assert false - end + | "caml_create_string" -> (* Bytes.create *) (* Note that for invalid range, JS raise an Exception RangeError,