assemblyscript
Version:
A TypeScript-like language for WebAssembly.
834 lines (821 loc) • 155 kB
TypeScript
/**
* Environment definitions for compiling AssemblyScript to WebAssembly using asc.
* @module std/assembly
*//***/
/// <reference no-default-lib="true"/>
// Types
/** An 8-bit signed integer. */
declare type i8 = number;
/** A 16-bit signed integer. */
declare type i16 = number;
/** A 32-bit signed integer. */
declare type i32 = number;
/** A 64-bit signed integer. */
declare type i64 = number;
/** A 32-bit signed integer when targeting 32-bit WebAssembly or a 64-bit signed integer when targeting 64-bit WebAssembly. */
declare type isize = number;
/** An 8-bit unsigned integer. */
declare type u8 = number;
/** A 16-bit unsigned integer. */
declare type u16 = number;
/** A 32-bit unsigned integer. */
declare type u32 = number;
/** A 64-bit unsigned integer. */
declare type u64 = number;
/** A 32-bit unsigned integer when targeting 32-bit WebAssembly or a 64-bit unsigned integer when targeting 64-bit WebAssembly. */
declare type usize = number;
/** A 1-bit unsigned integer. */
declare type bool = boolean | number;
/** A 32-bit float. */
declare type f32 = number;
/** A 64-bit float. */
declare type f64 = number;
/** A 128-bit vector. */
declare type v128 = object;
/** Non-nullable function reference. */
declare type ref_func = object;
/** Canonical nullable function reference. */
declare type funcref = ref_func | null;
/** Non-nullable external reference. */
declare type ref_extern = object;
/** Canonical nullable external reference. */
declare type externref = ref_extern | null;
/** Non-nullable any reference. */
declare type ref_any = object;
/** Canonical nullable any reference. */
declare type anyref = ref_any | null;
/** Non-nullable equatable reference. */
declare type ref_eq = object;
/** Canonical nullable equatable reference. */
declare type eqref = ref_eq | null;
/** Non-nullable struct reference. */
declare type ref_struct = object;
/** Canonical nullable struct reference. */
declare type structref = ref_struct | null;
/** Non-nullable array reference. */
declare type ref_array = object;
/** Canonical nullable array reference. */
declare type arrayref = ref_array | null;
/** Non-nullable 31-bit integer reference. */
declare type ref_i31 = object;
/** Canonical nullable 31-bit integer reference. */
declare type i31ref = ref_i31 | null;
/** Non-nullable string reference. */
declare type ref_string = object;
/** Canonical nullable string reference. */
declare type stringref = ref_string | null;
/** Non-nullable WTF-8 string view. */
declare type ref_stringview_wtf8 = object;
/** Canonical nullable WTF-8 string view. */
declare type stringview_wtf8 = ref_stringview_wtf8 | null;
/** Non-nullable WTF-16 string view. */
declare type ref_stringview_wtf16 = object;
/** Canonical nullable WTF-16 string view. */
declare type stringview_wtf16 = ref_stringview_wtf16 | null;
/** Non-nullable string iterator. */
declare type ref_stringview_iter = object;
/** Canonical nullable string iterator. */
declare type stringview_iter = ref_stringview_iter | null;
// Compiler hints
/** Compiler target. 0 = JS, 1 = WASM32, 2 = WASM64. */
declare const ASC_TARGET: i32;
/** Runtime type. 0 = Stub, 1 = Minimal, 2 = Incremental. */
declare const ASC_RUNTIME: i32;
/** Provided noAssert option. */
declare const ASC_NO_ASSERT: bool;
/** Provided memoryBase option. */
declare const ASC_MEMORY_BASE: i32;
/** Provided tableBase option. */
declare const ASC_TABLE_BASE: i32;
/** Provided optimizeLevel option. */
declare const ASC_OPTIMIZE_LEVEL: i32;
/** Provided shrinkLevel option. */
declare const ASC_SHRINK_LEVEL: i32;
/** Provided lowMemoryLimit option. */
declare const ASC_LOW_MEMORY_LIMIT: i32;
/** Provided noExportRuntime option. */
declare const ASC_NO_EXPORT_RUNTIME: i32;
/** Whether the sign extension feature is enabled. */
declare const ASC_FEATURE_SIGN_EXTENSION: bool;
/** Whether the mutable globals feature is enabled. */
declare const ASC_FEATURE_MUTABLE_GLOBALS: bool;
/** Whether the non-trapping float-to-int feature is enabled. */
declare const ASC_FEATURE_NONTRAPPING_F2I: bool;
/** Whether the bulk memory feature is enabled. */
declare const ASC_FEATURE_BULK_MEMORY: bool;
/** Whether the SIMD feature is enabled. */
declare const ASC_FEATURE_SIMD: bool;
/** Whether the threads feature is enabled. */
declare const ASC_FEATURE_THREADS: bool;
/** Whether the exception handling feature is enabled. */
declare const ASC_FEATURE_EXCEPTION_HANDLING: bool;
/** Whether the tail calls feature is enabled. */
declare const ASC_FEATURE_TAIL_CALLS: bool;
/** Whether the reference types feature is enabled. */
declare const ASC_FEATURE_REFERENCE_TYPES: bool;
/** Whether the multi value types feature is enabled. */
declare const ASC_FEATURE_MULTI_VALUE: bool;
/** Whether the garbage collection feature is enabled. */
declare const ASC_FEATURE_GC: bool;
/** Whether the memory64 feature is enabled. */
declare const ASC_FEATURE_MEMORY64: bool;
/** Whether the relaxed SIMD feature is enabled. */
declare const ASC_FEATURE_RELAXED_SIMD: bool;
/** Whether the extended const expression feature is enabled. */
declare const ASC_FEATURE_EXTENDED_CONST: bool;
/** Whether the string references feature is enabled. */
declare const ASC_FEATURE_STRINGREF: bool;
/** Major version of the compiler. */
declare const ASC_VERSION_MAJOR: i32;
/** Minor version of the compiler. */
declare const ASC_VERSION_MINOR: i32;
/** Patch version of the compiler. */
declare const ASC_VERSION_PATCH: i32;
// Builtins
/** Performs the sign-agnostic reverse bytes **/
declare function bswap<T extends i8 | u8 | i16 | u16 | i32 | u32 | i64 | u64 | isize | usize>(value: T): T;
/** Performs the sign-agnostic count leading zero bits operation on a 32-bit or 64-bit integer. All zero bits are considered leading if the value is zero. */
declare function clz<T extends i32 | i64>(value: T): T;
/** Performs the sign-agnostic count tailing zero bits operation on a 32-bit or 64-bit integer. All zero bits are considered trailing if the value is zero. */
declare function ctz<T extends i32 | i64>(value: T): T;
/** Performs the sign-agnostic count number of one bits operation on a 32-bit or 64-bit integer. */
declare function popcnt<T extends i32 | i64>(value: T): T;
/** Performs the sign-agnostic rotate left operation on a 32-bit or 64-bit integer. */
declare function rotl<T extends i32 | i64>(value: T, shift: T): T;
/** Performs the sign-agnostic rotate right operation on a 32-bit or 64-bit integer. */
declare function rotr<T extends i32 | i64>(value: T, shift: T): T;
/** Computes the absolute value of an integer or float. */
declare function abs<T extends i32 | i64 | f32 | f64>(value: T): T;
/** Determines the maximum of two integers or floats. If either operand is `NaN`, returns `NaN`. */
declare function max<T extends i32 | i64 | f32 | f64>(left: T, right: T): T;
/** Determines the minimum of two integers or floats. If either operand is `NaN`, returns `NaN`. */
declare function min<T extends i32 | i64 | f32 | f64>(left: T, right: T): T;
/** Performs the ceiling operation on a 32-bit or 64-bit float. */
declare function ceil<T extends f32 | f64>(value: T): T;
/** Composes a 32-bit or 64-bit float from the magnitude of `x` and the sign of `y`. */
declare function copysign<T extends f32 | f64>(x: T, y: T): T;
/** Performs the floor operation on a 32-bit or 64-bit float. */
declare function floor<T extends f32 | f64>(value: T): T;
/** Rounds to the nearest integer tied to even of a 32-bit or 64-bit float. */
declare function nearest<T extends f32 | f64>(value: T): T;
/** Reinterprets the bits of the specified value as type `T`. Valid reinterpretations are u32/i32 to/from f32 and u64/i64 to/from f64. */
declare function reinterpret<T extends i32 | i64 | f32 | f64>(value: number): T;
/** Selects one of two pre-evaluated values depending on the condition. */
declare function select<T>(ifTrue: T, ifFalse: T, condition: bool): T;
/** Calculates the square root of a 32-bit or 64-bit float. */
declare function sqrt<T extends f32 | f64>(value: T): T;
/** Rounds to the nearest integer towards zero of a 32-bit or 64-bit float. */
declare function trunc<T extends f32 | f64>(value: T): T;
/** Computes the sum of two integers or floats. */
declare function add<T extends i32 | i64 | f32 | f64>(left: T, right: T): T;
/** Computes the difference of two integers or floats. */
declare function sub<T extends i32 | i64 | f32 | f64>(left: T, right: T): T;
/** Computes the product of two integers or floats. */
declare function mul<T extends i32 | i64 | f32 | f64>(left: T, right: T): T;
/** Computes the quotient of two integers or floats. */
declare function div<T extends i32 | i64 | f32 | f64>(left: T, right: T): T;
/** Return 1 if two numbers are equal to each other, 0 otherwise. */
declare function eq<T extends i32 | i64 | f32 | f64>(left: T, right: T): i32;
/** Return 0 if two numbers are equal to each other, 1 otherwise. */
declare function ne<T extends i32 | i64 | f32 | f64>(left: T, right: T): i32;
/** Computes the remainder of two integers. */
declare function rem<T extends i32 | i64>(left: T, right: T): T;
/** Loads a value of the specified type from memory. Equivalent to dereferncing a pointer in other languages. */
declare function load<T>(ptr: usize, immOffset?: usize, immAlign?: usize): T;
/** Stores a value of the specified type to memory. Equivalent to dereferencing a pointer in other languages when assigning a value. */
declare function store<T>(ptr: usize, value: T, immOffset?: usize, immAlign?: usize): void;
/** Emits an unreachable operation that results in a runtime error when executed. Both a statement and an expression. */
declare function unreachable(): never;
/** NaN (not a number) as a 32-bit or 64-bit float depending on context. */
declare const NaN: f32 | f64;
/** Positive infinity as a 32-bit or 64-bit float depending on context. */
declare const Infinity: f32 | f64;
/** Data end offset. */
declare const __data_end: usize;
/** Stack pointer offset. */
declare let __stack_pointer: usize;
/** Heap base offset. */
declare const __heap_base: usize;
/** Determines the byte size of the specified underlying core type. Compiles to a constant. */
declare function sizeof<T>(): usize;
/** Determines the alignment (log2) of the specified underlying core type. Compiles to a constant. */
declare function alignof<T>(): usize;
/** Determines the end offset of the given class type. Compiles to a constant. */
declare function offsetof<T>(): usize;
/** Determines the offset of the specified field within the given class type. Compiles to a constant. */
declare function offsetof<T>(fieldName: keyof T | string): usize;
/** Determines the offset of the specified field within the given class type. Returns the class type's end offset if field name has been omitted. Compiles to a constant. */
declare function offsetof<T>(fieldName?: string): usize;
/** Determines the name of a given type. */
declare function nameof<T>(value?: T): string;
/** Determines the unique runtime id of a class type. Compiles to a constant. */
declare function idof<T>(): u32;
/** Changes the type of any value of `usize` kind to another one of `usize` kind. Useful for casting class instances to their pointer values and vice-versa. Beware that this is unsafe.*/
declare function changetype<T>(value: any): T;
/** Explicitly requests no bounds checks on the provided expression. Useful for array accesses. */
declare function unchecked<T>(value: T): T;
/** Emits a `call_indirect` instruction, calling the specified function in the function table by index with the specified arguments. Does result in a runtime error if the arguments do not match the called function. */
declare function call_indirect<T>(index: u32, ...args: unknown[]): T;
/** Instantiates a new instance of `T` using the specified constructor arguments. */
declare function instantiate<T>(...args: any[]): T;
/** Tests if a 32-bit or 64-bit float is `NaN`. */
declare function isNaN<T extends f32 | f64>(value: T): bool;
/** Tests if a 32-bit or 64-bit float is finite, that is not `NaN` or +/-`Infinity`. */
declare function isFinite<T extends f32 | f64>(value: T): bool;
/** Tests if the specified type *or* expression is of a boolean type. */
declare function isBoolean<T>(value?: any): value is number;
/** Tests if the specified type *or* expression is of an integer type and not a reference. Compiles to a constant. */
declare function isInteger<T>(value?: any): value is number;
/** Tests if the specified type *or* expression can represent negative numbers. Compiles to a constant. */
declare function isSigned<T>(value?: any): value is number;
/** Tests if the specified type *or* expression is of a float type. Compiles to a constant. */
declare function isFloat<T>(value?: any): value is number;
/** Tests if the specified type *or* expression is of a v128 type. Compiles to a constant. */
declare function isVector<T>(value?: any): value is v128;
/** Tests if the specified type *or* expression is of a reference type. Compiles to a constant. */
declare function isReference<T>(value?: any): value is object | string;
/** Tests if the specified type *or* expression can be used as a string. Compiles to a constant. */
declare function isString<T>(value?: any): value is string | String;
/** Tests if the specified type *or* expression can be used as an array. Compiles to a constant. */
declare function isArray<T>(value?: any): value is Array<any>;
/** Tests if the specified type *or* expression can be used as an array like object. Compiles to a constant. */
declare function isArrayLike<T>(value?: any): value is ArrayLike<any>;
/** Tests if the specified type *or* expression is of a function type. Compiles to a constant. */
declare function isFunction<T>(value?: any): value is (...args: any) => any;
/** Tests if the specified type *or* expression is of a nullable reference type. Compiles to a constant. */
declare function isNullable<T>(value?: any): bool;
/** Tests if the specified expression resolves to a defined element. Compiles to a constant. */
declare function isDefined(expression: any): bool;
/** Tests if the specified expression evaluates to a constant value. Compiles to a constant. */
declare function isConstant(expression: any): bool;
/** Tests if the specified type *or* expression is of a managed type. Compiles to a constant. */
declare function isManaged<T>(value?: any): bool;
/** Tests if the specified type is void. Compiles to a constant. */
declare function isVoid<T>(): bool;
/** Traps if the specified value is not true-ish, otherwise returns the (non-nullable) value. */
declare function assert<T>(isTrueish: T, message?: string): T & (object | string | number); // any better way to model `: T != null`?
/** Parses an integer string to a 64-bit float. */
declare function parseInt(str: string, radix?: i32): f64;
/** Parses a string to a 64-bit float. */
declare function parseFloat(str: string): f64;
/** Returns the 64-bit floating-point remainder of `x/y`. */
declare function fmod(x: f64, y: f64): f64;
/** Returns the 32-bit floating-point remainder of `x/y`. */
declare function fmodf(x: f32, y: f32): f32;
/** Returns the number of parameters in the given function signature type. */
declare function lengthof<T extends (...args: any[]) => any>(func?: T): i32;
/** Encodes a text string as a valid Uniform Resource Identifier (URI). */
declare function encodeURI(str: string): string;
/** Encodes a text string as a valid component of a Uniform Resource Identifier (URI). */
declare function encodeURIComponent(str: string): string;
/** Decodes a Uniform Resource Identifier (URI) previously created by encodeURI. */
declare function decodeURI(str: string): string;
/** Decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent. */
declare function decodeURIComponent(str: string): string;
/** Atomic operations. */
declare namespace atomic {
/** Atomically loads an integer value from memory and returns it. */
export function load<T>(ptr: usize, immOffset?: usize): T;
/** Atomically stores an integer value to memory. */
export function store<T>(ptr: usize, value: T, immOffset?: usize): void;
/** Atomically adds an integer value in memory. */
export function add<T>(ptr: usize, value: T, immOffset?: usize): T;
/** Atomically subtracts an integer value in memory. */
export function sub<T>(ptr: usize, value: T, immOffset?: usize): T;
/** Atomically performs a bitwise AND operation on an integer value in memory. */
export function and<T>(ptr: usize, value: T, immOffset?: usize): T;
/** Atomically performs a bitwise OR operation on an integer value in memory. */
export function or<T>(ptr: usize, value: T, immOffset?: usize): T;
/** Atomically performs a bitwise XOR operation on an integer value in memory. */
export function xor<T>(ptr: usize, value: T, immOffset?: usize): T;
/** Atomically exchanges an integer value in memory. */
export function xchg<T>(ptr: usize, value: T, immOffset?: usize): T;
/** Atomically compares and exchanges an integer value in memory if the condition is met. */
export function cmpxchg<T>(ptr: usize, expected: T, replacement: T, immOffset?: usize): T;
/** Performs a wait operation on an address in memory suspending this agent if the integer condition is met. */
export function wait<T>(ptr: usize, expected: T, timeout?: i64): AtomicWaitResult;
/** Performs a notify operation on an address in memory waking up suspended agents. */
export function notify(ptr: usize, count?: i32): i32;
/** Performs a fence operation, preserving synchronization guarantees of higher level languages. */
export function fence(): void;
}
/** Describes the result of an atomic wait operation. */
declare enum AtomicWaitResult {
/** Woken by another agent. */
OK,
/** Loaded value did not match the expected value. */
NOT_EQUAL,
/** Not woken before the timeout expired. */
TIMED_OUT
}
/** Converts any other numeric value to an 8-bit signed integer. */
declare function i8(value: any): i8;
declare namespace i8 {
/** Smallest representable value. */
export const MIN_VALUE: i8;
/** Largest representable value. */
export const MAX_VALUE: i8;
/** Parses a string as an i8. */
export function parse(value: string, radix?: i32): i8;
}
/** Converts any other numeric value to a 16-bit signed integer. */
declare function i16(value: any): i16;
declare namespace i16 {
/** Smallest representable value. */
export const MIN_VALUE: i16;
/** Largest representable value. */
export const MAX_VALUE: i16;
/** Parses a string as an i16. */
export function parse(value: string, radix?: i32): i16;
}
/** Converts any other numeric value to a 32-bit signed integer. */
declare function i32(value: any): i32;
declare namespace i32 {
/** Smallest representable value. */
export const MIN_VALUE: i32;
/** Largest representable value. */
export const MAX_VALUE: i32;
/** Parses a string as an i32. */
export function parse(value: string, radix?: i32): i32;
/** Loads an 8-bit signed integer value from memory and returns it as a 32-bit integer. */
export function load8_s(ptr: usize, immOffset?: usize, immAlign?: usize): i32;
/** Loads an 8-bit unsigned integer value from memory and returns it as a 32-bit integer. */
export function load8_u(ptr: usize, immOffset?: usize, immAlign?: usize): i32;
/** Loads a 16-bit signed integer value from memory and returns it as a 32-bit integer. */
export function load16_s(ptr: usize, immOffset?: usize, immAlign?: usize): i32;
/** Loads a 16-bit unsigned integer value from memory and returns it as a 32-bit integer. */
export function load16_u(ptr: usize, immOffset?: usize, immAlign?: usize): i32;
/** Loads a 32-bit integer value from memory. */
export function load(ptr: usize, immOffset?: usize, immAlign?: usize): i32;
/** Stores a 32-bit integer value to memory as an 8-bit integer. */
export function store8(ptr: usize, value: i32, immOffset?: usize, immAlign?: usize): void;
/** Stores a 32-bit integer value to memory as a 16-bit integer. */
export function store16(ptr: usize, value: i32, immOffset?: usize, immAlign?: usize): void;
/** Stores a 32-bit integer value to memory. */
export function store(ptr: usize, value: i32, immOffset?: usize, immAlign?: usize): void;
/** Performs the sign-agnostic count leading zero bits operation on a 32-bit integer. All zero bits are considered leading if the value is zero. */
export function clz(value: i32): i32;
/** Performs the sign-agnostic count tailing zero bits operation on a 32-bit integer. All zero bits are considered trailing if the value is zero. */
export function ctz(value: i32): i32;
/** Performs the sign-agnostic count number of one bits operation on a 32-bit integer. */
export function popcnt(value: i32): i32;
/** Performs the sign-agnostic rotate left operation on a 32-bit integer. */
export function rotl(value: i32, shift: i32): i32;
/** Performs the sign-agnostic rotate right operation on a 32-bit integer. */
export function rotr(value: i32, shift: i32): i32;
/** Reinterprets the bits of the specified 32-bit float as a 32-bit integer. */
export function reinterpret_f32(value: f32): i32;
/** Computes the sum of two 32-bit integers. */
export function add(left: i32, right: i32): i32;
/** Computes the difference of two 32-bit integers. */
export function sub(left: i32, right: i32): i32;
/** Computes the product of two 32-bit integers. */
export function mul(left: i32, right: i32): i32;
/** Computes the signed quotient of two 32-bit integers. */
export function div_s(left: i32, right: i32): i32;
/** Computes the unsigned quotient of two 32-bit integers. */
export function div_u(left: i32, right: i32): i32;
/** Return 1 if two 32-bit integers are equal to each other, 0 otherwise. */
export function eq(left: i32, right: i32): i32;
/** Return 0 if two 32-bit integers are equal to each other, 1 otherwise. */
export function ne(left: i32, right: i32): i32;
/** Computes the signed remainder of two 32-bit integers. */
export function rem_s(left: i32, right: i32): i32;
/** Computes the unsigned remainder of two 32-bit integers. */
export function rem_u(left: u32, right: u32): u32;
/** Atomic 32-bit integer operations. */
export namespace atomic {
/** Atomically loads an 8-bit unsigned integer value from memory and returns it as a 32-bit integer. */
export function load8_u(ptr: usize, immOffset?: usize): i32;
/** Atomically loads a 16-bit unsigned integer value from memory and returns it as a 32-bit integer. */
export function load16_u(ptr: usize, immOffset?: usize): i32;
/** Atomically loads a 32-bit integer value from memory and returns it. */
export function load(ptr: usize, immOffset?: usize): i32;
/** Atomically stores a 32-bit integer value to memory as an 8-bit integer. */
export function store8(ptr: usize, value: i32, immOffset?: usize): void;
/** Atomically stores a 32-bit integer value to memory as a 16-bit integer. */
export function store16(ptr: usize, value: i32, immOffset?: usize): void;
/** Atomically stores a 32-bit integer value to memory. */
export function store(ptr: usize, value: i32, immOffset?: usize): void;
/** Atomic 32-bit integer read-modify-write operations on 8-bit values. */
export namespace rmw8 {
/** Atomically adds an 8-bit unsigned integer value in memory. */
export function add_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically subtracts an 8-bit unsigned integer value in memory. */
export function sub_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically performs a bitwise AND operation an 8-bit unsigned integer value in memory. */
export function and_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically performs a bitwise OR operation an 8-bit unsigned integer value in memory. */
export function or_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically performs a bitwise XOR operation an 8-bit unsigned integer value in memory. */
export function xor_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically exchanges an 8-bit unsigned integer value in memory. */
export function xchg_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically compares and exchanges an 8-bit unsigned integer value in memory if the condition is met. */
export function cmpxchg_u(ptr: usize, expected: i32, replacement: i32, immOffset?: usize): i32;
}
/** Atomic 32-bit integer read-modify-write operations on 16-bit values. */
export namespace rmw16 {
/** Atomically adds a 16-bit unsigned integer value in memory. */
export function add_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically adds a 16-bit unsigned integer value in memory. */
export function sub_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically performs a bitwise AND operation a 16-bit unsigned integer value in memory. */
export function and_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically performs a bitwise OR operation a 16-bit unsigned integer value in memory. */
export function or_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically performs a bitwise XOR operation a 16-bit unsigned integer value in memory. */
export function xor_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically exchanges a 16-bit unsigned integer value in memory. */
export function xchg_u(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically compares and exchanges a 16-bit unsigned integer value in memory if the condition is met. */
export function cmpxchg_u(ptr: usize, expected: i32, replacement: i32, immOffset?: usize): i32;
}
/** Atomic 32-bit integer read-modify-write operations. */
export namespace rmw {
/** Atomically adds a 32-bit integer value in memory. */
export function add(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically subtracts a 32-bit integer value in memory. */
export function sub(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically performs a bitwise AND operation a 32-bit integer value in memory. */
export function and(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically performs a bitwise OR operation a 32-bit integer value in memory. */
export function or(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically performs a bitwise XOR operation a 32-bit integer value in memory. */
export function xor(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically exchanges a 32-bit integer value in memory. */
export function xchg(ptr: usize, value: i32, immOffset?: usize): i32;
/** Atomically compares and exchanges a 32-bit integer value in memory if the condition is met. */
export function cmpxchg(ptr: usize, expected: i32, replacement: i32, immOffset?: usize): i32;
}
}
}
/** Converts any other numeric value to a 64-bit signed integer. */
declare function i64(value: any): i64;
declare namespace i64 {
/** Smallest representable value. */
export const MIN_VALUE: i64;
/** Largest representable value. */
export const MAX_VALUE: i64;
/** Parses a string as an i64. */
export function parse(value: string, radix?: i32): i64;
/** Loads an 8-bit signed integer value from memory and returns it as a 64-bit integer. */
export function load8_s(ptr: usize, immOffset?: usize, immAlign?: usize): i64;
/** Loads an 8-bit unsigned integer value from memory and returns it as a 64-bit integer. */
export function load8_u(ptr: usize, immOffset?: usize, immAlign?: usize): i64;
/** Loads a 16-bit signed integer value from memory and returns it as a 64-bit integer. */
export function load16_s(ptr: usize, immOffset?: usize, immAlign?: usize): i64;
/** Loads a 16-bit unsigned integer value from memory and returns it as a 64-bit integer. */
export function load16_u(ptr: usize, immOffset?: usize, immAlign?: usize): i64;
/** Loads a 32-bit signed integer value from memory and returns it as a 64-bit integer. */
export function load32_s(ptr: usize, immOffset?: usize, immAlign?: usize): i64;
/** Loads a 32-bit unsigned integer value from memory and returns it as a 64-bit integer. */
export function load32_u(ptr: usize, immOffset?: usize, immAlign?: usize): i64;
/** Loads a 64-bit unsigned integer value from memory. */
export function load(ptr: usize, immOffset?: usize, immAlign?: usize): i64;
/** Stores a 64-bit integer value to memory as an 8-bit integer. */
export function store8(ptr: usize, value: i64, immOffset?: usize, immAlign?: usize): void;
/** Stores a 64-bit integer value to memory as a 16-bit integer. */
export function store16(ptr: usize, value: i64, immOffset?: usize, immAlign?: usize): void;
/** Stores a 64-bit integer value to memory as a 32-bit integer. */
export function store32(ptr: usize, value: i64, immOffset?: usize, immAlign?: usize): void;
/** Stores a 64-bit integer value to memory. */
export function store(ptr: usize, value: i64, immOffset?: usize, immAlign?: usize): void;
/** Performs the sign-agnostic count leading zero bits operation on a 64-bit integer. All zero bits are considered leading if the value is zero. */
export function clz(value: i64): i64;
/** Performs the sign-agnostic count tailing zero bits operation on a 64-bit integer. All zero bits are considered trailing if the value is zero. */
export function ctz(value: i64): i64;
/** Performs the sign-agnostic count number of one bits operation on a 64-bit integer. */
export function popcnt(value: i64): i64;
/** Performs the sign-agnostic rotate left operation on a 64-bit integer. */
export function rotl(value: i64, shift: i64): i64;
/** Performs the sign-agnostic rotate right operation on a 64-bit integer. */
export function rotr(value: i64, shift: i64): i64;
/** Reinterprets the bits of the specified 64-bit float as a 64-bit integer. */
export function reinterpret_f64(value: f64): i64;
/** Computes the sum of two 64-bit integers. */
export function add(left: i64, right: i64): i64;
/** Computes the difference of two 64-bit integers. */
export function sub(left: i64, right: i64): i64;
/** Computes the product of two 64-bit integers. */
export function mul(left: i64, right: i64): i64;
/** Computes the signed quotient of two 64-bit integers. */
export function div_s(left: i64, right: i64): i64;
/** Computes the unsigned quotient of two 64-bit integers. */
export function div_u(left: i64, right: i64): i64;
/** Return 1 if two 64-bit integers are equal to each other, 0 otherwise. */
export function eq(left: i64, right: i64): i32;
/** Return 0 if two 64-bit integers are equal to each other, 1 otherwise. */
export function ne(left: i64, right: i64): i32;
/** Computes the signed remainder of two 64-bit integers. */
export function rem_s(left: i64, right: i64): i64;
/** Computes the unsigned remainder of two 64-bit integers. */
export function rem_u(left: u64, right: u64): u64;
/** Atomic 64-bit integer operations. */
export namespace atomic {
/** Atomically loads an 8-bit unsigned integer value from memory and returns it as a 64-bit integer. */
export function load8_u(ptr: usize, immOffset?: usize): i64;
/** Atomically loads a 16-bit unsigned integer value from memory and returns it as a 64-bit integer. */
export function load16_u(ptr: usize, immOffset?: usize): i64;
/** Atomically loads a 32-bit unsigned integer value from memory and returns it as a 64-bit integer. */
export function load32_u(ptr: usize, immOffset?: usize): i64;
/** Atomically loads a 64-bit integer value from memory and returns it. */
export function load(ptr: usize, immOffset?: usize): i64;
/** Atomically stores a 64-bit integer value to memory as an 8-bit integer. */
export function store8(ptr: usize, value: i64, immOffset?: usize): void;
/** Atomically stores a 64-bit integer value to memory as a 16-bit integer. */
export function store16(ptr: usize, value: i64, immOffset?: usize): void;
/** Atomically stores a 64-bit integer value to memory as a 32-bit integer. */
export function store32(ptr: usize, value: i64, immOffset?: usize): void;
/** Atomically stores a 64-bit integer value to memory. */
export function store(ptr: usize, value: i64, immOffset?: usize): void;
/** Atomic 64-bit integer read-modify-write operations on 8-bit values. */
export namespace rmw8 {
/** Atomically adds an 8-bit unsigned integer value in memory. */
export function add_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically subtracts an 8-bit unsigned integer value in memory. */
export function sub_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise AND operation on an 8-bit unsigned integer value in memory. */
export function and_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise OR operation on an 8-bit unsigned integer value in memory. */
export function or_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise XOR operation on an 8-bit unsigned integer value in memory. */
export function xor_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically exchanges an 8-bit unsigned integer value in memory. */
export function xchg_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically compares and exchanges an 8-bit unsigned integer value in memory if the condition is met. */
export function cmpxchg_u(ptr: usize, expected: i64, replacement: i64, immOffset?: usize): i64;
}
/** Atomic 64-bit integer read-modify-write operations on 16-bit values. */
export namespace rmw16 {
/** Atomically adds a 16-bit unsigned integer value in memory. */
export function add_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically subtracts a 16-bit unsigned integer value in memory. */
export function sub_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise AND operation on a 16-bit unsigned integer value in memory. */
export function and_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise OR operation on a 16-bit unsigned integer value in memory. */
export function or_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise XOR operation on a 16-bit unsigned integer value in memory. */
export function xor_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically exchanges a 16-bit unsigned integer value in memory. */
export function xchg_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically compares and exchanges a 16-bit unsigned integer value in memory if the condition is met. */
export function cmpxchg_u(ptr: usize, expected: i64, replacement: i64, immOffset?: usize): i64;
}
/** Atomic 64-bit integer read-modify-write operations on 32-bit values. */
export namespace rmw32 {
/** Atomically adds a 32-bit unsigned integer value in memory. */
export function add_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically subtracts a 32-bit unsigned integer value in memory. */
export function sub_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise AND operation on a 32-bit unsigned integer value in memory. */
export function and_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise OR operation on a 32-bit unsigned integer value in memory. */
export function or_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise XOR operation on a 32-bit unsigned integer value in memory. */
export function xor_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically exchanges a 32-bit unsigned integer value in memory. */
export function xchg_u(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically compares and exchanges a 32-bit unsigned integer value in memory if the condition is met. */
export function cmpxchg_u(ptr: usize, expected: i64, replacement: i64, immOffset?: usize): i64;
}
/** Atomic 64-bit integer read-modify-write operations. */
export namespace rmw {
/** Atomically adds a 64-bit integer value in memory. */
export function add(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically subtracts a 64-bit integer value in memory. */
export function sub(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise AND operation on a 64-bit integer value in memory. */
export function and(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise OR operation on a 64-bit integer value in memory. */
export function or(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically performs a bitwise XOR operation on a 64-bit integer value in memory. */
export function xor(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically exchanges a 64-bit integer value in memory. */
export function xchg(ptr: usize, value: i64, immOffset?: usize): i64;
/** Atomically compares and exchanges a 64-bit integer value in memory if the condition is met. */
export function cmpxchg(ptr: usize, expected: i64, replacement: i64, immOffset?: usize): i64;
}
}
}
/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) signed integer. */
declare let isize: typeof i32 | typeof i64;
/** Converts any other numeric value to an 8-bit unsigned integer. */
declare function u8(value: any): u8;
declare namespace u8 {
/** Smallest representable value. */
export const MIN_VALUE: u8;
/** Largest representable value. */
export const MAX_VALUE: u8;
/** Parses a string as an u8. */
export function parse(value: string, radix?: i32): u8;
}
/** Converts any other numeric value to a 16-bit unsigned integer. */
declare function u16(value: any): u16;
declare namespace u16 {
/** Smallest representable value. */
export const MIN_VALUE: u16;
/** Largest representable value. */
export const MAX_VALUE: u16;
/** Parses a string as an u16. */
export function parse(value: string, radix?: i32): u16;
}
/** Converts any other numeric value to a 32-bit unsigned integer. */
declare function u32(value: any): u32;
declare namespace u32 {
/** Smallest representable value. */
export const MIN_VALUE: u32;
/** Largest representable value. */
export const MAX_VALUE: u32;
/** Parses a string as an u32. */
export function parse(value: string, radix?: i32): u32;
}
/** Converts any other numeric value to a 64-bit unsigned integer. */
declare function u64(value: any): u64;
declare namespace u64 {
/** Smallest representable value. */
export const MIN_VALUE: u64;
/** Largest representable value. */
export const MAX_VALUE: u64;
/** Parses a string as an u64. */
export function parse(value: string, radix?: i32): u64;
}
/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */
declare let usize: typeof u32 | typeof u64;
/** Converts any other numeric value to a 1-bit unsigned integer. */
declare function bool(value: any): bool;
declare namespace bool {
/** Smallest representable value. */
export const MIN_VALUE: bool;
/** Largest representable value. */
export const MAX_VALUE: bool;
/** Parses a string as a bool. */
export function parse(value: string): bool;
}
/** Converts any other numeric value to a 32-bit float. */
declare function f32(value: any): f32;
declare namespace f32 {
/** Smallest representable value. */
export const MIN_VALUE: f32;
/** Largest representable value. */
export const MAX_VALUE: f32;
/** Smallest normalized positive value. */
export const MIN_NORMAL_VALUE: f32;
/** Smallest safely representable integer value. */
export const MIN_SAFE_INTEGER: f32;
/** Largest safely representable integer value. */
export const MAX_SAFE_INTEGER: f32;
/** Positive infinity value. */
export const POSITIVE_INFINITY: f32;
/** Negative infinity value. */
export const NEGATIVE_INFINITY: f32;
/** Not a number value. */
export const NaN: f32;
/** Difference between 1 and the smallest representable value greater than 1. */
export const EPSILON: f32;
/** Parses a string as an f32. */
export function parse(value: string): f32;
/** Loads a 32-bit float from memory. */
export function load(ptr: usize, immOffset?: usize, immAlign?: usize): f32;
/** Stores a 32-bit float to memory. */
export function store(ptr: usize, value: f32, immOffset?: usize, immAlign?: usize): void;
/** Computes the sum of two 32-bit floats. */
export function add(left: f32, right: f32): f32;
/** Computes the difference of two 32-bit floats. */
export function sub(left: f32, right: f32): f32;
/** Computes the product of two 32-bit floats. */
export function mul(left: f32, right: f32): f32;
/** Computes the quotient of two 32-bit floats. */
export function div(left: f32, right: f32): f32;
/** Return 1 two 32-bit floats are equal to each other, 0 otherwise. */
export function eq(left: f32, right: f32): i32;
/** Return 0 two 32-bit floats are equal to each other, 1 otherwise. */
export function ne(left: f32, right: f32): i32;
/** Computes the absolute value of a 32-bit float. */
export function abs(value: f32): f32;
/** Determines the maximum of two 32-bit floats. If either operand is `NaN`, returns `NaN`. */
export function max(left: f32, right: f32): f32;
/** Determines the minimum of two 32-bit floats. If either operand is `NaN`, returns `NaN`. */
export function min(left: f32, right: f32): f32;
/** Performs the ceiling operation on a 32-bit float. */
export function ceil(value: f32): f32;
/** Composes a 32-bit float from the magnitude of `x` and the sign of `y`. */
export function copysign(x: f32, y: f32): f32;
/** Performs the floor operation on a 32-bit float. */
export function floor(value: f32): f32;
/** Rounds to the nearest integer tied to even of a 32-bit float. */
export function nearest(value: f32): f32;
/** Reinterprets the bits of the specified 32-bit integer as a 32-bit float. */
export function reinterpret_i32(value: i32): f32;
/** Calculates the square root of a 32-bit float. */
export function sqrt(value: f32): f32;
/** Rounds to the nearest integer towards zero of a 32-bit float. */
export function trunc(value: f32): f32;
}
/** Converts any other numeric value to a 64-bit float. */
declare function f64(value: any): f64;
declare namespace f64 {
/** Smallest representable value. */
export const MIN_VALUE: f64;
/** Largest representable value. */
export const MAX_VALUE: f64;
/** Smallest normalized positive value. */
export const MIN_NORMAL_VALUE: f64;
/** Smallest safely representable integer value. */
export const MIN_SAFE_INTEGER: f64;
/** Largest safely representable integer value. */
export const MAX_SAFE_INTEGER: f64;
/** Positive infinity value. */
export const POSITIVE_INFINITY: f64;
/** Negative infinity value. */
export const NEGATIVE_INFINITY: f64;
/** Not a number value. */
export const NaN: f64;
/** Difference between 1 and the smallest representable value greater than 1. */
export const EPSILON: f64;
/** Parses a string as an f64. */
export function parse(value: string): f64;
/** Loads a 64-bit float from memory. */
export function load(ptr: usize, immOffset?: usize, immAlign?: usize): f64;
/** Stores a 64-bit float to memory. */
export function store(ptr: usize, value: f64, immOffset?: usize, immAlign?: usize): void;
/** Computes the sum of two 64-bit floats. */
export function add(left: f64, right: f64): f64;
/** Computes the difference of two 64-bit floats. */
export function sub(left: f64, right: f64): f64;
/** Computes the product of two 64-bit floats. */
export function mul(left: f64, right: f64): f64;
/** Computes the quotient of two 64-bit floats. */
export function div(left: f64, right: f64): f64;
/** Return 1 two 64-bit floats are equal to each other, 0 otherwise. */
export function eq(left: f64, right: f64): i32;
/** Return 0 two 32-bit floats are equal to each other, 1 otherwise. */
export function ne(left: f64, right: f64): i32;
/** Computes the absolute value of a 64-bit float. */
export function abs(value: f64): f64;
/** Determines the maximum of two 64-bit floats. If either operand is `NaN`, returns `NaN`. */
export function max(left: f64, right: f64): f64;
/** Determines the minimum of two 64-bit floats. If either operand is `NaN`, returns `NaN`. */
export function min(left: f64, right: f64): f64;
/** Performs the ceiling operation on a 64-bit float. */
export function ceil(value: f64): f64;
/** Composes a 64-bit float from the magnitude of `x` and the sign of `y`. */
export function copysign(x: f64, y: f64): f64;
/** Performs the floor operation on a 64-bit float. */
export function floor(value: f64): f64;
/** Rounds to the nearest integer tied to even of a 64-bit float. */
export function nearest(value: f64): f64;
/** Reinterprets the bits of the specified 64-bit integer as a 64-bit float. */
export function reinterpret_i64(value: i64): f64;
/** Calculates the square root of a 64-bit float. */
export function sqrt(value: f64): f64;
/** Rounds to the nearest integer towards zero of a 64-bit float. */
export function trunc(value: f64): f64;
}
/** Initializes a 128-bit vector from sixteen 8-bit integer values. Arguments must be compile-time constants. */
declare function v128(a: i8, b: i8, c: i8, d: i8, e: i8, f: i8, g: i8, h: i8, i: i8, j: i8, k: i8, l: i8, m: i8, n: i8, o: i8, p: i8): v128;
declare namespace v128 {
/** Creates a vector with identical lanes. */
export function splat<T>(x: T): v128;
/** Extracts one lane as a scalar. idx argument needs to be compile time constant. */
export function extract_lane<T>(x: v128, idx: u8): T;
/** Replaces one lane. idx argument needs to be compile time constant.*/
export function replace_lane<T>(x: v128, idx: u8, value: T): v128;
/** Selects lanes from either vector according to the specified lane indexes. */
export function shuffle<T>(a: v128, b: v128, ...lanes: u8[]): v128;
/** Selects 8-bit lanes from the first vector according to the indexes [0-15] specified by the 8-bit lanes of the second vector. */
export function swizzle(a: v128, s: v128): v128;
/** Loads a vector from memory. */
export function load(ptr: usize, immOffset?: usize, immAlign?: usize): v128;
/** Creates a vector by loading the lanes of the specified type and extending each to the next larger type. */
export function load_ext<TFrom>(ptr: usize, immOffset?: usize, immAlign?: usize): v128;
/** Creates a vector by loading a value of the specified type into the lowest bits and initializing all other bits of the vector to zero. */
export function load_zero<TFrom>(ptr: usize, immOffset?: usize, immAlign?: usize): v128;
/** Loads a single lane from memory into the specified lane of the given vector. Other lanes are bypassed as is. */
export function load_lane<T>(ptr: usize, vec: v128, idx: u8, immOffset?: usize, immAlign?: usize): v128;
/** Stores the single lane at the specified index of the given vector to memory. */
export function store_lane<T>(ptr: usize, vec: v128, idx: u8, immOffset?: usize, immAlign?: usize): void;
/** Creates a vector with eight 16-bit integer lanes by loading and sign extending eight 8-bit integers. */
export function load8x8_s(ptr: usize, immOffset?: u32, immAlign?: u32): v128;
/** Creates a vector with eight 16-bit integer lanes by loading and zero extending eight 8-bit integers. */
export function load8x8_u(ptr: usize, immOffset?: u32, immAlign?: u32): v128;
/** Creates a vector with four 32-bit integer lanes by loading and sign extending four 16-bit integers. */
export function load16x4_s(ptr: usize, immOffset?: u32, immAlign?: u32): v128;
/** Creates a vector with four 32-bit integer lanes by loading and zero extending four 16-bit integers. */
export function load16x4_u(ptr: usize, immOffset?: u32, immAlign?: u32): v128;
/** Creates a vector with two 64-bit integer lanes by loading and sign extending two 32-bit integers. */
export function load32x2_s(ptr: usize, immOffset?: u32, immAlign?: u32): v128;
/** Creates a vector with two 64-bit integer lanes by loading and zero extending two 32-bit integers. */
export function load32x2_u(ptr: usize, immOffset?: u32, immAlign?: u32): v128;
/** Creates a vector with identical lanes by loading the splatted value. */
export function load_splat<T>(ptr: usize, immOffset?: usize, immAlign?: usize): v128;
/** Loads an 8-bit integer and splats it sixteen times forming a new vector. */
export function load8_splat(ptr: usize, immOffset?: usize, immAlign?: usize): v128;
/** Loads a 16-bit integer and splats it eight times forming a new vector. */
export function load16_splat(ptr: usize, immOffset?: usize, immAlign?: usize): v128;
/** Loads a 32-bit integer and splats it four times forming a new vector. */
export function load32_splat(ptr: usize, immOffset?: usize, immAlign?: usize): v128;
/** Loads a 64-bit integer and splats it two times forming a new vector. */
export function load64_splat(ptr: usize, immOffset?: usize, immAlign?: usize): v128;
/** Creates a vector by loading a 3