mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-05-25 21:51:25 +00:00
Merge branch 'master' into runtime
This commit is contained in:
commit
139cec0846
@ -52,7 +52,7 @@
|
|||||||
"make": "npm run clean && npm test && npm run build && npm test",
|
"make": "npm run clean && npm test && npm run build && npm test",
|
||||||
"all": "npm run check && npm run make",
|
"all": "npm run check && npm run make",
|
||||||
"docs": "typedoc --tsconfig tsconfig-docs.json --mode modules --name \"AssemblyScript Compiler API\" --out ./docs/api --ignoreCompilerErrors --excludeNotExported --excludePrivate --excludeExternals --exclude **/std/** --includeDeclarations --readme src/README.md",
|
"docs": "typedoc --tsconfig tsconfig-docs.json --mode modules --name \"AssemblyScript Compiler API\" --out ./docs/api --ignoreCompilerErrors --excludeNotExported --excludePrivate --excludeExternals --exclude **/std/** --includeDeclarations --readme src/README.md",
|
||||||
"postinstall": "opencollective-postinstall"
|
"postinstall": "opencollective-postinstall || exit 0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib/loader/index.d.ts",
|
"lib/loader/index.d.ts",
|
||||||
|
2
std/assembly/index.d.ts
vendored
2
std/assembly/index.d.ts
vendored
@ -1141,6 +1141,8 @@ declare abstract class TypedArray<T> implements ArrayBufferView<T> {
|
|||||||
every(callbackfn: (value: T, index: i32, self: this) => bool): bool;
|
every(callbackfn: (value: T, index: i32, self: this) => bool): bool;
|
||||||
/** The forEach() method executes a provided function once per array element. This method has the same algorithm as Array.prototype.forEach().*/
|
/** The forEach() method executes a provided function once per array element. This method has the same algorithm as Array.prototype.forEach().*/
|
||||||
forEach(callbackfn: (value: T, index: i32, self: this) => void): void;
|
forEach(callbackfn: (value: T, index: i32, self: this) => void): void;
|
||||||
|
/** The reverse() method reverses a typed array in place. The first typed array element becomes the last and the last becomes the first. This method has the same algorithm as Array.prototype.reverse(). */
|
||||||
|
reverse(): this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An array of twos-complement 8-bit signed integers. */
|
/** An array of twos-complement 8-bit signed integers. */
|
||||||
|
@ -69,6 +69,10 @@ export class Int8Array extends ArrayBufferView {
|
|||||||
forEach(callbackfn: (value: i8, index: i32, self: Int8Array) => void): void {
|
forEach(callbackfn: (value: i8, index: i32, self: Int8Array) => void): void {
|
||||||
FOREACH<Int8Array, i8>(this, callbackfn);
|
FOREACH<Int8Array, i8>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, i8>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Uint8Array extends ArrayBufferView {
|
export class Uint8Array extends ArrayBufferView {
|
||||||
@ -128,6 +132,10 @@ export class Uint8Array extends ArrayBufferView {
|
|||||||
forEach(callbackfn: (value: u8, index: i32, self: Uint8Array) => void): void {
|
forEach(callbackfn: (value: u8, index: i32, self: Uint8Array) => void): void {
|
||||||
FOREACH<Uint8Array, u8>(this, callbackfn);
|
FOREACH<Uint8Array, u8>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, u8>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Uint8ClampedArray extends Uint8Array {
|
export class Uint8ClampedArray extends Uint8Array {
|
||||||
@ -181,6 +189,10 @@ export class Uint8ClampedArray extends Uint8Array {
|
|||||||
forEach(callbackfn: (value: u8, index: i32, self: Uint8ClampedArray) => void): void {
|
forEach(callbackfn: (value: u8, index: i32, self: Uint8ClampedArray) => void): void {
|
||||||
FOREACH<Uint8ClampedArray, u8>(this, callbackfn);
|
FOREACH<Uint8ClampedArray, u8>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, u8>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Int16Array extends ArrayBufferView {
|
export class Int16Array extends ArrayBufferView {
|
||||||
@ -246,6 +258,10 @@ export class Int16Array extends ArrayBufferView {
|
|||||||
forEach(callbackfn: (value: i16, index: i32, self: Int16Array) => void): void {
|
forEach(callbackfn: (value: i16, index: i32, self: Int16Array) => void): void {
|
||||||
FOREACH<Int16Array, i16>(this, callbackfn);
|
FOREACH<Int16Array, i16>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, i16>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Uint16Array extends ArrayBufferView {
|
export class Uint16Array extends ArrayBufferView {
|
||||||
@ -311,6 +327,10 @@ export class Uint16Array extends ArrayBufferView {
|
|||||||
forEach(callbackfn: (value: u16, index: i32, self: Uint16Array) => void): void {
|
forEach(callbackfn: (value: u16, index: i32, self: Uint16Array) => void): void {
|
||||||
FOREACH<Uint16Array, u16>(this, callbackfn);
|
FOREACH<Uint16Array, u16>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, u16>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Int32Array extends ArrayBufferView {
|
export class Int32Array extends ArrayBufferView {
|
||||||
@ -376,6 +396,10 @@ export class Int32Array extends ArrayBufferView {
|
|||||||
forEach(callbackfn: (value: i32, index: i32, self: Int32Array) => void): void {
|
forEach(callbackfn: (value: i32, index: i32, self: Int32Array) => void): void {
|
||||||
FOREACH<Int32Array, i32>(this, callbackfn);
|
FOREACH<Int32Array, i32>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, i32>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Uint32Array extends ArrayBufferView {
|
export class Uint32Array extends ArrayBufferView {
|
||||||
@ -441,6 +465,10 @@ export class Uint32Array extends ArrayBufferView {
|
|||||||
forEach(callbackfn: (value: u32, index: i32, self: Uint32Array) => void): void {
|
forEach(callbackfn: (value: u32, index: i32, self: Uint32Array) => void): void {
|
||||||
FOREACH<Uint32Array, u32>(this, callbackfn);
|
FOREACH<Uint32Array, u32>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, u32>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Int64Array extends ArrayBufferView {
|
export class Int64Array extends ArrayBufferView {
|
||||||
@ -506,6 +534,10 @@ export class Int64Array extends ArrayBufferView {
|
|||||||
forEach(callbackfn: (value: i64, index: i32, self: Int64Array) => void): void {
|
forEach(callbackfn: (value: i64, index: i32, self: Int64Array) => void): void {
|
||||||
FOREACH<Int64Array, i64>(this, callbackfn);
|
FOREACH<Int64Array, i64>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, i64>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Uint64Array extends ArrayBufferView {
|
export class Uint64Array extends ArrayBufferView {
|
||||||
@ -571,6 +603,10 @@ export class Uint64Array extends ArrayBufferView {
|
|||||||
forEach(callbackfn: (value: u64, index: i32, self: Uint64Array) => void): void {
|
forEach(callbackfn: (value: u64, index: i32, self: Uint64Array) => void): void {
|
||||||
FOREACH<Uint64Array, u64>(this, callbackfn);
|
FOREACH<Uint64Array, u64>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, u64>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Float32Array extends ArrayBufferView {
|
export class Float32Array extends ArrayBufferView {
|
||||||
@ -636,6 +672,10 @@ export class Float32Array extends ArrayBufferView {
|
|||||||
forEach(callbackfn: (value: f32, index: i32, self: Float32Array) => void): void {
|
forEach(callbackfn: (value: f32, index: i32, self: Float32Array) => void): void {
|
||||||
FOREACH<Float32Array, f32>(this, callbackfn);
|
FOREACH<Float32Array, f32>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, f32>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Float64Array extends ArrayBufferView {
|
export class Float64Array extends ArrayBufferView {
|
||||||
@ -701,6 +741,10 @@ export class Float64Array extends ArrayBufferView {
|
|||||||
forEach(callbackfn: (value: f64, index: i32, self: Float64Array) => void): void {
|
forEach(callbackfn: (value: f64, index: i32, self: Float64Array) => void): void {
|
||||||
FOREACH<Float64Array, f64>(this, callbackfn);
|
FOREACH<Float64Array, f64>(this, callbackfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse(): this {
|
||||||
|
return REVERSE<this, f64>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore: decorator
|
// @ts-ignore: decorator
|
||||||
@ -866,3 +910,17 @@ function FOREACH<TArray extends ArrayBufferView, T>(
|
|||||||
callbackfn(load<T>(dataStart + (<usize>i << alignof<T>())), i, array);
|
callbackfn(load<T>(dataStart + (<usize>i << alignof<T>())), i, array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore: decorator
|
||||||
|
@inline
|
||||||
|
export function REVERSE<TArray extends ArrayBufferView, T>(array: TArray): TArray {
|
||||||
|
var dataStart = array.dataStart;
|
||||||
|
for (let front = 0, back = array.length - 1; front < back; ++front, --back) {
|
||||||
|
let frontPtr = dataStart + (<usize>front << alignof<T>());
|
||||||
|
let backPtr = dataStart + (<usize>back << alignof<T>());
|
||||||
|
let temp = load<T>(frontPtr);
|
||||||
|
store<T>(frontPtr, load<T>(backPtr));
|
||||||
|
store<T>(backPtr, temp);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -362,10 +362,10 @@ function testArrayFindIndex<ArrayType extends TypedArray<T>, T extends number>()
|
|||||||
// testIndex++;
|
// testIndex++;
|
||||||
return value == <T>2;
|
return value == <T>2;
|
||||||
});
|
});
|
||||||
assert(result == 1);
|
assert(result == 1, "result mismatch");
|
||||||
var failResult = source.findIndex((value: T, index: i32, self: ArrayType): bool => value == <T>4);
|
var failResult = source.findIndex((value: T, index: i32, self: ArrayType): bool => value == <T>4);
|
||||||
|
|
||||||
assert(failResult == -1);
|
assert(failResult == -1, "fail result mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
testArrayFindIndex<Int8Array, i8>();
|
testArrayFindIndex<Int8Array, i8>();
|
||||||
@ -441,3 +441,42 @@ testArrayForEach<Int64Array, i64>();
|
|||||||
testArrayForEach<Uint64Array, u64>();
|
testArrayForEach<Uint64Array, u64>();
|
||||||
testArrayForEach<Float32Array, f32>();
|
testArrayForEach<Float32Array, f32>();
|
||||||
testArrayForEach<Float64Array, f64>();
|
testArrayForEach<Float64Array, f64>();
|
||||||
|
|
||||||
|
|
||||||
|
var testArrayReverseValues: i32[] = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||||
|
function testArrayReverse<TArray extends TypedArray<T>, T extends number>(): void {
|
||||||
|
var values = testArrayReverseValues;
|
||||||
|
var array = instantiate<TArray>(9);
|
||||||
|
var arrayWithOffset = instantiate<TArray>(9);
|
||||||
|
var i: i32 = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 9; i++) {
|
||||||
|
array[i] = <T>values[i];
|
||||||
|
arrayWithOffset[i] = <T>values[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
array.reverse();
|
||||||
|
|
||||||
|
for (i = 0; i < 9; i++) {
|
||||||
|
assert(array[i] == <T>values[8 - i], "TypedArray reverse value mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
var reversedSlice = arrayWithOffset.subarray(4, 8).reverse();
|
||||||
|
|
||||||
|
assert(reversedSlice[0] == <T>8, "TypedArray reverse with byteOffset mismatch");
|
||||||
|
assert(reversedSlice[1] == <T>7, "TypedArray reverse with byteOffset mismatch");
|
||||||
|
assert(reversedSlice[2] == <T>6, "TypedArray reverse with byteOffset mismatch");
|
||||||
|
assert(reversedSlice[3] == <T>5, "TypedArray reverse with byteOffset mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
testArrayReverse<Int8Array, i8>();
|
||||||
|
testArrayReverse<Uint8Array, u8>();
|
||||||
|
testArrayReverse<Uint8ClampedArray, u8>();
|
||||||
|
testArrayReverse<Int16Array, i16>();
|
||||||
|
testArrayReverse<Uint16Array, u16>();
|
||||||
|
testArrayReverse<Int32Array, i32>();
|
||||||
|
testArrayReverse<Uint32Array, u32>();
|
||||||
|
testArrayReverse<Int64Array, i64>();
|
||||||
|
testArrayReverse<Uint64Array, u64>();
|
||||||
|
testArrayReverse<Float32Array, f32>();
|
||||||
|
testArrayReverse<Float64Array, f64>();
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user