Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions jscomp/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 16 additions & 9 deletions jscomp/core/lam_dispatch_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions jscomp/test/js_bool_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
14 changes: 14 additions & 0 deletions jscomp/test/js_bool_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 28 additions & 18 deletions lib/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down