diff --git a/static_core/plugins/ets/compiler/ir_build_intrinsics_ets.cpp b/static_core/plugins/ets/compiler/ir_build_intrinsics_ets.cpp index 6a3c0095a600ca8eab4d1b0715a1ef1c2d4c38a6..80697963583e4f9e9c83c45f388cbeee12ef65cc 100644 --- a/static_core/plugins/ets/compiler/ir_build_intrinsics_ets.cpp +++ b/static_core/plugins/ets/compiler/ir_build_intrinsics_ets.cpp @@ -281,6 +281,7 @@ void InstBuilder::BuildBigUint64ArrayGetIntrinsic(const BytecodeInstruction *bcI 7. ZeroCheck D v6 4. Bitcast INT64->POINTER v7 9. LoadObject v3, TYPED_ARRAY_BUFFER_BYTE_OFFSET_OFFSET + 10. Cast FLOAT64->INT32 v9 11. LoadObject v3, TYPED_ARRAY_LENGTH_OFFSET 12. BoundsCheck v11, v2 14. Add v2, v10 @@ -331,9 +332,12 @@ std::tuple InstBuilder::BuildTypedArrayLoadDataAndOffset(const B loadDataInst = graph->CreateInstBitcast(DataType::POINTER, bcAddr, loadDataInst, loadDataInst->GetType()); AddInstruction(loadDataInst); - auto *loadDataOffsetInst = graph->CreateInstLoadObject( - DataType::INT32, bcAddr, nullCheck, TypeIdMixin {runtime->GetFieldId(byteOffsetField), calleeMethod}, + auto *loadDataOffsetFloat64Inst = graph->CreateInstLoadObject( + DataType::FLOAT64, bcAddr, nullCheck, TypeIdMixin {runtime->GetFieldId(byteOffsetField), calleeMethod}, byteOffsetField, runtime->IsFieldVolatile(byteOffsetField)); + AddInstruction(loadDataOffsetFloat64Inst); + auto *loadDataOffsetInst = + graph->CreateInstCast(DataType::INT32, bcAddr, loadDataOffsetFloat64Inst, loadDataOffsetFloat64Inst->GetType()); AddInstruction(loadDataOffsetInst); if (needBoundCheck) { diff --git a/static_core/plugins/ets/runtime/types/ets_typed_arrays.h b/static_core/plugins/ets/runtime/types/ets_typed_arrays.h index 8d009db27e151f6c4550366ff6dce748077c6fc8..aa0120edcbaaea50f673fb9015069299e0871ba1 100644 --- a/static_core/plugins/ets/runtime/types/ets_typed_arrays.h +++ b/static_core/plugins/ets/runtime/types/ets_typed_arrays.h @@ -78,22 +78,22 @@ public: buffer_ = buffer; } - EtsInt GetByteOffset() const + EtsDouble GetByteOffset() const { return byteOffset_; } - void SetByteOffset(EtsInt offset) + void SetByteOffset(EtsDouble offset) { byteOffset_ = offset; } - EtsInt GetByteLength() const + EtsDouble GetByteLength() const { return byteLength_; } - void SetByteLength(EtsInt byteLength) + void SetByteLength(EtsDouble byteLength) { byteLength_ = byteLength; } @@ -133,10 +133,10 @@ public: private: ObjectPointer buffer_; ObjectPointer name_; + EtsDouble byteOffset_; + EtsDouble byteLength_; EtsInt bytesPerElement_; EtsInt lengthInt_; - EtsInt byteOffset_; - EtsInt byteLength_; friend class test::EtsEscompatTypedArrayBaseTest; }; diff --git a/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets b/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets index 849e88064624475c9ee74e9f3c6b75e7b9125868..1cca196b37fc1433eb13ac2d7a0c0d3a70dcd2fa 100644 --- a/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets +++ b/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets @@ -102,9 +102,9 @@ export final class Int8Array implements Iterable, ArrayLike { const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast(items as ArrayLike) - this.byteLength = arr.length * Int8Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * Int8Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { let temp: double = arr.$_get(i); @@ -222,9 +222,9 @@ export final class Int8Array implements Iterable, ArrayLike { // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLength = arr.length * Int8Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * Int8Array.BYTES_PER_ELEMENT.toInt() + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { this.setUnsafe(i, arr.$_get(i).toByte()) @@ -255,7 +255,7 @@ export final class Int8Array implements Iterable, ArrayLike { this.lengthInt = length.toInt() this.byteLength = this.lengthInt * Int8Array.BYTES_PER_ELEMENT this.byteOffset = 0 - this.buffer = new ArrayBuffer(this.byteLength) + this.buffer = new ArrayBuffer(this.byteLength.toInt()) } /** @@ -264,9 +264,9 @@ export final class Int8Array implements Iterable, ArrayLike { * @param other data initializer */ public constructor(other: Int8Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer this.byteLength = other.byteLength - this.lengthInt = other.length + this.lengthInt = other.length.toInt() this.byteOffset = 0 } @@ -1607,7 +1607,7 @@ export final class Int8Array implements Iterable, ArrayLike { private setUnsafe(insertPos: int, val: byte): void { const BPE = Int8Array.BYTES_PER_ELEMENT.toInt() - let byteIndex = insertPos * BPE + this.byteOffset + let byteIndex = insertPos * BPE + this.byteOffset.toInt() let buf = this.buffer buf.set(byteIndex, val) } @@ -1616,10 +1616,10 @@ export final class Int8Array implements Iterable, ArrayLike { public readonly buffer: ArrayBuffer /** Byte offset within the underlying ArrayBuffer */ - public readonly byteOffset: int + public readonly byteOffset: number /** Number of bytes used */ - public readonly byteLength: int + public readonly byteLength: number /** String \"Int8Array\" */ public readonly name = "Int8Array" @@ -1710,9 +1710,9 @@ export final class Int16Array implements Iterable, ArrayLike { const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast(items as ArrayLike) - this.byteLength = arr.length * Int16Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * Int16Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { let temp: double = arr.$_get(i); @@ -1837,9 +1837,9 @@ export final class Int16Array implements Iterable, ArrayLike { // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLength = arr.length * Int16Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * Int16Array.BYTES_PER_ELEMENT.toInt() + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { this.setUnsafe(i, arr.$_get(i).toShort()) @@ -1870,7 +1870,7 @@ export final class Int16Array implements Iterable, ArrayLike { this.lengthInt = length.toInt() this.byteLength = this.lengthInt * Int16Array.BYTES_PER_ELEMENT this.byteOffset = 0 - this.buffer = new ArrayBuffer(this.byteLength) + this.buffer = new ArrayBuffer(this.byteLength.toInt()) } /** @@ -1879,9 +1879,9 @@ export final class Int16Array implements Iterable, ArrayLike { * @param other data initializer */ public constructor(other: Int16Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer this.byteLength = other.byteLength - this.lengthInt = other.length + this.lengthInt = other.length.toInt() this.byteOffset = 0 } @@ -3222,7 +3222,7 @@ export final class Int16Array implements Iterable, ArrayLike { private setUnsafe(insertPos: int, val: short): void { const BPE = Int16Array.BYTES_PER_ELEMENT.toInt() - let byteIndex = insertPos * BPE + this.byteOffset + let byteIndex = insertPos * BPE + this.byteOffset.toInt() let buf = this.buffer let bits = val if (IS_LITTLE_ENDIAN) { @@ -3244,10 +3244,10 @@ export final class Int16Array implements Iterable, ArrayLike { public readonly buffer: ArrayBuffer /** Byte offset within the underlying ArrayBuffer */ - public readonly byteOffset: int + public readonly byteOffset: number /** Number of bytes used */ - public readonly byteLength: int + public readonly byteLength: number /** String \"Int16Array\" */ public readonly name = "Int16Array" @@ -3338,9 +3338,9 @@ export final class Int32Array implements Iterable, ArrayLike { const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast(items as ArrayLike) - this.byteLength = arr.length * Int32Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * Int32Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { let temp: double = arr.$_get(i); @@ -3465,9 +3465,9 @@ export final class Int32Array implements Iterable, ArrayLike { // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLength = arr.length * Int32Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * Int32Array.BYTES_PER_ELEMENT.toInt() + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { this.setUnsafe(i, arr.$_get(i).toInt()) @@ -3498,7 +3498,7 @@ export final class Int32Array implements Iterable, ArrayLike { this.lengthInt = length.toInt() this.byteLength = this.lengthInt * Int32Array.BYTES_PER_ELEMENT this.byteOffset = 0 - this.buffer = new ArrayBuffer(this.byteLength) + this.buffer = new ArrayBuffer(this.byteLength.toInt()) } /** @@ -3507,9 +3507,9 @@ export final class Int32Array implements Iterable, ArrayLike { * @param other data initializer */ public constructor(other: Int32Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer this.byteLength = other.byteLength - this.lengthInt = other.length + this.lengthInt = other.length.toInt() this.byteOffset = 0 } @@ -4813,7 +4813,7 @@ export final class Int32Array implements Iterable, ArrayLike { private setUnsafe(insertPos: int, val: int): void { const BPE = Int32Array.BYTES_PER_ELEMENT.toInt() - let byteIndex = insertPos * BPE + this.byteOffset + let byteIndex = insertPos * BPE + this.byteOffset.toInt() let buf = this.buffer let bits = val if (IS_LITTLE_ENDIAN) { @@ -4835,10 +4835,10 @@ export final class Int32Array implements Iterable, ArrayLike { public readonly buffer: ArrayBuffer /** Byte offset within the underlying ArrayBuffer */ - public readonly byteOffset: int + public readonly byteOffset: number /** Number of bytes used */ - public readonly byteLength: int + public readonly byteLength: number /** String \"Int32Array\" */ public readonly name = "Int32Array" @@ -4929,9 +4929,9 @@ export final class BigInt64Array implements Iterable, ArrayLike const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast(items as ArrayLike) - this.byteLength = arr.length * BigInt64Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * BigInt64Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { this.setUnsafe(i, arr.$_get(i).getLong()) @@ -5050,9 +5050,9 @@ export final class BigInt64Array implements Iterable, ArrayLike // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLength = arr.length * BigInt64Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * BigInt64Array.BYTES_PER_ELEMENT.toInt() + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { this.setUnsafe(i, arr.$_get(i).toLong()) @@ -5083,7 +5083,7 @@ export final class BigInt64Array implements Iterable, ArrayLike this.lengthInt = length.toInt() this.byteLength = this.lengthInt * BigInt64Array.BYTES_PER_ELEMENT this.byteOffset = 0 - this.buffer = new ArrayBuffer(this.byteLength) + this.buffer = new ArrayBuffer(this.byteLength.toInt()) } /** @@ -5092,9 +5092,9 @@ export final class BigInt64Array implements Iterable, ArrayLike * @param other data initializer */ public constructor(other: BigInt64Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer this.byteLength = other.byteLength - this.lengthInt = other.length + this.lengthInt = other.length.toInt() this.byteOffset = 0 } @@ -6420,7 +6420,7 @@ export final class BigInt64Array implements Iterable, ArrayLike private setUnsafe(insertPos: int, val: long): void { const BPE = BigInt64Array.BYTES_PER_ELEMENT.toInt() - let byteIndex = insertPos * BPE + this.byteOffset + let byteIndex = insertPos * BPE + this.byteOffset.toInt() let buf = this.buffer let bits = val if (IS_LITTLE_ENDIAN) { @@ -6442,10 +6442,10 @@ export final class BigInt64Array implements Iterable, ArrayLike public readonly buffer: ArrayBuffer /** Byte offset within the underlying ArrayBuffer */ - public readonly byteOffset: int + public readonly byteOffset: number /** Number of bytes used */ - public readonly byteLength: int + public readonly byteLength: number /** String \"BigInt64Array\" */ public readonly name = "BigInt64Array" @@ -6536,9 +6536,9 @@ export final class Float32Array implements Iterable, ArrayLike { const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast(items as ArrayLike) - this.byteLength = arr.length * Float32Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * Float32Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { this.setUnsafe(i, arr.$_get(i).toFloat()); @@ -6657,9 +6657,9 @@ export final class Float32Array implements Iterable, ArrayLike { // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLength = arr.length * Float32Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * Float32Array.BYTES_PER_ELEMENT.toInt() + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { this.setUnsafe(i, arr.$_get(i).toFloat()) @@ -6690,7 +6690,7 @@ export final class Float32Array implements Iterable, ArrayLike { this.lengthInt = length.toInt() this.byteLength = this.lengthInt * Float32Array.BYTES_PER_ELEMENT this.byteOffset = 0 - this.buffer = new ArrayBuffer(this.byteLength) + this.buffer = new ArrayBuffer(this.byteLength.toInt()) } /** @@ -6699,9 +6699,9 @@ export final class Float32Array implements Iterable, ArrayLike { * @param other data initializer */ public constructor(other: Float32Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer this.byteLength = other.byteLength - this.lengthInt = other.length + this.lengthInt = other.length.toInt() this.byteOffset = 0 } @@ -8013,7 +8013,7 @@ export final class Float32Array implements Iterable, ArrayLike { private setUnsafe(insertPos: int, val: float): void { const BPE = Float32Array.BYTES_PER_ELEMENT.toInt() - let byteIndex = insertPos * BPE + this.byteOffset + let byteIndex = insertPos * BPE + this.byteOffset.toInt() let buf = this.buffer let bits = Float.bitCastToInt(val) if (IS_LITTLE_ENDIAN) { @@ -8035,10 +8035,10 @@ export final class Float32Array implements Iterable, ArrayLike { public readonly buffer: ArrayBuffer /** Byte offset within the underlying ArrayBuffer */ - public readonly byteOffset: int + public readonly byteOffset: number /** Number of bytes used */ - public readonly byteLength: int + public readonly byteLength: number /** String \"Float32Array\" */ public readonly name = "Float32Array" @@ -8129,9 +8129,9 @@ export final class Float64Array implements Iterable, ArrayLike { const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast(items as ArrayLike) - this.byteLength = arr.length * Float64Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * Float64Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { this.setUnsafe(i, arr.$_get(i).toDouble()); @@ -8250,9 +8250,9 @@ export final class Float64Array implements Iterable, ArrayLike { // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLength = arr.length * Float64Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * Float64Array.BYTES_PER_ELEMENT.toInt() + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { this.setUnsafe(i, arr.$_get(i).toDouble()) @@ -8283,7 +8283,7 @@ export final class Float64Array implements Iterable, ArrayLike { this.lengthInt = length.toInt() this.byteLength = this.lengthInt * Float64Array.BYTES_PER_ELEMENT this.byteOffset = 0 - this.buffer = new ArrayBuffer(this.byteLength) + this.buffer = new ArrayBuffer(this.byteLength.toInt()) } /** @@ -8292,9 +8292,9 @@ export final class Float64Array implements Iterable, ArrayLike { * @param other data initializer */ public constructor(other: Float64Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer this.byteLength = other.byteLength - this.lengthInt = other.length + this.lengthInt = other.length.toInt() this.byteOffset = 0 } @@ -9533,7 +9533,7 @@ export final class Float64Array implements Iterable, ArrayLike { private setUnsafe(insertPos: int, val: double): void { const BPE = Float64Array.BYTES_PER_ELEMENT.toInt() - let byteIndex = insertPos * BPE + this.byteOffset + let byteIndex = insertPos * BPE + this.byteOffset.toInt() let buf = this.buffer let bits = Double.bitCastToLong(val) if (IS_LITTLE_ENDIAN) { @@ -9555,10 +9555,10 @@ export final class Float64Array implements Iterable, ArrayLike { public readonly buffer: ArrayBuffer /** Byte offset within the underlying ArrayBuffer */ - public readonly byteOffset: int + public readonly byteOffset: number /** Number of bytes used */ - public readonly byteLength: int + public readonly byteLength: number /** String \"Float64Array\" */ public readonly name = "Float64Array" diff --git a/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets b/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets index 15d9a06db7c7e029d781320a632598979eaae97c..0686febe54fe6ceb8709ce3004e98b01edcdf34b 100644 --- a/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets +++ b/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets @@ -111,8 +111,8 @@ export final class Uint8ClampedArray implements Iterable, ArrayLike(items as ArrayLike) - this.byteLengthInt = arr.length * Uint8ClampedArray.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * Uint8ClampedArray.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -223,8 +223,8 @@ export final class Uint8ClampedArray implements Iterable, ArrayLike((buf as ArrayLike)) - this.byteLengthInt = arr.length * Uint8ClampedArray.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * Uint8ClampedArray.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -265,9 +265,9 @@ export final class Uint8ClampedArray implements Iterable, ArrayLike, ArrayLike, ArrayLike { const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast(items as ArrayLike) - this.byteLengthInt = arr.length * Uint8Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * Uint8Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -1833,8 +1833,8 @@ export final class Uint8Array implements Iterable, ArrayLike { // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLengthInt = arr.length * Uint8Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * Uint8Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -1875,9 +1875,9 @@ export final class Uint8Array implements Iterable, ArrayLike { * @param other data initializer */ public constructor(other: Uint8Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer - this.byteLengthInt = other.byteLength - this.lengthInt = other.length + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer + this.byteLengthInt = other.byteLength.toInt() + this.lengthInt = other.length.toInt() this.byteOffsetInt = 0 } @@ -3194,12 +3194,12 @@ export final class Uint8Array implements Iterable, ArrayLike { } /** Byte offset within the underlying Buffer */ - public get byteOffset(): int { + public get byteOffset(): number { return this.byteOffsetInt } /** Number of bytes used */ - public get byteLength(): int { + public get byteLength(): number { return this.byteLengthInt } @@ -3321,8 +3321,8 @@ export final class Uint16Array implements Iterable, ArrayLike { const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast(items as ArrayLike) - this.byteLengthInt = arr.length * Uint16Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * Uint16Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -3446,8 +3446,8 @@ export final class Uint16Array implements Iterable, ArrayLike { // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLengthInt = arr.length * Uint16Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * Uint16Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -3488,9 +3488,9 @@ export final class Uint16Array implements Iterable, ArrayLike { * @param other data initializer */ public constructor(other: Uint16Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer - this.byteLengthInt = other.byteLength - this.lengthInt = other.length + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer + this.byteLengthInt = other.byteLength.toInt() + this.lengthInt = other.length.toInt() this.byteOffsetInt = 0 } @@ -4792,12 +4792,12 @@ export final class Uint16Array implements Iterable, ArrayLike { } /** Byte offset within the underlying Buffer */ - public get byteOffset(): int { + public get byteOffset(): number { return this.byteOffsetInt } /** Number of bytes used */ - public get byteLength(): int { + public get byteLength(): number { return this.byteLengthInt } @@ -4930,8 +4930,8 @@ export final class Uint32Array implements Iterable, ArrayLike { const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast(items as ArrayLike) - this.byteLengthInt = arr.length * Uint32Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * Uint32Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -5055,8 +5055,8 @@ export final class Uint32Array implements Iterable, ArrayLike { // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLengthInt = arr.length * Uint32Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * Uint32Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -5097,9 +5097,9 @@ export final class Uint32Array implements Iterable, ArrayLike { * @param other data initializer */ public constructor(other: Uint32Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer - this.byteLengthInt = other.byteLength - this.lengthInt = other.length + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer + this.byteLengthInt = other.byteLength.toInt() + this.lengthInt = other.length.toInt() this.byteOffsetInt = 0 } @@ -6425,12 +6425,12 @@ export final class Uint32Array implements Iterable, ArrayLike { } /** Byte offset within the underlying Buffer */ - public get byteOffset(): int { + public get byteOffset(): number { return this.byteOffsetInt } /** Number of bytes used */ - public get byteLength(): int { + public get byteLength(): number { return this.byteLengthInt } @@ -6563,8 +6563,8 @@ export final class BigUint64Array implements Iterable, ArrayLike const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast(items as ArrayLike) - this.byteLengthInt = arr.length * BigUint64Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * BigUint64Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -6682,8 +6682,8 @@ export final class BigUint64Array implements Iterable, ArrayLike // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLengthInt = arr.length * BigUint64Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * BigUint64Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -6724,9 +6724,9 @@ export final class BigUint64Array implements Iterable, ArrayLike * @param other data initializer */ public constructor(other: BigUint64Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer - this.byteLengthInt = other.byteLength - this.lengthInt = other.length + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer + this.byteLengthInt = other.byteLength.toInt() + this.lengthInt = other.length.toInt() this.byteOffsetInt = 0 } @@ -8050,12 +8050,12 @@ export final class BigUint64Array implements Iterable, ArrayLike } /** Byte offset within the underlying Buffer */ - public get byteOffset(): int { + public get byteOffset(): number { return this.byteOffsetInt } /** Number of bytes used */ - public get byteLength(): int { + public get byteLength(): number { return this.byteLengthInt } diff --git a/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 b/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 index 48e399041053ff77d1b2925043cb7fab06fd4379..76f359267b130a50978eeaa7047498e23c657baf 100644 --- a/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 +++ b/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 @@ -121,9 +121,9 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast<{{subsetTypeValues}}>(items as ArrayLike<{{subsetTypeValues}}>) - this.byteLength = arr.length * {{N}}Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * {{N}}Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { {%- if N == 'BigInt64' %} @@ -257,9 +257,9 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLength = arr.length * {{N}}Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length - this.buffer = new ArrayBuffer(this.byteLength) + this.byteLength = arr.length.toInt() * {{N}}Array.BYTES_PER_ELEMENT.toInt() + this.lengthInt = arr.length.toInt() + this.buffer = new ArrayBuffer(this.byteLength.toInt()) this.byteOffset = 0 for (let i: int = 0; i < this.lengthInt; ++i) { this.setUnsafe(i, arr.$_get(i).to{{T.capitalize()}}()) @@ -290,7 +290,7 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi this.lengthInt = length.toInt() this.byteLength = this.lengthInt * {{N}}Array.BYTES_PER_ELEMENT this.byteOffset = 0 - this.buffer = new ArrayBuffer(this.byteLength) + this.buffer = new ArrayBuffer(this.byteLength.toInt()) } /** @@ -299,9 +299,9 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi * @param other data initializer */ public constructor(other: {{N}}Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer this.byteLength = other.byteLength - this.lengthInt = other.length + this.lengthInt = other.length.toInt() this.byteOffset = 0 } @@ -1875,7 +1875,7 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi private setUnsafe(insertPos: int, val: {{T}}): void { const BPE = {{N}}Array.BYTES_PER_ELEMENT.toInt() - let byteIndex = insertPos * BPE + this.byteOffset + let byteIndex = insertPos * BPE + this.byteOffset.toInt() let buf = this.buffer {%- if T != "byte" %} {%- if T == "float" %} @@ -1906,10 +1906,10 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi public readonly buffer: ArrayBuffer /** Byte offset within the underlying ArrayBuffer */ - public readonly byteOffset: int + public readonly byteOffset: number /** Number of bytes used */ - public readonly byteLength: int + public readonly byteLength: number /** String \"{{N}}Array\" */ public readonly name = "{{N}}Array" diff --git a/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 b/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 index 70f2d21ee982617f01cec5b8a69fb59769f1ecf3..74415991671e7f7056f75c87b8b579232f26f07f 100644 --- a/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 +++ b/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 @@ -131,8 +131,8 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse const items: Object = elements as Object if (items instanceof ArrayLike) { const arr = Types.identity_cast<{{element['subsetTypeValues']}}>(items as ArrayLike<{{element['subsetTypeValues']}}>) - this.byteLengthInt = arr.length * {{element['name']}}Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * {{element['name']}}Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -267,8 +267,8 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse // NOTE (ikorobkov): dealing with this overload is tricky // with banned `instanceof` generic, so it is delegated to array here. Initial idea from Set.ets let arr = Array.from((buf as ArrayLike)) - this.byteLengthInt = arr.length * {{element['name']}}Array.BYTES_PER_ELEMENT - this.lengthInt = arr.length + this.byteLengthInt = arr.length.toInt() * {{element['name']}}Array.BYTES_PER_ELEMENT + this.lengthInt = arr.length.toInt() this.buffer = new ArrayBuffer(this.byteLengthInt) this.byteOffsetInt = 0 for (let i: int = 0; i < this.lengthInt; ++i) { @@ -313,9 +313,9 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse * @param other data initializer */ public constructor(other: {{element['name']}}Array) { - this.buffer = other.buffer.slice(other.byteOffset, other.byteOffset + other.byteLength) as ArrayBuffer - this.byteLengthInt = other.byteLength - this.lengthInt = other.length + this.buffer = other.buffer.slice(other.byteOffset.toInt(), (other.byteOffset + other.byteLength).toInt()) as ArrayBuffer + this.byteLengthInt = other.byteLength.toInt() + this.lengthInt = other.length.toInt() this.byteOffsetInt = 0 } @@ -1816,12 +1816,12 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse } /** Byte offset within the underlying Buffer */ - public get byteOffset(): int { + public get byteOffset(): number { return this.byteOffsetInt } /** Number of bytes used */ - public get byteLength(): int { + public get byteLength(): number { return this.byteLengthInt } diff --git a/taihe/compiler/taihe/codegen/ani/analyses.py b/taihe/compiler/taihe/codegen/ani/analyses.py index ff7e67ec3b60f291ea0f94493006378405f937f0..ac29d414c84eb89147a145209e76454d3237dc77 100644 --- a/taihe/compiler/taihe/codegen/ani/analyses.py +++ b/taihe/compiler/taihe/codegen/ani/analyses.py @@ -1800,11 +1800,11 @@ class TypedArrayTypeAniInfo(TypeAniInfo): ani_data = f"{cpp_result}_data" ani_length = f"{cpp_result}_length" target.writelns( - f"ani_int {ani_byte_length} = {{}};", - f"ani_int {ani_byte_offset} = {{}};", + f"ani_double {ani_byte_length} = {{}};", + f"ani_double {ani_byte_offset} = {{}};", f"ani_arraybuffer {ani_arrbuf} = {{}};", - f'{env}->Object_GetPropertyByName_Int({ani_value}, "byteLength", &{ani_byte_length});', - f'{env}->Object_GetPropertyByName_Int({ani_value}, "byteOffset", &{ani_byte_offset});', + f'{env}->Object_GetPropertyByName_Double({ani_value}, "byteLength", &{ani_byte_length});', + f'{env}->Object_GetPropertyByName_Double({ani_value}, "byteOffset", &{ani_byte_offset});', f'{env}->Object_GetPropertyByName_Ref({ani_value}, "buffer", reinterpret_cast(&{ani_arrbuf}));', f"void* {ani_data} = {{}};", f"ani_size {ani_length} = {{}};",