Skip to content

Commit

Permalink
Merge ffe0981 into 289cf1d
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzhang committed Mar 9, 2018
2 parents 289cf1d + ffe0981 commit eccd7ed
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 96 deletions.
24 changes: 0 additions & 24 deletions jscomp/core/lam_compile_main.ml
Expand Up @@ -66,13 +66,6 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.t)
to make those parts pure (not a function call), then it can be removed
if unused
*)
| Single(_, ({name="infinity";_} as id),_ ), "pervasives.ml"
-> (* TODO: check relative path to compiler*)
Js_output.of_stmt @@ S.alias_variable id ~exp:(E.js_global "Infinity")
| Single(_, ({name="neg_infinity";_} as id),_ ), "pervasives.ml" ->
Js_output.of_stmt @@ S.alias_variable id ~exp:(E.js_global "-Infinity")
| Single(_, ({name="nan";_} as id),_ ), "pervasives.ml" ->
Js_output.of_stmt @@ S.alias_variable id ~exp:(E.js_global "NaN")

(* QUICK hack to make hello world example nicer,
Note the arity of [print_endline] is already analyzed before,
Expand All @@ -85,23 +78,6 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.t)
E.ocaml_fun [arg] [S.return_stmt (E.int_to_string (E.var arg))]
)

| Single(_, ({name="max_float";_} as id),_ ), "pervasives.ml" ->

Js_output.of_stmt @@ S.alias_variable id
~exp:(E.js_global_dot "Number" "MAX_VALUE")
| Single(_, ({name="min_float";_} as id) ,_ ), "pervasives.ml" ->
Js_output.of_stmt @@ S.alias_variable id
~exp:(E.js_global_dot "Number" "MIN_VALUE")
| Single(_, ({name="epsilon_float";_} as id) ,_ ), "pervasives.ml" ->
Js_output.of_stmt @@ S.alias_variable id
~exp:(E.float "2.220446049250313e-16")
| Single(_, ({name="cat";_} as id) ,_ ), "bytes.ml" ->
Js_output.of_stmt @@ S.alias_variable id
~exp:(let a = Ext_ident.create "a" in
let b = Ext_ident.create "b" in
E.ocaml_fun [a;b] [S.return_stmt (E.array_append (E.var a) (E.var b))]
)

