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
4 changes: 3 additions & 1 deletion jscomp/bsb/bsb_templates.ml
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,13 @@ let root = OCamlRes.Res.([
Dir ("react", [
File ("webpack.config.js",
"const path = require('path');\n\
const outputDir = path.join(__dirname, \"build/\");\n\
\n\
module.exports = {\n\
\ entry: './src/Index.bs.js',\n\
\ output: {\n\
\ path: path.join(__dirname, \"build\"),\n\
\ path: outputDir,\n\
\ publicPath: outputDir,\n\
\ filename: 'Index.js',\n\
\ },\n\
};\n\
Expand Down
7 changes: 7 additions & 0 deletions jscomp/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,13 @@ let js_bool ?comment x : t =

let is_undef ?comment x = triple_equal ?comment x undefined

let for_sure_js_null_undefined_boolean (x : t) =
match x.expression_desc with
| Var (Id ({name = "undefined" | "null"} as id))
-> Ext_ident.is_js id
| Bool _ -> true
| _ -> false

let is_null_undefined ?comment (x: t) : t =
match x.expression_desc with
| Var (Id ({name = "undefined" | "null"} as id))
Expand Down
1 change: 1 addition & 0 deletions jscomp/core/js_exp_make.mli
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,6 @@ val is_nil : unary_op

val js_bool : ?comment:string -> bool -> t
val is_undef : unary_op
val for_sure_js_null_undefined_boolean : J.expression -> bool
val is_null_undefined : unary_op
val not_implemented : ?comment:string -> string -> t
9 changes: 8 additions & 1 deletion jscomp/core/lam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type meth_kind = Lambda.meth_kind
type constant =
| Const_js_null
| Const_js_undefined
| Const_js_true
| Const_js_false
| Const_int of int
| Const_char of char
| Const_string of string (* use record later *)
Expand Down Expand Up @@ -1127,8 +1129,10 @@ let if_ (a : t) (b : t) c =
if x <> 0L then b else c
| (Const_nativeint x) ->
if x <> 0n then b else c
| Const_js_false
| Const_js_null
| Const_js_undefined -> c
| Const_js_true
| Const_string _
| Const_float _
| Const_unicode _
Expand Down Expand Up @@ -1818,7 +1822,10 @@ let convert exports lam : _ * _ =
prim ~primitive:Pdebugger ~args:[] loc
| _ when s = "#null" ->
Lconst (Const_js_null)

| _ when s = "#true" ->
Lconst (Const_js_true)
| _ when s = "#false" ->
Lconst (Const_js_false)
| _ when s = "#undefined" ->
Lconst (Const_js_undefined)
| _ when s = "#init_mod" ->
Expand Down
2 changes: 2 additions & 0 deletions jscomp/core/lam.mli
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type function_kind
type constant =
| Const_js_null
| Const_js_undefined
| Const_js_true
| Const_js_false
| Const_int of int
| Const_char of char
| Const_string of string
Expand Down
1 change: 1 addition & 0 deletions jscomp/core/lam_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ and size_constant x =
| Const_immstring _
| Const_pointer _
| Const_js_null | Const_js_undefined
| Const_js_true | Const_js_false
-> 1
| Const_block (_, _, str)
-> List.fold_left (fun acc x -> acc + size_constant x ) 0 str
Expand Down
2 changes: 2 additions & 0 deletions jscomp/core/lam_compile_const.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module E = Js_exp_make

let rec translate (x : Lam.constant ) : J.expression =
match x with
| Const_js_true -> E.js_bool true
| Const_js_false -> E.js_bool false
| Const_js_null -> E.nil
| Const_js_undefined -> E.undefined
| Const_int i -> E.int (Int32.of_int i)
Expand Down
14 changes: 12 additions & 2 deletions jscomp/core/lam_dispatch_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,20 @@ let translate loc (prim_name : string)
->
call Js_runtime_modules.obj_runtime

| "caml_equal" ->
begin match args with
| [a1;b1] when
E.for_sure_js_null_undefined_boolean a1 || E.for_sure_js_null_undefined_boolean b1
->
E.int_comp Ceq a1 b1
(* FIXME address_equal *)
| _ ->
Location.prerr_warning loc Warnings.Bs_polymorphic_comparison ;
call Js_runtime_modules.obj_runtime
end
| "caml_min"
| "caml_max"
| "caml_compare"
| "caml_equal"
| "caml_compare"
| "caml_notequal"
| "caml_greaterequal"
| "caml_greaterthan"
Expand Down
2 changes: 2 additions & 0 deletions jscomp/core/lam_print.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ open Types

let rec struct_const ppf (cst : Lam.constant) =
match cst with
| Const_js_true -> fprintf ppf "#true"
| Const_js_false -> fprintf ppf "#false"
| Const_js_null -> fprintf ppf "#null"
| Const_js_undefined -> fprintf ppf "#undefined"
| (Const_int n) -> fprintf ppf "%i" n
Expand Down
4 changes: 2 additions & 2 deletions jscomp/runtime/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ type (+'a, +'e) promise


(* tag::predefined_js_values[]*)
external true_ : boolean = "true" [@@bs.val]
external false_ : boolean = "false" [@@bs.val]
external true_ : boolean = "#true"
external false_ : boolean = "#false"
external null : 'a null = "#null"
(* The same as {!Js.Null.empty} will be compiled as [null]*)
external undefined : 'a undefined = "#undefined"
Expand Down
4 changes: 2 additions & 2 deletions jscomp/runtime/js.mli
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ type (+'a, +'e) promise
*)


external true_ : boolean = "true" [@@bs.val]
external false_ : boolean = "false" [@@bs.val]
external true_ : boolean = "#true"
external false_ : boolean = "#false"

external null : 'a null = "#null"
(** The same as [empty] in {!Js.Null} will be compiled as [null]*)
Expand Down
12 changes: 6 additions & 6 deletions jscomp/test/bs_hashtbl_string_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ function bench4() {
for(var i$2 = 0; i$2 <= 1000000; ++i$2){
Bs_HashMapString.remove(table, "" + i$2);
}
if (table.size) {
if (Bs_HashMapString.isEmpty(table)) {
return 0;
} else {
throw [
Caml_builtin_exceptions.assert_failure,
[
Expand All @@ -199,8 +201,6 @@ function bench4() {
2
]
];
} else {
return 0;
}
}

Expand Down Expand Up @@ -231,7 +231,9 @@ function bench5() {
Bs_HashMap.remove(table, i$2);
}
console.timeEnd("bs_hashtbl_string_test.ml 141");
if (table.size) {
if (Bs_HashMap.isEmpty(table)) {
return 0;
} else {
throw [
Caml_builtin_exceptions.assert_failure,
[
Expand All @@ -240,8 +242,6 @@ function bench5() {
2
]
];
} else {
return 0;
}
}

Expand Down
4 changes: 2 additions & 2 deletions jscomp/test/bs_poly_set_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ var m$2 = {
data: Bs_SortedSetDict.empty
};

b("File \"bs_poly_set_test.ml\", line 82, characters 4-11", Caml_obj.caml_equal(Bs_SortedSetDict.minUndefined(m$2.data), undefined));
b("File \"bs_poly_set_test.ml\", line 82, characters 4-11", +(Bs_SortedSetDict.minUndefined(m$2.data) === undefined));

var m$3 = {
cmp: IntCmp[/* cmp */0],
data: Bs_SortedSetDict.empty
};

b("File \"bs_poly_set_test.ml\", line 83, characters 4-11", Caml_obj.caml_equal(Bs_SortedSetDict.maxUndefined(m$3.data), undefined));
b("File \"bs_poly_set_test.ml\", line 83, characters 4-11", +(Bs_SortedSetDict.maxUndefined(m$3.data) === undefined));

function testIterToList(xs) {
var v = [/* [] */0];
Expand Down
10 changes: 5 additions & 5 deletions jscomp/test/ffi_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ function u() {
return xx(3);
}

var a = true;

var b = false;

var Textarea = /* module */[];

var Int32Array = /* module */[];
Expand All @@ -25,6 +21,10 @@ function f() {
return v[0];
}

var a = true;

var b = false;

var c = null;

var d = undefined;
Expand All @@ -38,4 +38,4 @@ exports.Textarea = Textarea;
exports.Int32Array = Int32Array;
exports.v = v;
exports.f = f;
/* a Not a pure module */
/* No side effect */
8 changes: 4 additions & 4 deletions jscomp/test/gpr496_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ var expected = /* tuple */[
expected_007
];

var u_000 = Caml_obj.caml_equal(true, false);
var u_000 = +(true === false);

var u_001 = Caml_obj.caml_equal(false, true);
var u_001 = +(false === true);

var u_002 = Caml_obj.caml_equal(false, false);
var u_002 = +(false === false);

var u_003 = Caml_obj.caml_equal(true, true);
var u_003 = +(true === true);

var u_004 = Caml_obj.caml_compare(false, true);

Expand Down
15 changes: 12 additions & 3 deletions jscomp/test/js_bool_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var suites_000 = /* tuple */[
(function () {
return /* Eq */Block.__(0, [
u,
f(true)
/* true */1
]);
})
];
Expand All @@ -59,7 +59,7 @@ var suites_001 = /* :: */[
(function () {
return /* Eq */Block.__(0, [
/* false */0,
+(f(true) === (true))
+(/* true */1 === (true))
]);
})
],
Expand All @@ -72,6 +72,14 @@ var suites = /* :: */[
suites_001
];

function ff(u) {
if (u === true) {
return 1;
} else {
return 2;
}
}

Mt.from_pair_suites("js_bool_test.ml", suites);

exports.f = f;
Expand All @@ -81,4 +89,5 @@ exports.f3 = f3;
exports.u = u;
exports.v = v;
exports.suites = suites;
/* f3 Not a pure module */
exports.ff = ff;
/* u Not a pure module */
4 changes: 3 additions & 1 deletion jscomp/test/js_bool_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ let suites = Mt.[
Eq( false, (f Js.true_ = [%bs.raw {|true|} ] (* not type check*))));
]

(* let f u = Js.unsafe_js_expr u *)
let ff u =
if u = Js.true_ then 1
else 2

;; Mt.from_pair_suites __FILE__ suites
2 changes: 1 addition & 1 deletion jscomp/test/js_null_undefined_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ var suites_001 = /* :: */[
/* tuple */[
"undefined = empty",
(function () {
return /* Ok */Block.__(4, [Caml_obj.caml_equal(undefined, undefined)]);
return /* Ok */Block.__(4, [+(undefined === undefined)]);
})
],
/* :: */[
Expand Down
4 changes: 3 additions & 1 deletion lib/bsb.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13394,11 +13394,13 @@ let root = OCamlRes.Res.([
Dir ("react", [
File ("webpack.config.js",
"const path = require('path');\n\
const outputDir = path.join(__dirname, \"build/\");\n\
\n\
module.exports = {\n\
\ entry: './src/Index.bs.js',\n\
\ output: {\n\
\ path: path.join(__dirname, \"build\"),\n\
\ path: outputDir,\n\
\ publicPath: outputDir,\n\
\ filename: 'Index.js',\n\
\ },\n\
};\n\
Expand Down
Loading