Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Core into compiler repo #7108

Merged
merged 13 commits into from
Oct 20, 2024
Prev Previous commit
Next Next commit
Remove Core__ prefix from module names
  • Loading branch information
cknitt committed Oct 20, 2024
commit 023dab243a335b67eb3974191c533a0634ba204f
20 changes: 10 additions & 10 deletions runtime/Array.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
external getUnsafe: (array<'a>, int) => 'a = "%array_unsafe_get"
external setUnsafe: (array<'a>, int, 'a) => unit = "%array_unsafe_set"

@val external fromIterator: Core__Iterator.t<'a> => array<'a> = "Array.from"
@val external fromIterator: Iterator.t<'a> => array<'a> = "Array.from"
@val external fromArrayLike: Js.Array2.array_like<'a> => array<'a> = "Array.from"
@val
external fromArrayLikeWithMap: (Js.Array2.array_like<'a>, 'a => 'b) => array<'b> = "Array.from"
Expand Down Expand Up @@ -58,10 +58,10 @@ let equal = (a, b, eq) => {

let rec compareFromIndex = (a, b, i, cmp, len) =>
if i === len {
Core__Ordering.equal
Ordering.equal
} else {
let c = cmp(a->getUnsafe(i), b->getUnsafe(i))
if c == Core__Ordering.equal {
if c == Ordering.equal {
compareFromIndex(a, b, i + 1, cmp, len)
} else {
c
Expand All @@ -72,9 +72,9 @@ let compare = (a, b, cmp) => {
let lenA = a->length
let lenB = b->length
lenA < lenB
? Core__Ordering.less
? Ordering.less
: lenA > lenB
? Core__Ordering.greater
? Ordering.greater
: compareFromIndex(a, b, 0, cmp, lenA)
}

Expand Down Expand Up @@ -146,8 +146,8 @@ let lastIndexOfOpt = (arr, item) =>
@send external sliceToEnd: (array<'a>, ~start: int) => array<'a> = "slice"
@send external copy: array<'a> => array<'a> = "slice"

@send external sort: (array<'a>, ('a, 'a) => Core__Ordering.t) => unit = "sort"
@send external toSorted: (array<'a>, ('a, 'a) => Core__Ordering.t) => array<'a> = "toSorted"
@send external sort: (array<'a>, ('a, 'a) => Ordering.t) => unit = "sort"
@send external toSorted: (array<'a>, ('a, 'a) => Ordering.t) => array<'a> = "toSorted"

@send external toString: array<'a> => string = "toString"
@send external toLocaleString: array<'a> => string = "toLocaleString"
Expand Down Expand Up @@ -187,9 +187,9 @@ let reduceRightWithIndex = (arr, init, f) => reduceRightWithIndex(arr, f, init)
@get_index external get: (array<'a>, int) => option<'a> = ""
@set_index external set: (array<'a>, int, 'a) => unit = ""

@get_index external getSymbol: (array<'a>, Core__Symbol.t) => option<'b> = ""
@get_index external getSymbolUnsafe: (array<'a>, Core__Symbol.t) => 'b = ""
@set_index external setSymbol: (array<'a>, Core__Symbol.t, 'b) => unit = ""
@get_index external getSymbol: (array<'a>, Symbol.t) => option<'b> = ""
@get_index external getSymbolUnsafe: (array<'a>, Symbol.t) => 'b = ""
@set_index external setSymbol: (array<'a>, Symbol.t, 'b) => unit = ""

let findIndexOpt = (array: array<'a>, finder: 'a => bool): option<int> =>
switch findIndex(array, finder) {
Expand Down
14 changes: 7 additions & 7 deletions runtime/Array.resi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
```
*/
@val
external fromIterator: Core__Iterator.t<'a> => array<'a> = "Array.from"
external fromIterator: Iterator.t<'a> => array<'a> = "Array.from"

// TODO: Docs
@val external fromArrayLike: Js.Array2.array_like<'a> => array<'a> = "Array.from"
Expand Down Expand Up @@ -43,7 +43,7 @@ let fromInitializer: (~length: int, int => 'a) => array<'a>

let equal: (array<'a>, array<'a>, ('a, 'a) => bool) => bool

let compare: (array<'a>, array<'a>, ('a, 'a) => Core__Ordering.t) => Core__Ordering.t
let compare: (array<'a>, array<'a>, ('a, 'a) => Ordering.t) => Ordering.t

@val external isArray: 'a => bool = "Array.isArray"

Expand Down Expand Up @@ -233,7 +233,7 @@ Console.log(someArray) // [3, 2, 1]. Original unchanged
```
*/
@send
external toSorted: (array<'a>, ('a, 'a) => Core__Ordering.t) => array<'a> = "toSorted"
external toSorted: (array<'a>, ('a, 'a) => Ordering.t) => array<'a> = "toSorted"

/**
`sort(array, comparator)` sorts `array` in-place using the `comparator` function.
Expand All @@ -251,7 +251,7 @@ Console.log(someArray) // [1, 2, 3]
```
*/
@send
external sort: (array<'a>, ('a, 'a) => Core__Ordering.t) => unit = "sort"
external sort: (array<'a>, ('a, 'a) => Ordering.t) => unit = "sort"

@variadic @send
external splice: (array<'a>, ~start: int, ~remove: int, ~insert: array<'a>) => unit = "splice"
Expand Down Expand Up @@ -840,9 +840,9 @@ Console.log(array[1]) // "Hello"
*/
@set_index
external set: (array<'a>, int, 'a) => unit = ""
@get_index external getSymbol: (array<'a>, Core__Symbol.t) => option<'b> = ""
@get_index external getSymbolUnsafe: (array<'a>, Core__Symbol.t) => 'b = ""
@set_index external setSymbol: (array<'a>, Core__Symbol.t, 'b) => unit = ""
@get_index external getSymbol: (array<'a>, Symbol.t) => option<'b> = ""
@get_index external getSymbolUnsafe: (array<'a>, Symbol.t) => 'b = ""
@set_index external setSymbol: (array<'a>, Symbol.t, 'b) => unit = ""

/**
`getUnsafe(array, index)` returns the element at `index` of `array`.
Expand Down
2 changes: 1 addition & 1 deletion runtime/BigInt.res
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ external toLocaleString: bigint => string = "toLocaleString"

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

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

external \"+": (bigint, bigint) => bigint = "%addbigint"
external \"-": (bigint, bigint) => bigint = "%subbigint"
Expand Down
9 changes: 4 additions & 5 deletions runtime/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<bigint>
type t = 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 @@ -19,22 +19,21 @@ external fromArray: array<bigint> => t = "BigInt64Array"
**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBuffer: Core__ArrayBuffer.t => t = "BigInt64Array"
external fromBuffer: ArrayBuffer.t => t = "BigInt64Array"

/** `fromBufferToEnd` creates a `BigInt64Array` from an `ArrayBuffer.t`, starting at a particular offset and continuing through to the end. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array/BigInt64Array)

**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBufferToEnd: (Core__ArrayBuffer.t, ~byteOffset: int) => t = "BigInt64Array"
external fromBufferToEnd: (ArrayBuffer.t, ~byteOffset: int) => t = "BigInt64Array"

/** `fromBufferWithRange` creates a `BigInt64Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array/BigInt64Array)

**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: int) => t =
"BigInt64Array"
external fromBufferWithRange: (ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "BigInt64Array"

/** `fromLength` creates a zero-initialized `BigInt64Array` to hold the specified count of numbers; this is **not** a byte length. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array/BigInt64Array)

Expand Down
8 changes: 4 additions & 4 deletions runtime/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<bigint>
type t = 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 @@ -19,21 +19,21 @@ external fromArray: array<bigint> => t = "BigUint64Array"
**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBuffer: Core__ArrayBuffer.t => t = "BigUint64Array"
external fromBuffer: ArrayBuffer.t => t = "BigUint64Array"

/** `fromBufferToEnd` creates a `BigUint64Array` from an `ArrayBuffer.t`, starting at a particular offset and continuing through to the end. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array/BigUint64Array)

**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBufferToEnd: (Core__ArrayBuffer.t, ~byteOffset: int) => t = "BigUint64Array"
external fromBufferToEnd: (ArrayBuffer.t, ~byteOffset: int) => t = "BigUint64Array"

/** `fromBufferWithRange` creates a `BigUint64Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array/BigUint64Array)

**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: int) => t =
external fromBufferWithRange: (ArrayBuffer.t, ~byteOffset: int, ~length: int) => t =
"BigUint64Array"

/** `fromLength` creates a zero-initialized `BigUint64Array` to hold the specified count of numbers; this is **not** a byte length. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array/BigUint64Array)
Expand Down
9 changes: 4 additions & 5 deletions runtime/DataView.res
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
type t

@new external fromBuffer: Core__ArrayBuffer.t => t = "DataView"
@new external fromBufferToEnd: (Core__ArrayBuffer.t, ~byteOffset: int) => t = "DataView"
@new external fromBuffer: ArrayBuffer.t => t = "DataView"
@new external fromBufferToEnd: (ArrayBuffer.t, ~byteOffset: int) => t = "DataView"
@new
external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: int) => t =
"DataView"
external fromBufferWithRange: (ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "DataView"

@get external buffer: t => Core__ArrayBuffer.t = "buffer"
@get external buffer: t => ArrayBuffer.t = "buffer"
@get external byteLength: t => int = "byteLength"
@get external byteOffset: t => int = "byteOffset"

Expand Down
2 changes: 1 addition & 1 deletion runtime/Date.res
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module UTC = {

let equal = (a, b) => a->getTime === b->getTime

let compare = (a, b) => Core__Float.compare(a->getTime, b->getTime)
let compare = (a, b) => Float.compare(a->getTime, b->getTime)

// Locale
@send external getFullYear: t => int = "getFullYear"
Expand Down
2 changes: 1 addition & 1 deletion runtime/Date.resi
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ external now: unit => msSinceEpoch = "Date.now"

let equal: (t, t) => bool

let compare: (t, t) => Core__Ordering.t
let compare: (t, t) => Ordering.t

/**
`getTime(date)`
Expand Down
6 changes: 3 additions & 3 deletions runtime/Dict.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let delete = (dict, string) => {
@obj external make: unit => t<'a> = ""

@val external fromArray: array<(string, 'a)> => t<'a> = "Object.fromEntries"
@val external fromIterator: Core__Iterator.t<(string, 'a)> => t<'a> = "Object.fromEntries"
@val external fromIterator: Iterator.t<(string, 'a)> => t<'a> = "Object.fromEntries"

@val external toArray: t<'a> => array<(string, 'a)> = "Object.entries"

Expand All @@ -25,11 +25,11 @@ let delete = (dict, string) => {
@val external copy: (@as(json`{}`) _, t<'a>) => t<'a> = "Object.assign"

let forEach = (dict, f) => {
dict->valuesToArray->Core__Array.forEach(value => f(value))
dict->valuesToArray->Array.forEach(value => f(value))
}

let forEachWithKey = (dict, f) => {
dict->toArray->Core__Array.forEach(((key, value)) => f(value, key))
dict->toArray->Array.forEach(((key, value)) => f(value, key))
}

let mapValues = (dict, f) => {
Expand Down
2 changes: 1 addition & 1 deletion runtime/Dict.resi
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ let dict = Dict.fromIterator(someIterator) // Dict.t<int>
```
*/
@val
external fromIterator: Core__Iterator.t<(string, 'a)> => t<'a> = "Object.fromEntries"
external fromIterator: Iterator.t<(string, 'a)> => t<'a> = "Object.fromEntries"

/**
`toArray(dictionary)` returns an array of all the key/value pairs of the dictionary.
Expand Down
2 changes: 1 addition & 1 deletion runtime/Float.res
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Constants = {

external equal: (float, float) => bool = "%equal"

external compare: (float, float) => Core__Ordering.t = "%compare"
external compare: (float, float) => Ordering.t = "%compare"

@val external isNaN: float => bool = "isNaN"
@val external isFinite: float => bool = "isFinite"
Expand Down
2 changes: 1 addition & 1 deletion runtime/Float.resi
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module Constants: {

external equal: (float, float) => bool = "%equal"

external compare: (float, float) => Core__Ordering.t = "%compare"
external compare: (float, float) => Ordering.t = "%compare"

/**
`isNaN(v)` tests if the given `v` is `NaN`.
Expand Down
9 changes: 4 additions & 5 deletions runtime/Float32Array.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** The `Float32Array` typed array represents an array of 32-bit floating point numbers in platform byte order. See [Float32Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array)
*/
type t = Core__TypedArray.t<float>
type t = TypedArray.t<float>

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 @@ -19,22 +19,21 @@ external fromArray: array<float> => t = "Float32Array"
**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBuffer: Core__ArrayBuffer.t => t = "Float32Array"
external fromBuffer: ArrayBuffer.t => t = "Float32Array"

/** `fromBufferToEnd` creates a `Float32Array` from an `ArrayBuffer.t`, starting at a particular offset and continuing through to the end. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array/Float32Array)

**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBufferToEnd: (Core__ArrayBuffer.t, ~byteOffset: int) => t = "Float32Array"
external fromBufferToEnd: (ArrayBuffer.t, ~byteOffset: int) => t = "Float32Array"

/** `fromBufferWithRange` creates a `Float32Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array/Float32Array)

**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: int) => t =
"Float32Array"
external fromBufferWithRange: (ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Float32Array"

/** `fromLength` creates a zero-initialized `Float32Array` to hold the specified count of numbers; this is **not** a byte length. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array/Float32Array)

Expand Down
9 changes: 4 additions & 5 deletions runtime/Float64Array.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** The `Float64Array` typed array represents an array of 64-bit floating point numbers in platform byte order. See [Float64Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array)
*/
type t = Core__TypedArray.t<float>
type t = TypedArray.t<float>

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 @@ -19,22 +19,21 @@ external fromArray: array<float> => t = "Float64Array"
**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBuffer: Core__ArrayBuffer.t => t = "Float64Array"
external fromBuffer: ArrayBuffer.t => t = "Float64Array"

/** `fromBufferToEnd` creates a `Float64Array` from an `ArrayBuffer.t`, starting at a particular offset and continuing through to the end. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array/Float64Array)

**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBufferToEnd: (Core__ArrayBuffer.t, ~byteOffset: int) => t = "Float64Array"
external fromBufferToEnd: (ArrayBuffer.t, ~byteOffset: int) => t = "Float64Array"

/** `fromBufferWithRange` creates a `Float64Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array/Float64Array)

**Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds.
*/
@new
external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: int) => t =
"Float64Array"
external fromBufferWithRange: (ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Float64Array"

/** `fromLength` creates a zero-initialized `Float64Array` to hold the specified count of numbers; this is **not** a byte length. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array/Float64Array)

Expand Down
15 changes: 7 additions & 8 deletions runtime/Int.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Constants = {

external equal: (int, int) => bool = "%equal"

external compare: (int, int) => Core__Ordering.t = "%compare"
external compare: (int, int) => Ordering.t = "%compare"

@send external toExponential: (int, ~digits: int=?) => string = "toExponential"
@deprecated("Use `toExponential` instead") @send
Expand All @@ -29,11 +29,11 @@ external fromFloat: float => int = "%intoffloat"

let fromString = (x, ~radix=?) => {
let maybeInt = switch radix {
| Some(radix) => Core__Float.parseInt(x, ~radix)
| None => Core__Float.parseInt(x)
| Some(radix) => Float.parseInt(x, ~radix)
| None => Float.parseInt(x)
}

if Core__Float.isNaN(maybeInt) {
if Float.isNaN(maybeInt) {
None
} else if maybeInt > Constants.maxValue->toFloat || maybeInt < Constants.minValue->toFloat {
None
Expand All @@ -59,8 +59,7 @@ let range = (start, end, ~options: rangeOptions={}) => {

let step = switch options.step {
| None => isInverted ? -1 : 1
| Some(0) if start !== end =>
Core__Error.raise(Core__Error.RangeError.make("Incorrect range arguments"))
| Some(0) if start !== end => Error.raise(Error.RangeError.make("Incorrect range arguments"))
| Some(n) => n
}

Expand All @@ -71,10 +70,10 @@ let range = (start, end, ~options: rangeOptions={}) => {
} else {
let range = isInverted ? start - end : end - start
let range = options.inclusive === Some(true) ? range + 1 : range
ceil(float(range) /. float(abs(step)))->Core__Float.toInt
ceil(float(range) /. float(abs(step)))->Float.toInt
}

Core__Array.fromInitializer(~length, i => start + i * step)
Array.fromInitializer(~length, i => start + i * step)
}

@deprecated("Use `range` instead") @send
Expand Down
2 changes: 1 addition & 1 deletion runtime/Int.resi
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module Constants: {

external equal: (int, int) => bool = "%equal"

external compare: (int, int) => Core__Ordering.t = "%compare"
external compare: (int, int) => Ordering.t = "%compare"

/**
`toExponential(n, ~digits=?)` return a `string` representing the given value in
Expand Down
Loading