mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-16 08:21:44 +00:00
guard, info on never null, more general array rt
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { ALLOCATE, REGISTER, ArrayBufferView } from "./runtime";
|
||||
import { COMPARATOR, SORT as SORT_IMPL } from "./util/sort";
|
||||
import { E_INDEXOUTOFRANGE } from "./util/error";
|
||||
|
||||
export class Int8Array extends ArrayBufferView {
|
||||
[key: number]: i8;
|
||||
@ -22,13 +23,13 @@ export class Int8Array extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): i8 {
|
||||
if (<u32>index >= <u32>this.dataLength) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<i8>(this.dataStart + <usize>index);
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: native<i8>): void {
|
||||
if (<u32>index >= <u32>this.dataLength) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<i8>(this.dataStart + <usize>index, value);
|
||||
}
|
||||
|
||||
@ -104,13 +105,13 @@ export class Uint8Array extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): u8 {
|
||||
if (<u32>index >= <u32>this.dataLength) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<u8>(this.dataStart + <usize>index);
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: native<u8>): void {
|
||||
if (<u32>index >= <u32>this.dataLength) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<u8>(this.dataStart + <usize>index, value);
|
||||
}
|
||||
|
||||
@ -186,13 +187,13 @@ export class Uint8ClampedArray extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): u8 {
|
||||
if (<u32>index >= <u32>this.dataLength) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<u8>(this.dataStart + <usize>index);
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: native<u8>): void {
|
||||
if (<u32>index >= <u32>this.dataLength) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<u8>(this.dataStart + <usize>index, ~(<i32>value >> 31) & (((255 - value) >> 31) | value));
|
||||
}
|
||||
|
||||
@ -268,13 +269,13 @@ export class Int16Array extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): i16 {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i16>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i16>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<i16>(this.dataStart + (<usize>index << alignof<i16>()));
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: native<i16>): void {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i16>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i16>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<i16>(this.dataStart + (<usize>index << alignof<i16>()), value);
|
||||
}
|
||||
|
||||
@ -350,13 +351,13 @@ export class Uint16Array extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): u16 {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u16>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u16>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<u16>(this.dataStart + (<usize>index << alignof<u16>()));
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: native<u16>): void {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u16>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u16>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<u16>(this.dataStart + (<usize>index << alignof<u16>()), value);
|
||||
}
|
||||
|
||||
@ -432,13 +433,13 @@ export class Int32Array extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): i32 {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i32>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i32>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<i32>(this.dataStart + (<usize>index << alignof<i32>()));
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: i32): void {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i32>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i32>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<i32>(this.dataStart + (<usize>index << alignof<i32>()), value);
|
||||
}
|
||||
|
||||
@ -514,13 +515,13 @@ export class Uint32Array extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): u32 {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u32>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u32>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<u32>(this.dataStart + (<usize>index << alignof<u32>()));
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: u32): void {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u32>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u32>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<u32>(this.dataStart + (<usize>index << alignof<u32>()), value);
|
||||
}
|
||||
|
||||
@ -596,13 +597,13 @@ export class Int64Array extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): i64 {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i64>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i64>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<i64>(this.dataStart + (<usize>index << alignof<i64>()));
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: i64): void {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i64>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<i64>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<i64>(this.dataStart + (<usize>index << alignof<i64>()), value);
|
||||
}
|
||||
|
||||
@ -678,13 +679,13 @@ export class Uint64Array extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): u64 {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u64>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u64>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<u64>(this.dataStart + (<usize>index << alignof<u64>()));
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: u64): void {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u64>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<u64>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<u64>(this.dataStart + (<usize>index << alignof<u64>()), value);
|
||||
}
|
||||
|
||||
@ -760,13 +761,13 @@ export class Float32Array extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): f32 {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<f32>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<f32>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<f32>(this.dataStart + (<usize>index << alignof<f32>()));
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: f32): void {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<f32>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<f32>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<f32>(this.dataStart + (<usize>index << alignof<f32>()), value);
|
||||
}
|
||||
|
||||
@ -842,13 +843,13 @@ export class Float64Array extends ArrayBufferView {
|
||||
|
||||
@operator("[]") // unchecked is built-in
|
||||
private __get(index: i32): f64 {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<f64>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<f64>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
return load<f64>(this.dataStart + (<usize>index << alignof<f64>()));
|
||||
}
|
||||
|
||||
@operator("[]=") // unchecked is built-in
|
||||
private __set(index: i32, value: f64): void {
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<f64>()) throw new Error("Offset out of bounds");
|
||||
if (<u32>index >= <u32>this.dataLength >>> alignof<f64>()) throw new RangeError(E_INDEXOUTOFRANGE);
|
||||
store<f64>(this.dataStart + (<usize>index << alignof<f64>()), value);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user