Skip to content

Commit

Permalink
Use native bigint type
Browse files Browse the repository at this point in the history
  • Loading branch information
fhammerschmidt committed Apr 2, 2024
1 parent 6725ea4 commit b9e3f33
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 73 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
"src/**/*.mjs"
],
"peerDependencies": {
"rescript": ">=11.0.0 || ^11.1.0-rc.2"
"rescript": "^11.1.0-rc.6"
},
"devDependencies": {
"@babel/code-frame": "7.18.6",
"@rescript/tools": "^0.5.0",
"rescript": "11.1.0-rc.2"
"rescript": "11.1.0-rc.6"
}
}
4 changes: 2 additions & 2 deletions scripts/DocTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function prepareCompiler() {
stdio: "ignore",
cwd: compilerDir
});
var dict = JSON.parse(Fs.readFileSync(Path.join(corePath, "package.json")), undefined);
var dict = JSON.parse(Fs.readFileSync(Path.join(corePath, "package.json")));
var currentCoreVersion;
if (!Array.isArray(dict) && (dict === null || typeof dict !== "object") && typeof dict !== "number" && typeof dict !== "string" && typeof dict !== "boolean") {
throw {
Expand Down Expand Up @@ -179,7 +179,7 @@ function extractDocFromFile(file) {
"doc",
file
]);
return Tools_Docgen.decodeFromJson(JSON.parse(spawn.stdout.toString(), undefined));
return Tools_Docgen.decodeFromJson(JSON.parse(spawn.stdout.toString()));
}