(** Special handling for values in [Sys] *)
| Single(_, ({name="max_array_length" | "max_string_length";_} as id) ,_ ), "sys.ml" ->
(* See [js_knowledge] Array size section, can not be expressed by OCaml int,
Expand Down
19 changes: 18 additions & 1 deletion jscomp/stdlib/pervasives.ml
Expand Up @@ -146,6 +146,22 @@ external float_of_int : int -> float = "%floatofint"
external truncate : float -> int = "%intoffloat"
external int_of_float : float -> int = "%intoffloat"
external float_of_bits : int64 -> float = "caml_int64_float_of_bits"

#if BS then
external infinity : float = "POSITIVE_INFINITY"
[@@bs.val] [@@bs.scope "Number"]
external neg_infinity : float = "NEGATIVE_INFINITY"
[@@bs.val] [@@bs.scope "Number"]
external nan : float = "NaN"
[@@bs.val] [@@bs.scope "Number"]
external max_float : float = "MAX_VALUE"
[@@bs.val] [@@bs.scope "Number"]
external min_float : float = "MIN_VALUE"
[@@bs.val] [@@bs.scope "Number"]
(* external epsilon_float : float = "EPSILON" (* ES 2015 *)
[@@bs.val] [@@bs.scope "Number"] *)
let epsilon_float = 2.220446049250313e-16
#else
let infinity =
float_of_bits 0x7F_F0_00_00_00_00_00_00L
let neg_infinity =
Expand All @@ -157,7 +173,8 @@ let max_float =
let min_float =
float_of_bits 0x00_10_00_00_00_00_00_00L
let epsilon_float =
float_of_bits 0x3C_B0_00_00_00_00_00_00L
float_of_bits 0x3C_B0_00_00_00_00_00_00L
#end

type fpclass =
FP_normal
Expand Down
18 changes: 17 additions & 1 deletion jscomp/stdlib/pervasives.mli
Expand Up @@ -463,7 +463,21 @@ external int_of_float : float -> int = "%intoffloat"
(** Truncate the given floating-point number to an integer.
The result is unspecified if the argument is [nan] or falls outside the
range of representable integers. *)

#if BS then
external infinity : float = "POSITIVE_INFINITY"
[@@bs.val] [@@bs.scope "Number"]
external neg_infinity : float = "NEGATIVE_INFINITY"
[@@bs.val] [@@bs.scope "Number"]
external nan : float = "NaN"
[@@bs.val] [@@bs.scope "Number"]
external max_float : float = "MAX_VALUE"
[@@bs.val] [@@bs.scope "Number"]
external min_float : float = "MIN_VALUE"
[@@bs.val] [@@bs.scope "Number"]
(* external epsilon_float : float = "EPSILON" (* ES 2015 *)
[@@bs.val] [@@bs.scope "Number"] *)
val epsilon_float : float
#else
val infinity : float
(** Positive infinity. *)

Expand All @@ -488,6 +502,8 @@ val epsilon_float : float
(** The difference between [1.0] and the smallest exactly representable
floating-point number greater than [1.0]. *)

#end

type fpclass =
FP_normal (** Normal number, none of the below *)
| FP_subnormal (** Number very close to 0.0, has reduced precision *)
Expand Down
6 changes: 3 additions & 3 deletions jscomp/test/caml_format_test.js
Expand Up @@ -1305,17 +1305,17 @@ var float_data = /* array */[
],
/* tuple */[
"%f",
Pervasives.nan,
Number.NaN,
"nan"
],
/* tuple */[
"%f",
Pervasives.infinity,
Number.POSITIVE_INFINITY,
"inf"
],
/* tuple */[
"%f",
Pervasives.neg_infinity,
Number.NEGATIVE_INFINITY,
"-inf"
],
/* tuple */[
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/float_test.js
Expand Up @@ -152,7 +152,7 @@ Mt_global.collect_eq(test_id, suites, "File \"float_test.ml\", line 48, characte
-3
]);

var match$3 = Caml_float.caml_modf_float(Pervasives.nan);
var match$3 = Caml_float.caml_modf_float(Number.NaN);

var param_000 = +isNaN(match$3[0]);

Expand Down
5 changes: 2 additions & 3 deletions jscomp/test/js_float_test.js
Expand Up @@ -2,7 +2,6 @@

var Mt = require("./mt.js");
var Block = require("../../lib/js/block.js");
var Pervasives = require("../../lib/js/pervasives.js");

var suites_000 = /* tuple */[
"_NaN <> _NaN",
Expand Down Expand Up @@ -40,7 +39,7 @@ var suites_001 = /* :: */[
(function () {
return /* Eq */Block.__(0, [
/* false */0,
+isFinite(Pervasives.infinity)
+isFinite(Number.POSITIVE_INFINITY)
]);
})
],
Expand All @@ -50,7 +49,7 @@ var suites_001 = /* :: */[
(function () {
return /* Eq */Block.__(0, [
/* false */0,
+isFinite(Pervasives.neg_infinity)
+isFinite(Number.NEGATIVE_INFINITY)
]);
})
],
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/ocaml_proto_test.js
Expand Up @@ -1628,7 +1628,7 @@ function lexer(lexbuf) {
case 15 :
return /* FLOAT */Block.__(4, [Caml_format.caml_float_of_string(Lexing.lexeme(lexbuf$1))]);
case 16 :
return /* FLOAT */Block.__(4, [Pervasives.nan]);
return /* FLOAT */Block.__(4, [Number.NaN]);
case 17 :
update_loc(lexbuf$1);
___ocaml_lex_state = 0;
Expand Down
5 changes: 0 additions & 5 deletions jscomp/test/test_pervasive.js
Expand Up @@ -55,11 +55,6 @@ var Pervasives$1 = /* module */[
/* max_int */Pervasives.max_int,
/* min_int */Pervasives.min_int,
/* lnot */Pervasives.lnot,
/* infinity */Pervasives.infinity,
/* neg_infinity */Pervasives.neg_infinity,
/* nan */Pervasives.nan,
/* max_float */Pervasives.max_float,
/* min_float */Pervasives.min_float,
/* epsilon_float */Pervasives.epsilon_float,
/* char_of_int */Pervasives.char_of_int,
/* string_of_bool */Pervasives.string_of_bool,
Expand Down
10 changes: 0 additions & 10 deletions jscomp/test/test_pervasives2.js
Expand Up @@ -56,11 +56,6 @@ var List$1 = /* module */[
/* max_int */Pervasives.max_int,
/* min_int */Pervasives.min_int,
/* lnot */Pervasives.lnot,
/* infinity */Pervasives.infinity,
/* neg_infinity */Pervasives.neg_infinity,
/* nan */Pervasives.nan,
/* max_float */Pervasives.max_float,
/* min_float */Pervasives.min_float,
/* epsilon_float */Pervasives.epsilon_float,
/* char_of_int */Pervasives.char_of_int,
/* string_of_bool */Pervasives.string_of_bool,
Expand Down Expand Up @@ -150,11 +145,6 @@ var U = /* module */[
/* max_int */Pervasives.max_int,
/* min_int */Pervasives.min_int,
/* lnot */Pervasives.lnot,
/* infinity */Pervasives.infinity,
/* neg_infinity */Pervasives.neg_infinity,
/* nan */Pervasives.nan,
/* max_float */Pervasives.max_float,
/* min_float */Pervasives.min_float,
/* epsilon_float */Pervasives.epsilon_float,
/* char_of_int */Pervasives.char_of_int,
/* string_of_bool */Pervasives.string_of_bool,
Expand Down
5 changes: 0 additions & 5 deletions jscomp/test/test_pervasives3.js
Expand Up @@ -11,11 +11,6 @@ var Pervasives$1 = /* module */[
/* max_int */Pervasives.max_int,
/* min_int */Pervasives.min_int,
/* lnot */Pervasives.lnot,
/* infinity */Pervasives.infinity,
/* neg_infinity */Pervasives.neg_infinity,
/* nan */Pervasives.nan,
/* max_float */Pervasives.max_float,
/* min_float */Pervasives.min_float,
/* epsilon_float */Pervasives.epsilon_float,
/* char_of_int */Pervasives.char_of_int,
/* string_of_bool */Pervasives.string_of_bool,
Expand Down
4 changes: 2 additions & 2 deletions jscomp/test/to_string_test.js
Expand Up @@ -15,7 +15,7 @@ Mt.from_pair_suites("to_string_test.ml", /* :: */[
"File \"to_string_test.ml\", line 7, characters 2-9",
(function () {
return /* Eq */Block.__(0, [
Pervasives.string_of_float(Pervasives.infinity),
Pervasives.string_of_float(Number.POSITIVE_INFINITY),
"inf"
]);
})
Expand All @@ -25,7 +25,7 @@ Mt.from_pair_suites("to_string_test.ml", /* :: */[
"File \"to_string_test.ml\", line 8, characters 1-8",
(function () {
return /* Eq */Block.__(0, [
Pervasives.string_of_float(Pervasives.neg_infinity),
Pervasives.string_of_float(Number.NEGATIVE_INFINITY),
"-inf"
]);
})
Expand Down
9 changes: 7 additions & 2 deletions lib/js/bytes.js
Expand Up @@ -149,8 +149,13 @@ function concat(sep, l) {
}
}

function cat(a, b) {
return a.concat(b);
function cat(s1, s2) {
var l1 = s1.length;
var l2 = s2.length;
var r = Caml_string.caml_create_string(l1 + l2 | 0);
Caml_string.caml_blit_bytes(s1, 0, r, 0, l1);
Caml_string.caml_blit_bytes(s2, 0, r, l1, l2);
return r;
}

function is_space(param) {
Expand Down
15 changes: 0 additions & 15 deletions lib/js/pervasives.js
Expand Up @@ -471,16 +471,6 @@ function exit(retcode) {

var max_int = 2147483647;

var infinity = Infinity;

var neg_infinity = -Infinity;

var nan = NaN;

var max_float = Number.MAX_VALUE;

var min_float = Number.MIN_VALUE;

var epsilon_float = 2.220446049250313e-16;

var flush = Caml_io.caml_ml_flush;
Expand Down Expand Up @@ -581,11 +571,6 @@ exports.abs = abs;
exports.max_int = max_int;
exports.min_int = min_int;
exports.lnot = lnot;
exports.infinity = infinity;
exports.neg_infinity = neg_infinity;
exports.nan = nan;
exports.max_float = max_float;
exports.min_float = min_float;
exports.epsilon_float = epsilon_float;
exports.char_of_int = char_of_int;
exports.string_of_bool = string_of_bool;
Expand Down
23 changes: 0 additions & 23 deletions lib/whole_compiler.ml
Expand Up @@ -101831,13 +101831,6 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.t)
to make those parts pure (not a function call), then it can be removed
if unused
*)
| Single(_, ({name="infinity";_} as id),_ ), "pervasives.ml"
-> (* TODO: check relative path to compiler*)
Js_output.of_stmt @@ S.alias_variable id ~exp:(E.js_global "Infinity")
| Single(_, ({name="neg_infinity";_} as id),_ ), "pervasives.ml" ->
Js_output.of_stmt @@ S.alias_variable id ~exp:(E.js_global "-Infinity")
| Single(_, ({name="nan";_} as id),_ ), "pervasives.ml" ->
Js_output.of_stmt @@ S.alias_variable id ~exp:(E.js_global "NaN")

(* QUICK hack to make hello world example nicer,
Note the arity of [print_endline] is already analyzed before,
Expand All @@ -101850,22 +101843,6 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.t)
E.ocaml_fun [arg] [S.return_stmt (E.int_to_string (E.var arg))]
)

| Single(_, ({name="max_float";_} as id),_ ), "pervasives.ml" ->

Js_output.of_stmt @@ S.alias_variable id
~exp:(E.js_global_dot "Number" "MAX_VALUE")
| Single(_, ({name="min_float";_} as id) ,_ ), "pervasives.ml" ->
Js_output.of_stmt @@ S.alias_variable id
~exp:(E.js_global_dot "Number" "MIN_VALUE")
| Single(_, ({name="epsilon_float";_} as id) ,_ ), "pervasives.ml" ->
Js_output.of_stmt @@ S.alias_variable id
~exp:(E.float "2.220446049250313e-16")
| Single(_, ({name="cat";_} as id) ,_ ), "bytes.ml" ->
Js_output.of_stmt @@ S.alias_variable id
~exp:(let a = Ext_ident.create "a" in
let b = Ext_ident.create "b" in
E.ocaml_fun [a;b] [S.return_stmt (E.array_append (E.var a) (E.var b))]
)

(** Special handling for values in [Sys] *)
| Single(_, ({name="max_array_length" | "max_string_length";_} as id) ,_ ), "sys.ml" ->
Expand Down

0 comments on commit eccd7ed

Please sign in to comment.