Skip to content

Commit b9e3f33

Browse files
Use native bigint type
1 parent 6725ea4 commit b9e3f33

21 files changed

+64
-73
lines changed

package-lock.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
"src/**/*.mjs"
2525
],
2626
"peerDependencies": {
27-
"rescript": ">=11.0.0 || ^11.1.0-rc.2"
27+
"rescript": "^11.1.0-rc.6"
2828
},
2929
"devDependencies": {
3030
"@babel/code-frame": "7.18.6",
3131
"@rescript/tools": "^0.5.0",
32-
"rescript": "11.1.0-rc.2"
32+
"rescript": "11.1.0-rc.6"
3333
}
3434
}

scripts/DocTests.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function prepareCompiler() {
6565
stdio: "ignore",
6666
cwd: compilerDir
6767
});
68-
var dict = JSON.parse(Fs.readFileSync(Path.join(corePath, "package.json")), undefined);
68+
var dict = JSON.parse(Fs.readFileSync(Path.join(corePath, "package.json")));
6969
var currentCoreVersion;
7070
if (!Array.isArray(dict) && (dict === null || typeof dict !== "object") && typeof dict !== "number" && typeof dict !== "string" && typeof dict !== "boolean") {
7171
throw {
@@ -179,7 +179,7 @@ function extractDocFromFile(file) {
179179
"doc",
180180
file
181181
]);
182-
return Tools_Docgen.decodeFromJson(JSON.parse(spawn.stdout.toString(), undefined));
182+
return Tools_Docgen.decodeFromJson(JSON.parse(spawn.stdout.toString()));
183183
}
184184

