Skip to content

Commit 5394da1

Browse files
committed
fix gpr 977
1 parent 6cd086a commit 5394da1

25 files changed

+155
-43
lines changed

jscomp/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BYTE=ocamlc.opt$(EXE)
1010
OCAMLLEX=ocamllex.opt$(EXE)
1111
CAMLP4OF=camlp4of
1212
CAMLDEP=ocamldep.opt$(EXE)
13-
COMPFLAGS= -g -w +6-40-30-23 -warn-error +a-40-30-23
13+
COMPFLAGS= -g -w +6-40-30-23 -warn-error +a-40-30-23
1414

1515

1616
.SUFFIXES: .mli .ml .cmi .cmx .mll .c .o .cmo

jscomp/bin/all_ounit_tests.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ end = struct
13421342

13431343

13441344
let reverse_range a i len =
1345-
if len=0 then ()
1345+
if len = 0 then ()
13461346
else
13471347
for k = 0 to (len-1)/2 do
13481348
let t = Array.unsafe_get a (i+k) in
@@ -1549,7 +1549,7 @@ external char_code: char -> int = "%identity"
15491549
external char_chr: int -> char = "%identity"
15501550

15511551
let escaped s =
1552-
let n = ref 0 in
1552+
let n = Pervasives.ref 0 in
15531553
for i = 0 to Bytes.length s - 1 do
15541554
n := !n +
15551555
(match Bytes.unsafe_get s i with

jscomp/bin/bsb.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ external char_code: char -> int = "%identity"
335335
external char_chr: int -> char = "%identity"
336336

337337
let escaped s =
338-
let n = ref 0 in
338+
let n = Pervasives.ref 0 in
339339
for i = 0 to Bytes.length s - 1 do
340340
n := !n +
341341
(match Bytes.unsafe_get s i with
@@ -2813,7 +2813,7 @@ end = struct
28132813

28142814

28152815
let reverse_range a i len =
2816-
if len=0 then ()
2816+
if len = 0 then ()
28172817
else
28182818
for k = 0 to (len-1)/2 do
28192819
let t = Array.unsafe_get a (i+k) in
@@ -4573,7 +4573,7 @@ module Ext_file_pp : sig
45734573
type action =
45744574
[
45754575
`skip
4576-
| `print of (out_channel -> int -> unit)
4576+
| `print of (Pervasives.out_channel -> int -> unit)
45774577
]
45784578

45794579

jscomp/bin/bsb_helper.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ external char_code: char -> int = "%identity"
301301
external char_chr: int -> char = "%identity"
302302

303303
let escaped s =
304-
let n = ref 0 in
304+
let n = Pervasives.ref 0 in
305305
for i = 0 to Bytes.length s - 1 do
306306
n := !n +
307307
(match Bytes.unsafe_get s i with

jscomp/bin/bsdep.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23127,7 +23127,7 @@ external char_code: char -> int = "%identity"
2312723127
external char_chr: int -> char = "%identity"
2312823128

2312923129
let escaped s =
23130-
let n = ref 0 in
23130+
let n = Pervasives.ref 0 in
2313123131
for i = 0 to Bytes.length s - 1 do
2313223132
n := !n +
2313323133
(match Bytes.unsafe_get s i with

jscomp/bin/bsppx.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4974,7 +4974,7 @@ external char_code: char -> int = "%identity"
49744974
external char_chr: int -> char = "%identity"
49754975

49764976
let escaped s =
4977-
let n = ref 0 in
4977+
let n = Pervasives.ref 0 in
49784978
for i = 0 to Bytes.length s - 1 do
49794979
n := !n +
49804980
(match Bytes.unsafe_get s i with

jscomp/bin/whole_compiler.ml

+10-9
Original file line numberDiff line numberDiff line change
@@ -20942,7 +20942,7 @@ external char_code: char -> int = "%identity"
2094220942
external char_chr: int -> char = "%identity"
2094320943

2094420944
let escaped s =
20945-
let n = ref 0 in
20945+
let n = Pervasives.ref 0 in
2094620946
for i = 0 to Bytes.length s - 1 do
2094720947
n := !n +
2094820948
(match Bytes.unsafe_get s i with
@@ -57204,7 +57204,7 @@ end = struct
5720457204

5720557205

5720657206
let reverse_range a i len =
57207-
if len=0 then ()
57207+
if len = 0 then ()
5720857208
else
5720957209
for k = 0 to (len-1)/2 do
5721057210
let t = Array.unsafe_get a (i+k) in
@@ -91657,6 +91657,13 @@ let translate loc
9165791657
| [ e ] -> E.int32_minus (E.zero_int_literal) e
9165891658
| _ -> assert false
9165991659
end
91660+
| Pnegint
91661+
->
91662+
begin match args with (* #977 *)
91663+
| [ e ] -> E.int32_minus (E.zero_int_literal) e
91664+
| _ -> assert false
91665+
end
91666+
9166091667
| Pnegbint Pnativeint
9166191668
->
9166291669
begin match args with
@@ -91667,13 +91674,7 @@ let translate loc
9166791674
->
9166891675
Js_long.neg args
9166991676

91670-
| Pnegint
91671-
->
91672-
begin match args with
91673-
| [ e ] -> E.unchecked_int32_minus (E.zero_int_literal) e
91674-
| _ -> assert false
91675-
end
91676-
91677+
9167791678
| Pnegfloat
9167891679
->
9167991680
begin match args with

jscomp/core/lam_compile_group.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ let lambda_as_module
367367
begin
368368
Js_config.set_current_file filename ;
369369
#if BS_DEBUG then
370-
Js_config.set_debug_file "rec_value_test.ml";
370+
Js_config.set_debug_file "gpr_977_test.ml";
371371
#end
372372
let lambda_output = compile ~filename output_prefix env sigs lam in
373373
let (//) = Filename.concat in

jscomp/core/lam_compile_primitive.ml

+8-7
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ let translate loc
8585
| [ e ] -> E.int32_minus (E.zero_int_literal) e
8686
| _ -> assert false
8787
end
88+
| Pnegint
89+
->
90+
begin match args with (* #977 *)
91+
| [ e ] -> E.int32_minus (E.zero_int_literal) e
92+
| _ -> assert false
93+
end
94+
8895
| Pnegbint Pnativeint
8996
->
9097
begin match args with
@@ -95,13 +102,7 @@ let translate loc
95102
->
96103
Js_long.neg args
97104

98-
| Pnegint
99-
->
100-
begin match args with
101-
| [ e ] -> E.unchecked_int32_minus (E.zero_int_literal) e
102-
| _ -> assert false
103-
end
104-
105+
105106
| Pnegfloat
106107
->
107108
begin match args with

jscomp/ext/ext_array.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
let reverse_range a i len =
30-
if len=0 then ()
30+
if len = 0 then ()
3131
else
3232
for k = 0 to (len-1)/2 do
3333
let t = Array.unsafe_get a (i+k) in

jscomp/ext/ext_bytes.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ external char_code: char -> int = "%identity"
3333
external char_chr: int -> char = "%identity"
3434

3535
let escaped s =
36-
let n = ref 0 in
36+
let n = Pervasives.ref 0 in
3737
for i = 0 to Bytes.length s - 1 do
3838
n := !n +
3939
(match Bytes.unsafe_get s i with

jscomp/ext/ext_file_pp.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
type action =
2626
[
2727
`skip
28-
| `print of (out_channel -> int -> unit)
28+
| `print of (Pervasives.out_channel -> int -> unit)
2929
]
3030

3131

jscomp/runtime/Readme.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Runtime support
2+
3+
The build deps are manually maintained.

jscomp/test/.depend

+3-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ event_ffi.cmj : ../stdlib/list.cmj ../runtime/js_unsafe.cmj \
128128
exception_raise_test.cmj : mt.cmj
129129
exception_value_test.cmj :
130130
ext_array.cmj : ../stdlib/list.cmj ../stdlib/array.cmj
131-
ext_bytes.cmj : ../stdlib/bytes.cmj
131+
ext_bytes.cmj : ../stdlib/pervasives.cmj ../stdlib/bytes.cmj
132132
ext_filename.cmj : ../stdlib/sys.cmj ../stdlib/string.cmj literals.cmj \
133133
../stdlib/list.cmj ../stdlib/lazy.cmj ../stdlib/filename.cmj \
134134
ext_string.cmj ext_pervasives.cmj
@@ -188,6 +188,8 @@ gpr_858_test.cmj : ../stdlib/list.cmj
188188
gpr_858_unit2_test.cmj :
189189
gpr_904_test.cmj : mt.cmj
190190
gpr_974_test.cmj : ../runtime/js.cmj
191+
gpr_977_test.cmj : ../stdlib/nativeint.cmj mt.cmj ../runtime/js.cmj \
192+
../stdlib/int32.cmj
191193
gray_code_test.cmj : ../stdlib/bytes.cmj
192194
guide_for_ext.cmj :
193195
hamming_test.cmj : ../stdlib/printf.cmj mt.cmj ../stdlib/lazy.cmj \

jscomp/test/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
7777
gray_code_test alias_test\
7878
flattern_order_test\
7979
minimal_test\
80-
gpr_1063_test
80+
gpr_1063_test\
81+
gpr_977_test
8182

8283

8384

jscomp/test/gpr_977_test.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
var Mt = require("./mt");
4+
var Block = require("../../lib/js/block");
5+
var Int32 = require("../../lib/js/int32");
6+
7+
var suites = [/* [] */0];
8+
9+
var test_id = [0];
10+
11+
function eq(loc, x, y) {
12+
test_id[0] = test_id[0] + 1 | 0;
13+
suites[0] = /* :: */[
14+
/* tuple */[
15+
loc + (" id " + test_id[0]),
16+
function () {
17+
return /* Eq */Block.__(0, [
18+
x,
19+
y
20+
]);
21+
}
22+
],
23+
suites[0]
24+
];
25+
return /* () */0;
26+
}
27+
28+
function f(x) {
29+
for(var i = 0; i <= 100; ++i){
30+
console.log(".");
31+
}
32+
return -x | 0;
33+
}
34+
35+
function int32_f(x) {
36+
for(var i = 0; i <= 100; ++i){
37+
console.log(".");
38+
}
39+
return -x | 0;
40+
}
41+
42+
function nint32_f(x) {
43+
for(var i = 0; i <= 100; ++i){
44+
console.log(".");
45+
}
46+
return -x;
47+
}
48+
49+
var u = f(-2147483648);
50+
51+
eq('File "gpr_977_test.ml", line 32, characters 5-12', -2147483648, u);
52+
53+
eq('File "gpr_977_test.ml", line 33, characters 5-12', Int32.min_int, int32_f(Int32.min_int));
54+
55+
eq('File "gpr_977_test.ml", line 34, characters 5-12', nint32_f(-2147483648), 2147483648);
56+
57+
Mt.from_pair_suites("gpr_977_test.ml", suites[0]);
58+
59+
var min_32_int = -2147483648;
60+
61+
exports.suites = suites;
62+
exports.test_id = test_id;
63+
exports.eq = eq;
64+
exports.f = f;
65+
exports.int32_f = int32_f;
66+
exports.nint32_f = nint32_f;
67+
exports.min_32_int = min_32_int;
68+
exports.u = u;
69+
/* u Not a pure module */

jscomp/test/gpr_977_test.ml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
let suites : Mt.pair_suites ref = ref []
2+
let test_id = ref 0
3+
let eq loc x y =
4+
incr test_id ;
5+
suites :=
6+
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites
7+
8+
9+
let f x =
10+
for i = 0 to 100 do
11+
Js.log "." ; (* prevent optimization*)
12+
done;
13+
- x
14+
15+
16+
let int32_f x =
17+
for i = 0 to 100 do
18+
Js.log "." ; (* prevent optimization*)
19+
done;
20+
Int32.neg x
21+
22+
let nint32_f x =
23+
for i = 0 to 100 do
24+
Js.log "." ; (* prevent optimization*)
25+
done;
26+
Nativeint.neg x
27+
28+
let min_32_int = (-2147483648)
29+
let u = f min_32_int
30+
31+
let () =
32+
eq __LOC__ min_32_int u ;
33+
eq __LOC__ (Int32.min_int) (int32_f Int32.min_int);
34+
eq __LOC__ (nint32_f (-2147483648n)) (2147483648n)
35+
let () = Mt.from_pair_suites __FILE__ !suites

jscomp/test/qcc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ function top(_param) {
15301530
}
15311531
var stk$prime_000 = /* tuple */[
15321532
match[0],
1533-
(-n << 3)
1533+
((-n | 0) << 3)
15341534
];
15351535
var stk$prime = /* :: */[
15361536
stk$prime_000,

jscomp/test/test_per.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function abs(x) {
4848
return x;
4949
}
5050
else {
51-
return -x;
51+
return -x | 0;
5252
}
5353
}
5454

@@ -409,7 +409,7 @@ function input_line(chan) {
409409
}
410410
}
411411
else {
412-
var beg = Caml_string.caml_create_string(-n);
412+
var beg = Caml_string.caml_create_string(-n | 0);
413413
(function () {
414414
throw "caml_ml_input not implemented by bucklescript yet\n";
415415
}());

lib/js/bytes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function extend(s, left, right) {
6262
var len = (s.length + left | 0) + right | 0;
6363
var r = Caml_string.caml_create_string(len);
6464
var match = left < 0 ? /* tuple */[
65-
-left,
65+
-left | 0,
6666
0
6767
] : /* tuple */[
6868
0,

lib/js/caml_int64.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function lsr_(x, numBits) {
113113
}
114114
else {
115115
var hi$1 = (hi >>> numBits);
116-
var lo$1 = (hi << -offset) | (x[/* lo */1] >>> numBits);
116+
var lo$1 = (hi << (-offset | 0)) | (x[/* lo */1] >>> numBits);
117117
return /* record */[
118118
/* hi */hi$1,
119119
/* lo */(lo$1 >>> 0)

lib/js/camlinternalFormat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5293,7 +5293,7 @@ function fmt_ebb_of_string(legacy_behavior, str) {
52935293
var match$1 = parse_positive(str_ind + 1 | 0, end_ind, 0);
52945294
return /* tuple */[
52955295
match$1[0],
5296-
-match$1[1]
5296+
-match$1[1] | 0
52975297
];
52985298
}
52995299
}

lib/js/curry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function app(_f, _args) {
1313
var d = arity$1 - len | 0;
1414
if (d) {
1515
if (d < 0) {
16-
_args = Caml_array.caml_array_sub(args, arity$1, -d);
16+
_args = Caml_array.caml_array_sub(args, arity$1, -d | 0);
1717
_f = f.apply(null, Caml_array.caml_array_sub(args, 0, arity$1));
1818
continue ;
1919

0 commit comments

Comments
 (0)