Skip to content

Commit 9985e9a

Browse files
committed
inline int64 literal
1 parent e9b0ad3 commit 9985e9a

24 files changed

+3404
-924
lines changed

jscomp/core/js_exp_make.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ val method_ : ?comment:string ->
129129
val econd : ?comment:string -> t -> t -> t -> t
130130

131131
val int : ?comment:string -> ?c:char -> int32 -> t
132+
val uint32: ?comment:string -> int32 -> t
132133
val small_int : int -> t
133134
val float : ?comment:string -> string -> t
134135

jscomp/core/js_long.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ let of_const (v : Int64.t) =
5454
| -9223372036854775808L ->
5555
E.runtime_var_dot Js_runtime_modules.int64 "min_int"
5656
| _ ->
57-
E.pure_runtime_call Js_runtime_modules.int64 "mk"
58-
[
59-
E.int (Int64.to_int32 v );
60-
E.int (Int64.to_int32 (Int64.shift_right v 32))
61-
(* signed shift right *)
62-
]
57+
let unsigned_lo = E.uint32 (Int64.to_int32 v ) in
58+
let hi = E.int (Int64.to_int32 (Int64.shift_right v 32)) in
59+
E.array Immutable [hi ;unsigned_lo]
60+
(* Assume the encoding of Int64 *)
6361

6462
let to_int32 args =
6563
int64_call "to_int32" args

jscomp/runtime/caml_format.ml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ let caml_int_of_string (s : string) : int =
125125
failwith "int_of_string");
126126
or_res
127127

128+
let hex_threshold,
129+
dec_threshold,
130+
oct_threshold,
131+
bin_threshold =
132+
1152921504606846975L,
133+
1844674407370955161L,
134+
2305843009213693951L,
135+
9223372036854775807L
128136

129137
let caml_int64_of_string s =
130138
let i, sign, hbase = parse_sign_and_base s in
@@ -133,13 +141,13 @@ let caml_int64_of_string s =
133141
let threshold =
134142
match hbase with
135143
| Hex -> (* 2 ^ 64 - 1 / 16*)
136-
1152921504606846975L
144+
hex_threshold
137145
| Dec ->
138-
1844674407370955161L
146+
dec_threshold
139147
| Oct ->
140-
2305843009213693951L
148+
oct_threshold
141149
| Bin ->
142-
9223372036854775807L
150+
bin_threshold
143151
in
144152
let len =Caml_string_extern.length s in
145153
let c = if i < len then s.!(i) else '\000' in

jscomp/test/bs_min_max_test.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,24 @@ var f5_max = Caml_obj.caml_max;
4545

4646
b("File \"bs_min_max_test.ml\", line 28, characters 4-11", Caml_int64.eq(Caml_int64.min(Caml_int64.zero, Caml_int64.one), Caml_int64.zero));
4747

48-
b("File \"bs_min_max_test.ml\", line 29, characters 4-11", Caml_int64.eq(Caml_int64.max(/* @__PURE__ */Caml_int64.mk(22, 0), Caml_int64.one), /* @__PURE__ */Caml_int64.mk(22, 0)));
49-
50-
b("File \"bs_min_max_test.ml\", line 30, characters 4-11", Caml_int64.eq(Caml_int64.max(/* @__PURE__ */Caml_int64.mk(-3, -1), /* @__PURE__ */Caml_int64.mk(3, 0)), /* @__PURE__ */Caml_int64.mk(3, 0)));
48+
b("File \"bs_min_max_test.ml\", line 29, characters 4-11", Caml_int64.eq(Caml_int64.max([
49+
0,
50+
22
51+
], Caml_int64.one), [
52+
0,
53+
22
54+
]));
55+
56+
b("File \"bs_min_max_test.ml\", line 30, characters 4-11", Caml_int64.eq(Caml_int64.max([
57+
-1,
58+
4294967293
59+
], [
60+
0,
61+
3
62+
]), [
63+
0,
64+
3
65+
]));
5166

5267
eq("File \"bs_min_max_test.ml\", line 31, characters 5-12", Caml_obj.caml_min(undefined, 3), undefined);
5368

jscomp/test/caml_format_test.js