185185
function getExamples(param) {

src/Core__BigInt.res

+24-26
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
1-
type t = Js.Types.bigint_val
1+
@val external asIntN: (~width: int, bigint) => bigint = "BigInt.asIntN"
2+
@val external asUintN: (~width: int, bigint) => bigint = "BigInt.asUintN"
23

3-
@val external asIntN: (~width: int, t) => t = "BigInt.asIntN"
4-
@val external asUintN: (~width: int, t) => t = "BigInt.asUintN"
4+
@val external fromString: string => bigint = "BigInt"
5+
@val external fromInt: int => bigint = "BigInt"
6+
@val external fromFloat: float => bigint = "BigInt"
57

6-
@val external fromString: string => t = "BigInt"
7-
@val external fromInt: int => t = "BigInt"
8-
@val external fromFloat: float => t = "BigInt"
8+
@send external toString: bigint => string = "toString"
9+
@send external toStringWithRadix: (bigint, ~radix: int) => string = "toString"
10+
@send external toLocaleString: bigint => string = "toLocaleString"
911

10-
@send external toString: t => string = "toString"
11-
@send external toStringWithRadix: (t, ~radix: int) => string = "toString"
12-
@send external toLocaleString: t => string = "toLocaleString"
13-
14-
@val external toFloat: t => float = "Number"
12+
@val external toFloat: bigint => float = "Number"
1513

1614
let toInt = t => t->toFloat->Core__Int.fromFloat
1715

18-
external \"+": (t, t) => t = "%addfloat"
19-
external \"-": (t, t) => t = "%subfloat"
20-
external \"*": (t, t) => t = "%mulfloat"
21-
external \"/": (t, t) => t = "%divfloat"
16+
external \"+": (bigint, bigint) => bigint = "%addfloat"
17+
external \"-": (bigint, bigint) => bigint = "%subfloat"
18+
external \"*": (bigint, bigint) => bigint = "%mulfloat"
19+
external \"/": (bigint, bigint) => bigint = "%divfloat"
2220

23-
external add: (t, t) => t = "%addfloat"
24-
external sub: (t, t) => t = "%subfloat"
25-
external mul: (t, t) => t = "%mulfloat"
26-
external div: (t, t) => t = "%divfloat"
21+
external add: (bigint, bigint) => bigint = "%addfloat"
22+
external sub: (bigint, bigint) => bigint = "%subfloat"
23+
external mul: (bigint, bigint) => bigint = "%mulfloat"
24+
external div: (bigint, bigint) => bigint = "%divfloat"
2725

28-
@noalloc external mod: (t, t) => t = "?fmod_float"
26+
@noalloc external mod: (bigint, bigint) => bigint = "?fmod_float"
2927

30-
external land: (t, t) => t = "%andint"
31-
external lor: (t, t) => t = "%orint"
32-
external lxor: (t, t) => t = "%xorint"
28+
external land: (bigint, bigint) => bigint = "%andint"
29+
external lor: (bigint, bigint) => bigint = "%orint"
30+
external lxor: (bigint, bigint) => bigint = "%xorint"
3331

34-
external lsl: (t, t) => t = "%lslint"
35-
external asr: (t, t) => t = "%asrint"
32+
external lsl: (bigint, bigint) => bigint = "%lslint"
33+
external asr: (bigint, bigint) => bigint = "%asrint"
3634

37-
let exp = (x: t, y: t) => {
35+
let exp = (x: bigint, y: bigint) => {
3836
let _ = x
3937
let _ = y
4038
%raw(`x ** y`)

src/Core__DataView.res

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: i
2020
@send external getFloat32: t => float = "getFloat32"
2121
@send external getFloat64: t => float = "getFloat64"
2222

23-
@send external getBigInt64: t => Core__BigInt.t = "getBigInt64"
24-
@send external getBigUint64: t => Core__BigInt.t = "getBigUint64"
23+
@send external getBigInt64: t => bigint = "getBigInt64"
24+
@send external getBigUint64: t => bigint = "getBigUint64"
2525

2626
@send external setInt8: (t, int) => unit = "setInt8"
2727
@send external setUint8: (t, int) => unit = "setUint8"
@@ -33,5 +33,5 @@ external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: i
3333
@send external setFloat32: (t, float) => unit = "setFloat32"
3434
@send external setFloat64: (t, float) => unit = "setFloat64"
3535

36-
@send external setBigInt64: (t, Core__BigInt.t) => unit = "setBigInt64"
37-
@send external setBigUint64: (t, Core__BigInt.t) => unit = "setBigUint64"
36+
@send external setBigInt64: (t, bigint) => unit = "setBigInt64"
37+
@send external setBigUint64: (t, bigint) => unit = "setBigUint64"

src/Core__Type.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Classify = {
1515
| Object(object)
1616
| Function(function)
1717
| Symbol(Core__Symbol.t)
18-
| BigInt(Core__BigInt.t)
18+
| BigInt(bigint)
1919

2020
@val external _internalClass: 'a => string = "Object.prototype.toString.call"
2121
external _asBool: 'a => bool = "%identity"
@@ -24,7 +24,7 @@ module Classify = {
2424
external _asObject: 'a => object = "%identity"
2525
external _asFunction: 'a => function = "%identity"
2626
external _asSymbol: 'a => Core__Symbol.t = "%identity"
27-
external _asBigInt: 'a => Core__BigInt.t = "%identity"
27+
external _asBigInt: 'a => bigint = "%identity"
2828

2929
let classify = value => {
3030
switch _internalClass(value) {

src/Core__Type.resi

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module Classify: {
5959
| Object(object)
6060
| Function(function)
6161
| Symbol(Core__Symbol.t)
62-
| BigInt(Core__BigInt.t)
62+
| BigInt(bigint)
6363

6464
/**
6565
`classify(anyValue)`

src/intl/Core__Intl__NumberFormat.res

+5-9
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,16 @@ external formatIntToParts: (t, int) => array<numberFormatPart> = "formatToParts"
194194
external formatIntRangeToParts: (t, ~start: int, ~end: int) => array<numberFormatRangePart> =
195195
"formatRange"
196196

197-
@send external formatBigInt: (t, Core__BigInt.t) => string = "format"
197+
@send external formatBigInt: (t, bigint) => string = "format"
198198

199199
@send
200-
external formatBigIntRange: (t, ~start: Core__BigInt.t, ~end: Core__BigInt.t) => array<string> =
201-
"formatRange"
200+
external formatBigIntRange: (t, ~start: bigint, ~end: bigint) => array<string> = "formatRange"
202201
@send
203-
external formatBigIntToParts: (t, Core__BigInt.t) => array<numberFormatPart> = "formatToParts"
202+
external formatBigIntToParts: (t, bigint) => array<numberFormatPart> = "formatToParts"
204203

205204
@send
206-
external formatBigIntRangeToParts: (
207-
t,
208-
~start: Core__BigInt.t,
209-
~end: Core__BigInt.t,
210-
) => array<numberFormatPart> = "formatRange"
205+
external formatBigIntRangeToParts: (t, ~start: bigint, ~end: bigint) => array<numberFormatPart> =
206+
"formatRange"
211207

212208
@send external formatString: (t, string) => string = "format"
213209

src/intl/Core__Intl__PluralRules.res

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type rule = [#zero | #one | #two | #few | #many | #other]
5050

5151
@send external select: (t, float) => rule = "select"
5252
@send external selectInt: (t, int) => rule = "select"
53-
@send external selectBigInt: (t, Core__BigInt.t) => rule = "select"
53+
@send external selectBigInt: (t, bigint) => rule = "select"
5454

5555
@send
5656
external selectRange: (t, ~start: float, ~end: float) => rule = "selectRange"
@@ -59,5 +59,4 @@ external selectRange: (t, ~start: float, ~end: float) => rule = "selectRange"
5959
external selectRangeInt: (t, ~start: int, ~end: int) => rule = "selectRange"
6060

6161
@send
62-
external selectRangeBigInt: (t, ~start: Core__BigInt.t, ~end: Core__BigInt.t) => rule =
63-
"selectRange"
62+
external selectRangeBigInt: (t, ~start: bigint, ~end: bigint) => rule = "selectRange"

src/typed-arrays/Core__BigInt64Array.res

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** The `BigInt64Array` typed array represents an array of 64-bit signed integers in platform byte order. See [BigInt64Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array)
22
*/
3-
type t = Core__TypedArray.t<Core__BigInt.t>
3+
type t = Core__TypedArray.t<bigint>
44

55
module Constants = {
66
/**`bytesPerElement` returns the element size. See [BYTES_PER_ELEMENT on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT)
@@ -12,7 +12,7 @@ module Constants = {
1212
/** `fromArray` creates a `BigInt64Array` from an array of values. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array/BigInt64Array)
1313
*/
1414
@new
15-
external fromArray: array<Core__BigInt.t> => t = "BigInt64Array"
15+
external fromArray: array<bigint> => t = "BigInt64Array"
1616

1717
/** `fromBuffer` creates a `BigInt64Array` from an `ArrayBuffer.t`. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array/BigInt64Array)
1818
@@ -51,5 +51,4 @@ external fromArrayLikeOrIterable: 'a => t = "BigInt64Array.from"
5151
/** `fromArrayLikeOrIterableWithMap` creates a `BigInt64Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from)
5252
*/
5353
@val
54-
external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => Core__BigInt.t) => t =
55-
"BigInt64Array.from"
54+
external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => bigint) => t = "BigInt64Array.from"

src/typed-arrays/Core__BigUint64Array.res

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** The `BigUint64Array` typed array represents an array of 64-bit unsigned integers in platform byte order. See [BigUint64Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array)
22
*/
3-
type t = Core__TypedArray.t<Core__BigInt.t>
3+
type t = Core__TypedArray.t<bigint>
44

55
module Constants = {
66
/**`bytesPerElement` returns the element size. See [BYTES_PER_ELEMENT on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT)
@@ -12,7 +12,7 @@ module Constants = {
1212
/** `fromArray` creates a `BigUint64Array` from an array of values. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array/BigUint64Array)
1313
*/
1414
@new
15-
external fromArray: array<Core__BigInt.t> => t = "BigUint64Array"
15+
external fromArray: array<bigint> => t = "BigUint64Array"
1616

1717
/** `fromBuffer` creates a `BigUint64Array` from an `ArrayBuffer.t`. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array/BigUint64Array)
1818
@@ -51,5 +51,4 @@ external fromArrayLikeOrIterable: 'a => t = "BigUint64Array.from"
5151
/** `fromArrayLikeOrIterableWithMap` creates a `BigUint64Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from)
5252
*/
5353
@val
54-
external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => Core__BigInt.t) => t =
55-
"BigUint64Array.from"
54+
external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => bigint) => t = "BigUint64Array.from"

test/ObjectTests.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ Test.run([
386386
32
387387
],
388388
"is: bigint"
389-
], Caml_obj.equal(BigInt("123"), BigInt("123")), eq, true);
389+
], BigInt("123") === BigInt("123"), eq, true);
390390

391391
Test.run([
392392
[

test/TempTests.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ console.info("JSON");
9898

9999
console.info("---");
100100

101-
var json = JSON.parse("{\"foo\": \"bar\"}", undefined);
101+
var json = JSON.parse("{\"foo\": \"bar\"}");
102102

103103
var json$1 = Core__JSON.Classify.classify(json);
104104

test/Test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function print(value) {
1313
if (match === "object" || match === "bigint") {
1414
return Util.inspect(value);
1515
} else if (match === "string") {
16-
return Core__Option.getExn(JSON.stringify(value, undefined, undefined));
16+
return Core__Option.getExn(JSON.stringify(value));
1717
} else {
1818
return String(value);
1919
}

test/TypedArrayTests.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let assertWillThrow = (message, f) => {
3232
}
3333
}
3434

35-
let areSame = (x: BigInt.t, y: BigInt.t) => BigInt.toString(x) == BigInt.toString(y)
35+
let areSame = (x: bigint, y: bigint) => BigInt.toString(x) == BigInt.toString(y)
3636

3737
// What's going on here?
3838
// assertTrue("big ints if different then not equal", () => num1 != num2)

test/intl/Intl__CollatorTest.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var collator = new Intl.Collator(["en-US"], {
2424
Intl.Collator.supportedLocalesOf([
2525
"en-US",
2626
"en-GB"
27-
], undefined);
27+
]);
2828

2929
Intl.Collator.supportedLocalesOf([
3030
"en-US",
@@ -37,7 +37,7 @@ console.log(collator.resolvedOptions());
3737

3838
console.log(collator.compare("hi", "hï"));
3939

40-
console.log(Intl.Collator.supportedLocalesOf(["hi"], undefined));
40+
console.log(Intl.Collator.supportedLocalesOf(["hi"]));
4141

4242
export {
4343
_collator ,

test/intl/Intl__DateTimeFormatTest.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ console.log("Intl.DateTimeFormat");
99
Intl.DateTimeFormat.supportedLocalesOf([
1010
"en-US",
1111
"en-GB"
12-
], undefined);
12+
]);
1313

1414
Intl.DateTimeFormat.supportedLocalesOf([
1515
"en-US",

test/intl/Intl__ListFormatTest.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var _formatter = new Intl.ListFormat([
2323
Intl.ListFormat.supportedLocalesOf([
2424
"en-US",
2525
"en-GB"
26-
], undefined);
26+
]);
2727

2828
Intl.ListFormat.supportedLocalesOf([
2929
"en-US",

test/intl/Intl__NumberFormatTest.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var currencyFormatter = new Intl.NumberFormat(["fr-FR"], {
1515
console.log(Intl.NumberFormat.supportedLocalesOf([
1616
"fr-FR",
1717
"en-US"
18-
], undefined));
18+
]));
1919

2020
console.log(currencyFormatter.format(123.23));
2121

test/intl/Intl__RelativeTimeFormatTest.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ console.log("Intl.RelativeTimeFormat");
88
Intl.RelativeTimeFormat.supportedLocalesOf([
99
"en-US",
1010
"en-GB"
11-
], undefined);
11+
]);
1212

1313
Intl.RelativeTimeFormat.supportedLocalesOf([
1414
"en-US",

test/intl/Intl__SegmenterTest.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ console.log("Intl.Segmenter");
88
Intl.Segmenter.supportedLocalesOf([
99
"en-US",
1010
"en-GB"
11-
], undefined);
11+
]);
1212

1313
Intl.Segmenter.supportedLocalesOf([
1414
"en-US",

0 commit comments

Comments
 (0)