Skip to content

Commit b44bd95

Browse files
committed
less ad-hoc, the remaining part: stdin,stdout,stderr
1 parent d1cdc16 commit b44bd95

File tree

6 files changed

+16
-70
lines changed

6 files changed

+16
-70
lines changed

jscomp/core/lam_compile_main.ml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,36 +71,6 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.t)
7171
Note the arity of [print_endline] is already analyzed before,
7272
so it should be safe
7373
*)
74-
(* | Single(_, ({name="string_of_int";_} as id),_ ), "pervasives.ml" ->
75-
Js_output.of_stmt @@ S.alias_variable id
76-
~exp:(
77-
let arg = Ext_ident.create "param" in
78-
E.ocaml_fun [arg] [S.return_stmt (E.int_to_string (E.var arg))]
79-
) *)
80-
81-
(** Special handling for values in [Sys] *)
82-
| Single(_, ({name="max_array_length" | "max_string_length";_} as id) ,_ ), "sys.ml" ->
83-
(* See [js_knowledge] Array size section, can not be expressed by OCaml int,
84-
note that casual handling of {!Sys.max_string_length} could result into
85-
negative value which could cause wrong behavior of {!Buffer.create}
86-
*)
87-
Js_output.of_stmt @@ S.alias_variable id ~exp:(E.float "2147483647") (*2 ^ 31 - 1*)
88-
89-
| Single(_, ({name="max_int";_} as id) ,_ ), ("sys.ml" | "nativeint.ml") ->
90-
(* See [js_knowledge] Max int section, (2. ** 53. -. 1.;;)
91-
can not be expressed by OCaml int
92-
FIXME: we need handle {!Nativeint} and {!Sys} differently
93-
*)
94-
Js_output.of_stmt @@ S.alias_variable id
95-
~exp:(E.float "9007199254740991.")
96-
97-
| Single(_, ({name="min_int";_} as id) ,_ ), ("sys.ml" | "nativeint.ml") ->
98-
(* See [js_knowledge] Max int section, -. (2. ** 53. -. 1.);;
99-
can not be expressed by OCaml int
100-
FIXME: we need handle {!Nativeint} and {!Sys} differently
101-
*)
102-
Js_output.of_stmt @@ S.alias_variable id
103-
~exp:(E.float ("-9007199254740991."))
10474

10575
| Single (kind, id, lam), _ ->
10676
(* let lam = Optimizer.simplify_lets [] lam in *)

jscomp/stdlib/nativeint.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ let pred n = sub n 1n
4040
let abs n = if n >= 0n then n else neg n
4141
#if BS then
4242
let size = 54 (* 54 is not a multiple of 8 *)
43+
let min_int = -9007199254740991n
44+
let max_int = 9007199254740991n
4345
#else
4446
let size = Sys.word_size
45-
#end
4647
let min_int = shift_left 1n (size - 1)
4748
let max_int = sub min_int 1n
49+
#end
4850
let lognot n = logxor n (-1n)
4951

5052
external format : string -> nativeint -> string = "caml_nativeint_format"

jscomp/stdlib/sys.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ let word_size = word_size ()
3333
let unix = unix ()
3434
let win32 = win32 ()
3535
let cygwin = cygwin ()
36+
#if BS then
37+
let max_array_length = 2147483647 (* 2^ 31 - 1 *)
38+
let max_string_length = 2147483647
39+
#else
3640
let max_array_length = (1 lsl (word_size - 10)) - 1;;
3741
let max_string_length = word_size / 8 * max_array_length - 1;;
38-
42+
#end
3943
external file_exists: string -> bool = "caml_sys_file_exists"
4044
external is_directory : string -> bool = "caml_sys_is_directory"
4145
external remove: string -> unit = "caml_sys_remove"

lib/js/nativeint.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ function abs(n) {
1919
}
2020
}
2121

22-
var min_int = -9007199254740991;
23-
24-
var max_int = 9007199254740991;
25-
2622
function lognot(n) {
2723
return n ^ -1;
2824
}
@@ -41,6 +37,10 @@ var minus_one = -1;
4137

4238
var size = 54;
4339

40+
var max_int = 9007199254740991;
41+
42+
var min_int = -9007199254740991;
43+
4444
exports.zero = zero;
4545
exports.one = one;
4646
exports.minus_one = minus_one;

lib/js/sys.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ var win32 = /* false */0;
1515

1616
var cygwin = /* false */0;
1717

18-
var max_array_length = 2147483647;
19-
20-
var max_string_length = 2147483647;
21-
2218
var interactive = [/* false */0];
2319

2420
function set_signal(_, _$1) {
@@ -39,6 +35,10 @@ var os_type = "Unix";
3935

4036
var word_size = 32;
4137

38+
var max_string_length = 2147483647;
39+
40+
var max_array_length = 2147483647;
41+
4242
var sigabrt = -1;
4343

4444
var sigalrm = -2;

lib/whole_compiler.ml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101836,36 +101836,6 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.t)
101836101836
Note the arity of [print_endline] is already analyzed before,
101837101837
so it should be safe
101838101838
*)
101839-
(* | Single(_, ({name="string_of_int";_} as id),_ ), "pervasives.ml" ->
101840-
Js_output.of_stmt @@ S.alias_variable id
101841-
~exp:(
101842-
let arg = Ext_ident.create "param" in
101843-
E.ocaml_fun [arg] [S.return_stmt (E.int_to_string (E.var arg))]
101844-
) *)
101845-
101846-
(** Special handling for values in [Sys] *)
101847-
| Single(_, ({name="max_array_length" | "max_string_length";_} as id) ,_ ), "sys.ml" ->
101848-
(* See [js_knowledge] Array size section, can not be expressed by OCaml int,
101849-
note that casual handling of {!Sys.max_string_length} could result into
101850-
negative value which could cause wrong behavior of {!Buffer.create}
101851-
*)
101852-
Js_output.of_stmt @@ S.alias_variable id ~exp:(E.float "2147483647") (*2 ^ 31 - 1*)
101853-
101854-
| Single(_, ({name="max_int";_} as id) ,_ ), ("sys.ml" | "nativeint.ml") ->
101855-
(* See [js_knowledge] Max int section, (2. ** 53. -. 1.;;)
101856-
can not be expressed by OCaml int
101857-
FIXME: we need handle {!Nativeint} and {!Sys} differently
101858-
*)
101859-
Js_output.of_stmt @@ S.alias_variable id
101860-
~exp:(E.float "9007199254740991.")
101861-
101862-
| Single(_, ({name="min_int";_} as id) ,_ ), ("sys.ml" | "nativeint.ml") ->
101863-
(* See [js_knowledge] Max int section, -. (2. ** 53. -. 1.);;
101864-
can not be expressed by OCaml int
101865-
FIXME: we need handle {!Nativeint} and {!Sys} differently
101866-
*)
101867-
Js_output.of_stmt @@ S.alias_variable id
101868-
~exp:(E.float ("-9007199254740991."))
101869101839

101870101840
| Single (kind, id, lam), _ ->
101871101841
(* let lam = Optimizer.simplify_lets [] lam in *)

0 commit comments

Comments
 (0)