Lines changed: 99 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,10 @@ var int64_suites_1 = {
20852085
_3: /* End_of_format */0
20862086
},
20872087
_1: "%Ld"
2088-
}), /* @__PURE__ */Caml_int64.mk(3, 0)),
2088+
}), [
2089+
0,
2090+
3
2091+
]),
20892092
_1: "3"
20902093
};
20912094
})
@@ -2105,7 +2108,10 @@ var int64_suites_1 = {
21052108
_3: /* End_of_format */0
21062109
},
21072110
_1: "%Lx"
2108-
}), /* @__PURE__ */Caml_int64.mk(33, 0)),
2111+
}), [
2112+
0,
2113+
33
2114+
]),
21092115
_1: "21"
21102116
};
21112117
})
@@ -2125,7 +2131,10 @@ var int64_suites_1 = {
21252131
_3: /* End_of_format */0
21262132
},
21272133
_1: "%Li"
2128-
}), /* @__PURE__ */Caml_int64.mk(33, 0)),
2134+
}), [
2135+
0,
2136+
33
2137+
]),
21292138
_1: "33"
21302139
};
21312140
})
@@ -2145,7 +2154,10 @@ var int64_suites_1 = {
21452154
_3: /* End_of_format */0
21462155
},
21472156
_1: "%LX"
2148-
}), /* @__PURE__ */Caml_int64.mk(44, 0)),
2157+
}), [
2158+
0,
2159+
44
2160+
]),
21492161
_1: "2C"
21502162
};
21512163
})
@@ -2165,7 +2177,10 @@ var int64_suites_1 = {
21652177
_3: /* End_of_format */0
21662178
},
21672179
_1: "%Lx"
2168-
}), /* @__PURE__ */Caml_int64.mk(44, 0)),
2180+
}), [
2181+
0,
2182+
44
2183+
]),
21692184
_1: "2c"
21702185
};
21712186
})
@@ -2188,7 +2203,10 @@ var int64_suites_1 = {
21882203
_3: /* End_of_format */0
21892204
},
21902205
_1: "%*Lx"
2191-
}), 5, /* @__PURE__ */Caml_int64.mk(44, 0)),
2206+
}), 5, [
2207+
0,
2208+
44
2209+
]),
21922210
_1: " 2c"
21932211
};
21942212
})
@@ -2199,7 +2217,10 @@ var int64_suites_1 = {
21992217
(function (param) {
22002218
return {
22012219
TAG: /* Eq */0,
2202-
_0: Caml_int64.to_string(/* @__PURE__ */Caml_int64.mk(3333, 0)),
2220+
_0: Caml_int64.to_string([
2221+
0,
2222+
3333
2223+
]),
22032224
_1: "3333"
22042225
};
22052226
})
@@ -2229,7 +2250,13 @@ var int64_suites_1 = {
22292250
}
22302251
},
22312252
_1: "%Ld%018Ld"
2232-
}), /* @__PURE__ */Caml_int64.mk(3, 0), /* @__PURE__ */Caml_int64.mk(3, 0)),
2253+
}), [
2254+
0,
2255+
3
2256+
], [
2257+
0,
2258+
3
2259+
]),
22332260
_1: "3000000000000000003"
22342261
};
22352262
})
@@ -2259,7 +2286,10 @@ var int64_suites_1 = {
22592286
}
22602287
},
22612288
_1: "%Ld%018Ld"
2262-
}), /* @__PURE__ */Caml_int64.mk(1548746752, 107288), Caml_int64.zero),
2289+
}), [
2290+
107288,
2291+
1548746752
2292+
], Caml_int64.zero),
22632293
_1: "460800000000000000000000000000000"
22642294
};
22652295
})
@@ -2319,7 +2349,10 @@ var int64_suites_1 = {
23192349
_3: /* End_of_format */0
23202350
},
23212351
_1: "%Ld"
2322-
}), /* @__PURE__ */Caml_int64.mk(-11111, -1)),
2352+
}), [
2353+
-1,
2354+
4294956185
2355+
]),
23232356
_1: "-11111"
23242357
};
23252358
})
@@ -2439,7 +2472,10 @@ var int64_suites_1 = {
24392472
_3: /* End_of_format */0
24402473
},
24412474
_1: "%Lu"
2442-
}), /* @__PURE__ */Caml_int64.mk(-100, -1)),
2475+
}), [
2476+
-1,
2477+
4294967196
2478+
]),
24432479
_1: "18446744073709551516"
24442480
};
24452481
})
@@ -2479,7 +2515,10 @@ var int64_suites_1 = {
24792515
_3: /* End_of_format */0
24802516
},
24812517
_1: "%Lu"
2482-
}), /* @__PURE__ */Caml_int64.mk(-10000, -1)),
2518+
}), [
2519+
-1,
2520+
4294957296
2521+
]),
24832522
_1: "18446744073709541616"
24842523
};
24852524
})
@@ -2543,7 +2582,10 @@ var int64_suites_1 = {
25432582
_3: /* End_of_format */0
25442583
},
25452584
_1: "%12Lx"
2546-
}), /* @__PURE__ */Caml_int64.mk(3, 0)),
2585+
}), [
2586+
0,
2587+
3
2588+
]),
25472589
_1: " 3"
25482590
};
25492591
})
@@ -2563,7 +2605,10 @@ var int64_suites_1 = {
25632605
_3: /* End_of_format */0
25642606
},
25652607
_1: "%LX"
2566-
}), /* @__PURE__ */Caml_int64.mk(1163551168, 1859194407)),
2608+
}), [
2609+
1859194407,
2610+
1163551168
2611+
]),
25672612
_1: "6ED10E27455A61C0"
25682613
};
25692614
})
@@ -2587,7 +2632,10 @@ var int64_suites_1 = {
25872632
}
25882633
},
25892634
_1: "%Ld\n"
2590-
}), /* @__PURE__ */Caml_int64.mk(32, 0)),
2635+
}), [
2636+
0,
2637+
32
2638+
]),
25912639
_1: "32\n"
25922640
};
25932641
})
@@ -2612,7 +2660,10 @@ var int64_suites_1 = {
26122660
}
26132661
},
26142662
_1: "%Ld\n"
2615-
}), /* @__PURE__ */Caml_int64.mk(32, 0)), $$Buffer.contents(buf)),
2663+
}), [
2664+
0,
2665+
32
2666+
]), $$Buffer.contents(buf)),
26162667
_1: "32\n"
26172668
};
26182669
})
@@ -2657,31 +2708,49 @@ var of_string_data = [
26572708
"0"
26582709
],
26592710
[
2660-
/* @__PURE__ */Caml_int64.mk(3, 0),
2711+
[
2712+
0,
2713+
3
2714+
],
26612715
"3"
26622716
],
26632717
[
2664-
/* @__PURE__ */Caml_int64.mk(33, 0),
2718+
[
2719+
0,
2720+
33
2721+
],
26652722
"33"
26662723
],
26672724
[
2668-
/* @__PURE__ */Caml_int64.mk(333, 0),
2725+
[
2726+
0,
2727+
333
2728+
],
26692729
"33_3"
26702730
],
26712731
[
2672-
/* @__PURE__ */Caml_int64.mk(33333, 0),
2732+
[
2733+
0,
2734+
33333
2735+
],
26732736
"33_33_3"
26742737
],
26752738
[
2676-
/* @__PURE__ */Caml_int64.mk(-1674115755, 77),
2739+
[
2740+
77,
2741+
2620851541
2742+
],
26772743
"333333333333"
26782744
],
26792745
[
26802746
Caml_int64.neg_one,
26812747
"0xffff_ffff_ffff_ffff"
26822748
],
26832749
[
2684-
/* @__PURE__ */Caml_int64.mk(113, 0),
2750+
[
2751+
0,
2752+
113
2753+
],
26852754
"0b01110001"
26862755
],
26872756
[
@@ -2756,9 +2825,15 @@ var float_suites = {
27562825
tl: /* [] */0
27572826
};
27582827

2759-
var hh = /* @__PURE__ */Caml_int64.mk(-858993460, 214748364);
2828+
var hh = [
2829+
214748364,
2830+
3435973836
2831+
];
27602832

2761-
var hhh = /* @__PURE__ */Caml_int64.mk(0, 268435456);
2833+
var hhh = [
2834+
268435456,
2835+
0
2836+
];
27622837

27632838
exports.of_string = of_string;
27642839
exports.from_float_of_string = from_float_of_string;

jscomp/test/div_by_zero_test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ add([
9696
return {
9797
TAG: /* ThrowAny */7,
9898
_0: (function (param) {
99-
Caml_int64.div(/* @__PURE__ */Caml_int64.mk(3, 0), Caml_int64.zero);
99+
Caml_int64.div([
100+
0,
101+
3
102+
], Caml_int64.zero);
100103

101104
})
102105
};
@@ -109,7 +112,10 @@ add([
109112
return {
110113
TAG: /* ThrowAny */7,
111114
_0: (function (param) {
112-
Caml_int64.mod_(/* @__PURE__ */Caml_int64.mk(3, 0), Caml_int64.zero);
115+
Caml_int64.mod_([
116+
0,
117+
3
118+
], Caml_int64.zero);
113119

114120
})
115121
};

jscomp/test/float_of_bits_test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ var Caml_float = require("../../lib/js/caml_float.js");
99
var Caml_int64 = require("../../lib/js/caml_int64.js");
1010
var Pervasives = require("../../lib/js/pervasives.js");
1111

12-
var one_float = /* @__PURE__ */Caml_int64.mk(0, 1072693248);
12+
var one_float = [
13+
1072693248,
14+
0
15+
];
1316

1417
var int32_pairs = [
1518
[

0 commit comments

Comments
 (0)