function getExamples(param) {
Expand Down
50 changes: 24 additions & 26 deletions src/Core__BigInt.res
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
type t = Js.Types.bigint_val
@val external asIntN: (~width: int, bigint) => bigint = "BigInt.asIntN"
@val external asUintN: (~width: int, bigint) => bigint = "BigInt.asUintN"

@val external asIntN: (~width: int, t) => t = "BigInt.asIntN"
@val external asUintN: (~width: int, t) => t = "BigInt.asUintN"
@val external fromString: string => bigint = "BigInt"
@val external fromInt: int => bigint = "BigInt"
@val external fromFloat: float => bigint = "BigInt"

@val external fromString: string => t = "BigInt"
@val external fromInt: int => t = "BigInt"
@val external fromFloat: float => t = "BigInt"
@send external toString: bigint => string = "toString"
@send external toStringWithRadix: (bigint, ~radix: int) => string = "toString"
@send external toLocaleString: bigint => string = "toLocaleString"

@send external toString: t => string = "toString"
@send external toStringWithRadix: (t, ~radix: int) => string = "toString"
@send external toLocaleString: t => string = "toLocaleString"

@val external toFloat: t => float = "Number"
@val external toFloat: bigint => float = "Number"

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

external \"+": (t, t) => t = "%addfloat"
external \"-": (t, t) => t = "%subfloat"
external \"*": (t, t) => t = "%mulfloat"
external \"/": (t, t) => t = "%divfloat"
external \"+": (bigint, bigint) => bigint = "%addfloat"
external \"-": (bigint, bigint) => bigint = "%subfloat"
external \"*": (bigint, bigint) => bigint = "%mulfloat"
external \"/": (bigint, bigint) => bigint = "%divfloat"

external add: (t, t) => t = "%addfloat"
external sub: (t, t) => t = "%subfloat"
external mul: (t, t) => t = "%mulfloat"
external div: (t, t) => t = "%divfloat"
external add: (bigint, bigint) => bigint = "%addfloat"
external sub: (bigint, bigint) => bigint = "%subfloat"
external mul: (bigint, bigint) => bigint = "%mulfloat"
external div: (bigint, bigint) => bigint = "%divfloat"

@noalloc external mod: (t, t) => t = "?fmod_float"
@noalloc external mod: (bigint, bigint) => bigint = "?fmod_float"

external land: (t, t) => t = "%andint"
external lor: (t, t) => t = "%orint"
external lxor: (t, t) => t = "%xorint"
external land: (bigint, bigint) => bigint = "%andint"
external lor: (bigint, bigint) => bigint = "%orint"
external lxor: (bigint, bigint) => bigint = "%xorint"

external lsl: (t, t) => t = "%lslint"
external asr: (t, t) => t = "%asrint"
external lsl: (bigint, bigint) => bigint = "%lslint"
external asr: (bigint, bigint) => bigint = "%asrint"

let exp = (x: t, y: t) => {
let exp = (x: bigint, y: bigint) => {
let _ = x
let _ = y
%raw(`x ** y`)
Expand Down
8 changes: 4 additions & 4 deletions src/Core__DataView.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: i
@send external getFloat32: t => float = "getFloat32"
@send external getFloat64: t => float = "getFloat64"

@send external getBigInt64: t => Core__BigInt.t = "getBigInt64"
@send external getBigUint64: t => Core__BigInt.t = "getBigUint64"
@send external getBigInt64: t => bigint = "getBigInt64"
@send external getBigUint64: t => bigint = "getBigUint64"

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

@send external setBigInt64: (t, Core__BigInt.t) => unit = "setBigInt64"
@send external setBigUint64: (t, Core__BigInt.t) => unit = "setBigUint64"
@send external setBigInt64: (t, bigint) => unit = "setBigInt64"
@send external setBigUint64: (t, bigint) => unit = "setBigUint64"
4 changes: 2 additions & 2 deletions src/Core__Type.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Classify = {
| Object(object)
| Function(function)
| Symbol(Core__Symbol.t)
| BigInt(Core__BigInt.t)
| BigInt(bigint)

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

let classify = value => {
switch _internalClass(value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core__Type.resi
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module Classify: {
| Object(object)
| Function(function)
| Symbol(Core__Symbol.t)
| BigInt(Core__BigInt.t)
| BigInt(bigint)

/**
`classify(anyValue)`
Expand Down
14 changes: 5 additions & 9 deletions src/intl/Core__Intl__NumberFormat.res
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,16 @@ external formatIntToParts: (t, int) => array<numberFormatPart> = "formatToParts"
external formatIntRangeToParts: (t, ~start: int, ~end: int) => array<numberFormatRangePart> =
"formatRange"

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

@send
external formatBigIntRange: (t, ~start: Core__BigInt.t, ~end: Core__BigInt.t) => array<string> =
"formatRange"
external formatBigIntRange: (t, ~start: bigint, ~end: bigint) => array<string> = "formatRange"
@send
external formatBigIntToParts: (t, Core__BigInt.t) => array<numberFormatPart> = "formatToParts"
external formatBigIntToParts: (t, bigint) => array<numberFormatPart> = "formatToParts"

@send
external formatBigIntRangeToParts: (
t,
~start: Core__BigInt.t,
~end: Core__BigInt.t,
) => array<numberFormatPart> = "formatRange"
external formatBigIntRangeToParts: (t, ~start: bigint, ~end: bigint) => array<numberFormatPart> =
"formatRange"

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

Expand Down
5 changes: 2 additions & 3 deletions src/intl/Core__Intl__PluralRules.res
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type rule = [#zero | #one | #two | #few | #many | #other]

@send external select: (t, float) => rule = "select"
@send external selectInt: (t, int) => rule = "select"
@send external selectBigInt: (t, Core__BigInt.t) => rule = "select"
@send external selectBigInt: (t, bigint) => rule = "select"

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

@send
external selectRangeBigInt: (t, ~start: Core__BigInt.t, ~end: Core__BigInt.t) => rule =
"selectRange"
external selectRangeBigInt: (t, ~start: bigint, ~end: bigint) => rule = "selectRange"
7 changes: 3 additions & 4 deletions src/typed-arrays/Core__BigInt64Array.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** 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)
*/
type t = Core__TypedArray.t<Core__BigInt.t>
type t = Core__TypedArray.t<bigint>

module Constants = {
/**`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)
Expand All @@ -12,7 +12,7 @@ module Constants = {
/** `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)
*/
@new
external fromArray: array<Core__BigInt.t> => t = "BigInt64Array"
external fromArray: array<bigint> => t = "BigInt64Array"

/** `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)
Expand Down Expand Up @@ -51,5 +51,4 @@ external fromArrayLikeOrIterable: 'a => t = "BigInt64Array.from"
/** `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)
*/
@val
external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => Core__BigInt.t) => t =
"BigInt64Array.from"
external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => bigint) => t = "BigInt64Array.from"
7 changes: 3 additions & 4 deletions src/typed-arrays/Core__BigUint64Array.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** 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)
*/
type t = Core__TypedArray.t<Core__BigInt.t>
type t = Core__TypedArray.t<bigint>

module Constants = {
/**`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)
Expand All @@ -12,7 +12,7 @@ module Constants = {
/** `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)
*/
@new
external fromArray: array<Core__BigInt.t> => t = "BigUint64Array"
external fromArray: array<bigint> => t = "BigUint64Array"

/** `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)
Expand Down Expand Up @@ -51,5 +51,4 @@ external fromArrayLikeOrIterable: 'a => t = "BigUint64Array.from"
/** `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)
*/
@val
external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => Core__BigInt.t) => t =
"BigUint64Array.from"
external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => bigint) => t = "BigUint64Array.from"
2 changes: 1 addition & 1 deletion test/ObjectTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ Test.run([
32
],
"is: bigint"
], Caml_obj.equal(BigInt("123"), BigInt("123")), eq, true);
], BigInt("123") === BigInt("123"), eq, true);

Test.run([
[
Expand Down
2 changes: 1 addition & 1 deletion test/TempTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ console.info("JSON");

console.info("---");

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/Test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function print(value) {
if (match === "object" || match === "bigint") {
return Util.inspect(value);
} else if (match === "string") {
return Core__Option.getExn(JSON.stringify(value, undefined, undefined));
return Core__Option.getExn(JSON.stringify(value));
} else {
return String(value);
}
Expand Down
2 changes: 1 addition & 1 deletion test/TypedArrayTests.res
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let assertWillThrow = (message, f) => {
}
}

let areSame = (x: BigInt.t, y: BigInt.t) => BigInt.toString(x) == BigInt.toString(y)
let areSame = (x: bigint, y: bigint) => BigInt.toString(x) == BigInt.toString(y)

// What's going on here?
// assertTrue("big ints if different then not equal", () => num1 != num2)
Expand Down
4 changes: 2 additions & 2 deletions test/intl/Intl__CollatorTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var collator = new Intl.Collator(["en-US"], {
Intl.Collator.supportedLocalesOf([
"en-US",
"en-GB"
], undefined);
]);

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

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

console.log(Intl.Collator.supportedLocalesOf(["hi"], undefined));
console.log(Intl.Collator.supportedLocalesOf(["hi"]));

export {
_collator ,
Expand Down
2 changes: 1 addition & 1 deletion test/intl/Intl__DateTimeFormatTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ console.log("Intl.DateTimeFormat");
Intl.DateTimeFormat.supportedLocalesOf([
"en-US",
"en-GB"
], undefined);
]);

Intl.DateTimeFormat.supportedLocalesOf([
"en-US",
Expand Down
2 changes: 1 addition & 1 deletion test/intl/Intl__ListFormatTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var _formatter = new Intl.ListFormat([
Intl.ListFormat.supportedLocalesOf([
"en-US",
"en-GB"
], undefined);
]);

Intl.ListFormat.supportedLocalesOf([
"en-US",
Expand Down
2 changes: 1 addition & 1 deletion test/intl/Intl__NumberFormatTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var currencyFormatter = new Intl.NumberFormat(["fr-FR"], {
console.log(Intl.NumberFormat.supportedLocalesOf([
"fr-FR",
"en-US"
], undefined));
]));

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

Expand Down
2 changes: 1 addition & 1 deletion test/intl/Intl__RelativeTimeFormatTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ console.log("Intl.RelativeTimeFormat");
Intl.RelativeTimeFormat.supportedLocalesOf([
"en-US",
"en-GB"
], undefined);
]);

Intl.RelativeTimeFormat.supportedLocalesOf([
"en-US",
Expand Down
2 changes: 1 addition & 1 deletion test/intl/Intl__SegmenterTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ console.log("Intl.Segmenter");
Intl.Segmenter.supportedLocalesOf([
"en-US",
"en-GB"
], undefined);
]);

Intl.Segmenter.supportedLocalesOf([
"en-US",
Expand Down

0 comments on commit b9e3f33

Please sign in to comment.