2018-03-17 23:41:48 +01:00
/ * *
2018-03-19 01:12:18 +01:00
* Environment definitions for compiling AssemblyScript to WebAssembly using asc .
* @module std / assembly
* //***/
2017-12-08 19:08:03 +01:00
// Types
2017-12-01 02:18:36 +01:00
2017-10-19 18:55:27 +02:00
/** 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. */
2018-04-18 16:32:07 +02:00
declare type bool = boolean | number ;
2017-10-19 18:55:27 +02:00
/** A 32-bit float. */
declare type f32 = number ;
/** A 64-bit float. */
declare type f64 = number ;
2017-12-15 15:00:19 +01:00
/** Converts any other numeric value to an 8-bit signed integer. */
declare function i8 ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : i8 ;
declare namespace i8 {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : i8 ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : i8 ;
}
/** Converts any other numeric value to a 16-bit signed integer. */
declare function i16 ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : i8 ;
declare namespace i16 {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : i16 ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : i16 ;
}
/** Converts any other numeric value to a 32-bit signed integer. */
declare function i32 ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : i32 ;
declare namespace i32 {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : i32 ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : i32 ;
}
/** Converts any other numeric value to a 64-bit signed integer. */
declare function i64 ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : i64 ;
declare namespace i64 {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : i64 ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : i64 ;
}
/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) signed integer. */
declare function isize ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : isize ;
declare namespace isize {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : isize ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : isize ;
}
/** Converts any other numeric value to an 8-bit unsigned integer. */
declare function u8 ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : i8 ;
declare namespace u8 {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : u8 ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : u8 ;
}
/** Converts any other numeric value to a 16-bit unsigned integer. */
declare function u16 ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : i8 ;
declare namespace u16 {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : u16 ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : u16 ;
}
/** Converts any other numeric value to a 32-bit unsigned integer. */
declare function u32 ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : i32 ;
declare namespace u32 {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : u32 ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : u32 ;
}
/** Converts any other numeric value to a 64-bit unsigned integer. */
declare function u64 ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : i64 ;
declare namespace u64 {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : u64 ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : u64 ;
}
/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */
declare function usize ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : isize ;
declare namespace usize {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : usize ;
2018-03-21 01:16:46 +01:00
/** Largesst representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : usize ;
}
/** Converts any other numeric value to a 1-bit unsigned integer. */
declare function bool ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : bool ;
declare namespace bool {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2017-12-15 15:00:19 +01:00
export const MIN_VALUE : bool ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2017-12-15 15:00:19 +01:00
export const MAX_VALUE : bool ;
}
/** Converts any other numeric value to a 32-bit float. */
declare function f32 ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : f32 ;
declare namespace f32 {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2018-01-02 21:41:25 +01:00
export const MIN_VALUE : f32 ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2018-01-02 21:41:25 +01:00
export const MAX_VALUE : f32 ;
2018-03-21 01:16:46 +01:00
/** Smallest normalized positive value. */
2018-03-21 02:06:56 +02:00
export const MIN_POSITIVE_VALUE : f32 ;
2018-01-02 21:41:25 +01:00
/** Smallest safely representable integer value. */
2017-12-15 15:00:19 +01:00
export const MIN_SAFE_INTEGER : f32 ;
2018-01-02 21:41:25 +01:00
/** Largest safely representable integer value. */
2017-12-15 15:00:19 +01:00
export const MAX_SAFE_INTEGER : f32 ;
2018-01-02 21:41:25 +01:00
/** Difference between 1 and the smallest representable value greater than 1. */
export const EPSILON : f32 ;
2018-03-30 17:25:54 +02:00
/** Returns the floating-point remainder of `x / y` (rounded towards zero). */
export function mod ( x : f32 , y : f32 ) : f32 ;
/** Returns the floating-point remainder of `x / y` (rounded to nearest). */
export function rem ( x : f32 , y : f32 ) : f32 ;
2017-12-15 15:00:19 +01:00
}
/** Converts any other numeric value to a 64-bit float. */
declare function f64 ( value : i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64 ) : f64 ;
declare namespace f64 {
2018-03-21 01:16:46 +01:00
/** Smallest representable value. */
2018-01-02 21:41:25 +01:00
export const MIN_VALUE : f64 ;
2018-03-21 01:16:46 +01:00
/** Largest representable value. */
2018-01-02 21:41:25 +01:00
export const MAX_VALUE : f64 ;
2018-03-21 01:16:46 +01:00
/** Smallest normalized positive value. */
2018-03-21 02:06:56 +02:00
export const MIN_POSITIVE_VALUE : f64 ;
2018-01-02 21:41:25 +01:00
/** Smallest safely representable integer value. */
2017-12-15 15:00:19 +01:00
export const MIN_SAFE_INTEGER : f64 ;
2018-01-02 21:41:25 +01:00
/** Largest safely representable integer value. */
2017-12-15 15:00:19 +01:00
export const MAX_SAFE_INTEGER : f64 ;
2018-01-02 21:41:25 +01:00
/** Difference between 1 and the smallest representable value greater than 1. */
export const EPSILON : f64 ;
2017-12-15 15:00:19 +01:00
}
2017-12-08 19:08:03 +01:00
// Built-ins
2017-12-01 02:18:36 +01:00
/** 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. */
2017-12-04 02:00:48 +01:00
declare function clz < T = i32 | i64 > ( value : T ) : T ;
2017-12-01 02:18:36 +01:00
/** 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. */
2017-12-04 02:00:48 +01:00
declare function ctz < T = i32 | i64 > ( value : T ) : T ;
2017-12-01 02:18:36 +01:00
/** Performs the sign-agnostic count number of one bits operation on a 32-bit or 64-bit integer. */
2017-12-04 02:00:48 +01:00
declare function popcnt < T = i32 | i64 > ( value : T ) : T ;
2017-12-01 02:18:36 +01:00
/** Performs the sign-agnostic rotate left operation on a 32-bit or 64-bit integer. */
2017-12-04 02:00:48 +01:00
declare function rotl < T = i32 | i64 > ( value : T , shift : T ) : T ;
2017-12-01 02:18:36 +01:00
/** Performs the sign-agnostic rotate right operation on a 32-bit or 64-bit integer. */
2017-12-04 02:00:48 +01:00
declare function rotr < T = i32 | i64 > ( value : T , shift : T ) : T ;
2017-12-05 01:45:15 +01:00
/** Computes the absolute value of an integer or float. */
declare function abs < T = 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 = 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 = i32 | i64 | f32 | f64 > ( left : T , right : T ) : T ;
2017-12-01 02:18:36 +01:00
/** Performs the ceiling operation on a 32-bit or 64-bit float. */
2017-12-04 02:00:48 +01:00
declare function ceil < T = f32 | f64 > ( value : T ) : T ;
2017-12-01 02:18:36 +01:00
/** Composes a 32-bit or 64-bit float from the magnitude of `x` and the sign of `y`. */
2017-12-04 02:00:48 +01:00
declare function copysign < T = f32 | f64 > ( x : T , y : T ) : T ;
2017-12-01 02:18:36 +01:00
/** Performs the floor operation on a 32-bit or 64-bit float. */
2017-12-04 02:00:48 +01:00
declare function floor < T = f32 | f64 > ( value : T ) : T ;
2017-12-01 02:18:36 +01:00
/** Rounds to the nearest integer tied to even of a 32-bit or 64-bit float. */
2017-12-04 02:00:48 +01:00
declare function nearest < T = f32 | f64 > ( value : T ) : T ;
2018-01-13 01:15:09 +01:00
/** 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 = i32 | i64 | f32 | f64 > ( value : number ) : T ;
2017-12-04 22:47:08 +01:00
/** Selects one of two pre-evaluated values depending on the condition. */
declare function select < T > ( ifTrue : T , ifFalse : T , condition : bool ) : T ;
2017-12-01 02:18:36 +01:00
/** Calculates the square root of a 32-bit or 64-bit float. */
2017-12-04 02:00:48 +01:00
declare function sqrt < T = f32 | f64 > ( value : T ) : T ;
2017-12-01 02:18:36 +01:00
/** Rounds to the nearest integer towards zero of a 32-bit or 64-bit float. */
2017-12-04 02:00:48 +01:00
declare function trunc < T = f32 | f64 > ( value : T ) : T ;
2017-12-14 16:50:59 +01:00
/** Loads a value of the specified type from memory. Equivalent to dereferncing a pointer in other languages. */
2018-02-25 23:21:32 +01:00
declare function load < T > ( ptr : usize , constantOffset? : usize ) : T ;
2017-12-14 16:50:59 +01:00
/** Stores a value of the specified type to memory. Equivalent to dereferencing a pointer in other languages when assigning a value. */
2018-01-23 15:44:25 +01:00
declare function store < T > ( ptr : usize , value : any , constantOffset? : usize ) : void ;
2017-12-01 02:18:36 +01:00
/** Returns the current memory size in units of pages. One page is 64kb. */
declare function current_memory ( ) : i32 ;
/** Grows linear memory by a given unsigned delta of pages. One page is 64kb. Returns the previous memory size in units of pages or `-1` on failure. */
declare function grow_memory ( value : i32 ) : i32 ;
2018-01-14 02:30:20 +01:00
/** Copies n bytes from the specified source to the specified destination in memory. These regions may overlap. */
declare function move_memory ( destination : usize , source : usize , n : usize ) : void ;
/** Sets n bytes beginning at the specified destination in memory to the specified byte value. */
declare function set_memory ( destination : usize , value : u8 , count : usize ) : void ;
/** Compares two chunks of memory. Returns `0` if equal, otherwise the difference of the first differing bytes. */
declare function compare_memory ( vl : usize , vr : usize , n : usize ) : i32 ;
/** Allocates a chunk of memory of the specified size and returns a pointer to it. */
declare function allocate_memory ( size : usize ) : usize ;
/** Disposes a chunk of memory by its pointer. */
declare function free_memory ( ptr : usize ) : void ;
2017-12-14 16:50:59 +01:00
/** Emits an unreachable operation that results in a runtime error when executed. Both a statement and an expression of any type. */
2017-12-04 14:49:24 +01:00
declare function unreachable ( ) : any ; // sic
2017-12-01 02:18:36 +01:00
2018-02-19 13:35:28 +02:00
/** [Polyfill] Performs the sign-agnostic reverse bytes **/
declare function bswap < T = i8 | u8 | i16 | u16 | i32 | u32 | i64 | u64 | isize | usize > ( value : T ) : T ;
/** [Polyfill] Performs the sign-agnostic reverse bytes only for last 16-bit **/
declare function bswap16 < T = i8 | u8 | i16 | u16 | i32 | u32 > ( value : T ) : T ;
2017-12-01 02:18:36 +01:00
/** NaN (not a number) as a 32-bit or 64-bit float depending on context. */
2017-12-04 02:00:48 +01:00
declare const NaN : f32 | f64 ;
2017-12-01 02:18:36 +01:00
/** Positive infinity as a 32-bit or 64-bit float depending on context. */
2017-12-04 02:00:48 +01:00
declare const Infinity : f32 | f64 ;
2017-12-16 17:54:53 +01:00
/** Heap base offset. */
declare const HEAP_BASE : usize ;
2018-04-02 19:05:26 +02:00
/** Determines the byte size of the specified underlying core type. Compiles to a constant. */
2017-12-04 22:47:08 +01:00
declare function sizeof < T > ( ) : usize ;
2018-04-02 19:05:26 +02:00
/** Determines the alignment (log2) of the specified underlying core type. Compiles to a constant. */
declare function alignof < T > ( ) : usize ;
2018-03-24 00:38:49 +01:00
/** 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 ;
2018-01-10 13:09:05 +01:00
/** 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.*/
2017-12-28 17:16:37 +01:00
declare function changetype < T > ( value : any ) : T ;
2017-12-14 16:50:59 +01:00
/** Tests if a 32-bit or 64-bit float is `NaN`. */
2017-12-04 02:00:48 +01:00
declare function isNaN < T = f32 | f64 > ( value : T ) : bool ;
2017-12-14 16:50:59 +01:00
/** Tests if a 32-bit or 64-bit float is finite, that is not `NaN` or +/-`Infinity`. */
2017-12-04 02:00:48 +01:00
declare function isFinite < T = f32 | f64 > ( value : T ) : bool ;
2018-03-17 12:54:37 +01:00
/** Tests if the specified expression is of an integer type and not a reference. Compiles to a constant. */
2018-04-07 23:31:36 +02:00
declare function isInteger < T > ( value? : any ) : value is number ;
2018-03-17 12:54:37 +01:00
/** Tests if the specified expression is of a float type. Compiles to a constant. */
2018-04-07 23:31:36 +02:00
declare function isFloat < T > ( value? : any ) : value is number ;
2018-03-17 12:54:37 +01:00
/** Tests if the specified expression is of a reference type. Compiles to a constant. */
2018-04-07 23:31:36 +02:00
declare function isReference < T > ( value? : any ) : value is object | string ;
2018-03-17 12:54:37 +01:00
/** Tests if the specified expression can be used ass a string. Compiles to a constant. */
2018-04-07 23:31:36 +02:00
declare function isString < T > ( value? : any ) : value is string | String ;
2018-03-17 12:54:37 +01:00
/** Tests if the specified expression can be used as an array. Compiles to a constant. */
2018-04-07 23:31:36 +02:00
declare function isArray < T > ( value? : any ) : value is Array < any > ;
2018-01-30 01:26:38 +01:00
/** Traps if the specified value is not true-ish, otherwise returns the (non-nullable) value. */
2018-01-10 13:09:05 +01:00
declare function assert < T > ( isTrueish : T , message? : string ) : T & object ; // any better way to model `: T != null`?
2017-12-12 01:35:48 +01:00
/** Parses an integer string to a 64-bit float. */
declare function parseInt ( str : string , radix? : i32 ) : f64 ;
2018-01-30 06:05:35 +01:00
/** Parses an integer string to a 32-bit integer. */
declare function parseI32 ( str : string , radix? : i32 ) : i32 ;
2018-01-30 01:26:38 +01:00
/** Parses an integer string to a 64-bit integer. */
declare function parseI64 ( str : string , radix? : i32 ) : i64 ;
2017-12-12 01:35:48 +01:00
/** Parses a string to a 64-bit float. */
declare function parseFloat ( str : string ) : f64 ;
2018-03-24 18:39:20 +01:00
/** 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 ;
2017-12-01 02:18:36 +01:00
2018-03-23 01:47:01 +01:00
// Standard library
/** Class representing a generic, fixed-length raw binary data buffer. */
declare class ArrayBuffer {
/** The size, in bytes, of the array. */
readonly byteLength : i32 ;
/** Constructs a new array buffer of the given length in bytes. */
constructor ( length : i32 ) ;
/** Returns a copy of this array buffer's bytes from begin, inclusive, up to end, exclusive. */
slice ( begin? : i32 , end? : i32 ) : ArrayBuffer ;
}
2017-12-01 02:18:36 +01:00
2018-04-02 19:05:26 +02:00
/** Interface for a typed view on an array buffer. */
2018-04-07 03:27:22 +02:00
interface ArrayBufferView < T > {
2018-04-02 19:05:26 +02:00
[ key : number ] : T ;
/** The {@link ArrayBuffer} referenced by this view. */
readonly buffer : ArrayBuffer ;
/** The offset in bytes from the start of the referenced {@link ArrayBuffer}. */
readonly byteOffset : i32 ;
/** The length in bytes from the start of the referenced {@link ArrayBuffer}. */
readonly byteLength : i32 ;
}
2018-04-07 03:27:22 +02:00
/* @internal */
declare abstract class TypedArray < T > implements ArrayBufferView < T > {
[ key : number ] : T ;
/** Number of bytes per element. */
static readonly BYTES_PER_ELEMENT : usize ;
/** Constructs a new typed array. */
constructor ( length : i32 ) ;
/** The {@link ArrayBuffer} referenced by this view. */
readonly buffer : ArrayBuffer ;
/** The offset in bytes from the start of the referenced {@link ArrayBuffer}. */
readonly byteOffset : i32 ;
/** The length in bytes from the start of the referenced {@link ArrayBuffer}. */
readonly byteLength : i32 ;
/** The length (in elements). */
readonly length : i32 ;
2018-04-11 23:35:19 +02:00
/** Returns a new TypedArray of this type on the same ArrayBuffer from begin inclusive to end exclusive. */
subarray ( begin? : i32 , end? : i32 ) : this ;
2018-04-07 03:27:22 +02:00
}
/** An array of twos-complement 8-bit signed integers. */
declare class Int8Array extends TypedArray < i8 > { }
/** An array of 8-bit unsigned integers. */
declare class Uint8Array extends TypedArray < u8 > { }
/** An array of twos-complement 16-bit signed integers. */
declare class Int16Array extends TypedArray < i16 > { }
/** An array of 16-bit unsigned integers. */
declare class Uint16Array extends TypedArray < u16 > { }
/** An array of twos-complement 32-bit signed integers. */
declare class Int32Array extends TypedArray < i32 > { }
/** An array of 32-bit unsigned integers. */
declare class Uint32Array extends TypedArray < u32 > { }
/** An array of twos-complement 64-bit signed integers. */
declare class Int64Array extends TypedArray < i64 > { }
/** An array of 64-bit unsigned integers. */
declare class Uint64Array extends TypedArray < u64 > { }
/** An array of 32-bit floating point numbers. */
declare class Float32Array extends TypedArray < f32 > { }
/** An array of 64-bit floating point numbers. */
declare class Float64Array extends TypedArray < f64 > { }
2017-12-16 17:54:53 +01:00
/** Class representing a sequence of values of type `T`. */
declare class Array < T > {
2017-12-23 00:48:54 +01:00
[ key : number ] : T ;
2017-12-16 17:54:53 +01:00
/** Current length of the array. */
length : i32 ;
/** Constructs a new array. */
constructor ( capacity? : i32 ) ;
2018-03-25 13:13:53 +02:00
every ( callbackfn : ( element : T , index : i32 , array? : Array < T > ) = > bool ) : bool ;
findIndex ( predicate : ( element : T , index : i32 , array? : Array < T > ) = > bool ) : i32 ;
2018-03-17 17:02:15 +01:00
includes ( searchElement : T , fromIndex? : i32 ) : bool ;
2018-01-14 21:17:43 +01:00
indexOf ( searchElement : T , fromIndex? : i32 ) : i32 ;
lastIndexOf ( searchElement : T , fromIndex? : i32 ) : i32 ;
push ( element : T ) : void ;
pop ( ) : T ;
2018-04-22 23:15:38 +03:00
forEach ( callbackfn : ( value : T , index : i32 , array : Array < T > ) = > void ) : void ;
map < U > ( callbackfn : ( value : T , index : i32 , array : Array < T > ) = > U ) : Array < U > ;
filter ( callbackfn : ( value : T , index : i32 , array : Array < T > ) = > bool ) : Array < T > ;
2018-03-25 13:13:53 +02:00
reduce < U > ( callbackfn : ( previousValue : U , currentValue : T , currentIndex : i32 , array : Array < T > ) = > U , initialValue : U ) : U ;
2018-04-22 23:15:38 +03:00
reduceRight < U > ( callbackfn : ( previousValue : U , currentValue : T , currentIndex : i32 , array : Array < T > ) = > U , initialValue : U ) : U ;
2018-01-14 21:17:43 +01:00
shift ( ) : T ;
2018-03-25 13:13:53 +02:00
some ( callbackfn : ( element : T , index : i32 , array? : Array < T > ) = > bool ) : bool ;
2018-01-14 21:17:43 +01:00
unshift ( element : T ) : i32 ;
slice ( from : i32 , to? : i32 ) : T [ ] ;
splice ( start : i32 , deleteCount? : i32 ) : void ;
reverse ( ) : T [ ] ;
2018-04-22 23:15:38 +03:00
sort ( comparator ? : ( a : T , b : T ) = > i32 ) : this ;
2017-12-16 17:54:53 +01:00
}
2018-01-13 23:38:07 +01:00
/** Class representing a C-like array of values of type `T` with limited capabilities. */
declare class CArray < T > {
[ key : number ] : T ;
private constructor ( ) ;
}
2017-12-16 17:54:53 +01:00
/** Class representing a sequence of characters. */
2017-12-12 09:32:03 +01:00
declare class String {
2017-12-21 10:14:53 +01:00
2017-12-12 09:32:03 +01:00
static fromCharCode ( ls : i32 , hs? : i32 ) : string ;
static fromCharCodes ( arr : u16 [ ] ) : string ;
static fromCodePoint ( cp : i32 ) : string ;
static fromCodePoints ( arr : i32 [ ] ) : string ;
2017-12-21 10:14:53 +01:00
readonly length : u32 ;
charAt ( index : u32 ) : string ;
charCodeAt ( index : u32 ) : u16 ;
concat ( other : string ) : string ;
endsWith ( other : string ) : bool ;
indexOf ( other : string ) : u32 ;
2018-01-28 15:13:31 +01:00
includes ( other : string ) : bool ;
2017-12-21 10:14:53 +01:00
startsWith ( other : string ) : bool ;
substr ( start : u32 , length? : u32 ) : string ;
substring ( start : u32 , end? : u32 ) : string ;
trim ( ) : string ;
trimLeft ( ) : string ;
trimRight ( ) : string ;
2018-04-07 19:59:26 +03:00
repeat ( count? : i32 ) : string ;
toString ( ) : string ;
2017-12-12 09:32:03 +01:00
}
2017-12-16 17:54:53 +01:00
/** Class for representing a runtime error. Base class of all errors. */
declare class Error {
/** Error name. */
name : string ;
/** Message provided on construction. */
message : string ;
/** Stack trace. */
stack : string ;
/** Constructs a new error, optionally with a message. */
constructor ( message? : string ) ;
}
/** Class for indicating an error when a value is not in the set or range of allowed values. */
declare class RangeError extends Error { }
interface Boolean { }
interface Function { }
interface IArguments { }
interface Number { }
interface Object { }
interface RegExp { }
2018-01-15 00:08:06 +01:00
declare class Set < T > {
readonly size : i32 ;
has ( value : T ) : bool ;
add ( value : T ) : void ;
delete ( value : T ) : bool ;
clear ( ) : void ;
}
2018-03-26 16:54:25 +02:00
interface IMath < T > {
2018-03-26 23:46:41 +02:00
/** The base of natural logarithms, e, approximately 2.718. */
2018-03-26 16:54:25 +02:00
readonly E : T ;
2018-03-26 23:46:41 +02:00
/** The natural logarithm of 2, approximately 0.693. */
2018-03-26 16:54:25 +02:00
readonly LN2 : T ;
2018-03-26 23:46:41 +02:00
/** The natural logarithm of 10, approximately 2.302. */
2018-03-26 16:54:25 +02:00
readonly LN10 : T ;
2018-03-26 23:46:41 +02:00
/** The base 2 logarithm of e, approximately 1.442. */
2018-03-26 16:54:25 +02:00
readonly LOG2E : T ;
2018-03-26 23:46:41 +02:00
/** The base 10 logarithm of e, approximately 0.434. */
2018-03-26 16:54:25 +02:00
readonly LOG10E : T ;
2018-03-26 23:46:41 +02:00
/** The ratio of the circumference of a circle to its diameter, approximately 3.14159. */
2018-03-26 16:54:25 +02:00
readonly PI : T ;
2018-03-26 23:46:41 +02:00
/** The square root of 1/2, approximately 0.707. */
2018-03-26 16:54:25 +02:00
readonly SQRT1_2 : T ;
2018-03-26 23:46:41 +02:00
/** The square root of 2, approximately 1.414. */
2018-03-26 16:54:25 +02:00
readonly SQRT2 : T ;
2018-03-26 23:46:41 +02:00
/** Returns the absolute value of `x`. */
2018-03-26 16:54:25 +02:00
abs ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the arccosine (in radians) of `x`. */
2018-03-26 16:54:25 +02:00
acos ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the hyperbolic arc-cosine of `x`. */
2018-03-26 16:54:25 +02:00
acosh ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the arcsine (in radians) of `x` */
2018-03-26 16:54:25 +02:00
asin ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the hyperbolic arcsine of `x`. */
2018-03-26 16:54:25 +02:00
asinh ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the arctangent (in radians) of `x`. */
2018-03-26 16:54:25 +02:00
atan ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the arctangent of the quotient of its arguments. */
2018-03-26 16:54:25 +02:00
atan2 ( y : T , x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the hyperbolic arctangent of `x`. */
2018-03-26 16:54:25 +02:00
atanh ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the cube root of `x`. */
2018-03-26 16:54:25 +02:00
cbrt ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the smallest integer greater than or equal to `x`. */
2018-03-26 16:54:25 +02:00
ceil ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the number of leading zero bits in the 32-bit binary representation of `x`. */
2018-03-30 17:25:54 +02:00
clz32 ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the cosine (in radians) of `x`. */
2018-03-26 16:54:25 +02:00
cos ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the hyperbolic cosine of `x`. */
2018-03-26 16:54:25 +02:00
cosh ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns e to the power of `x`. */
2018-03-26 16:54:25 +02:00
exp ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns e to the power of `x`, minus 1. */
2018-03-26 16:54:25 +02:00
expm1 ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the largest integer less than or equal to `x`. */
2018-03-26 16:54:25 +02:00
floor ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the nearest 32-bit single precision float representation of `x`. */
2018-03-26 16:54:25 +02:00
fround ( x : T ) : f32 ;
2018-03-26 23:46:41 +02:00
/** Returns the square root of the sum of squares of its arguments. */
2018-03-26 16:54:25 +02:00
hypot ( value1 : T , value2 : T ) : T ; // TODO: rest
2018-03-26 23:46:41 +02:00
/** Returns the result of the C-like 32-bit multiplication of `a` and `b`. */
2018-03-30 17:25:54 +02:00
imul ( a : T , b : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the natural logarithm (base e) of `x`. */
2018-03-26 16:54:25 +02:00
log ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the base 10 logarithm of `x`. */
2018-03-26 16:54:25 +02:00
log10 ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the natural logarithm (base e) of 1 + `x`. */
2018-03-26 16:54:25 +02:00
log1p ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the base 2 logarithm of `x`. */
2018-03-26 16:54:25 +02:00
log2 ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the largest-valued number of its arguments. */
2018-03-26 16:54:25 +02:00
max ( value1 : T , value2 : T ) : T ; // TODO: rest
2018-03-26 23:46:41 +02:00
/** Returns the lowest-valued number of its arguments. */
2018-03-26 16:54:25 +02:00
min ( value1 : T , value2 : T ) : T ; // TODO: rest
2018-03-26 23:46:41 +02:00
/** Returns `base` to the power of `exponent`. */
2018-03-26 16:54:25 +02:00
pow ( base : T , exponent : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns a pseudo-random number in the range from 0.0 inclusive up to but not including 1.0. */
2018-03-26 16:54:25 +02:00
random ( ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the value of `x` rounded to the nearest integer. */
2018-03-26 16:54:25 +02:00
round ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the sign of `x`, indicating whether the number is positive, negative or zero. */
2018-03-26 16:54:25 +02:00
sign ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the sine of `x`. */
2018-03-26 16:54:25 +02:00
sin ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the hyperbolic sine of `x`. */
2018-03-26 16:54:25 +02:00
sinh ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the square root of `x`. */
2018-03-26 16:54:25 +02:00
sqrt ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the tangent of `x`. */
2018-03-26 16:54:25 +02:00
tan ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the hyperbolic tangent of `x`. */
2018-03-26 16:54:25 +02:00
tanh ( x : T ) : T ;
2018-03-26 23:46:41 +02:00
/** Returns the integer part of `x` by removing any fractional digits. */
2018-03-26 16:54:25 +02:00
trunc ( x : T ) : T ;
2018-03-24 17:18:15 +01:00
}
2018-03-30 17:25:54 +02:00
interface INativeMath < T > extends IMath < T > {
2018-03-26 23:46:41 +02:00
/** Seeds the random number generator. */
seedRandom ( value : i64 ) : void ;
2018-03-30 17:25:54 +02:00
/** Returns the floating-point remainder of `x / y` (rounded towards zero). */
mod ( x : T , y : T ) : T ;
/** Returns the floating-point remainder of `x / y` (rounded to nearest). */
rem ( x : T , y : T ) : T ;
2018-03-26 23:46:41 +02:00
}
/** Double precision math imported from JavaScript. */
2018-03-26 16:54:25 +02:00
declare const JSMath : IMath < f64 > ;
2018-03-26 23:46:41 +02:00
/** Double precision math implemented natively. */
2018-03-30 17:25:54 +02:00
declare const NativeMath : INativeMath < f64 > ;
2018-03-26 23:46:41 +02:00
/** Single precision math implemented natively. */
2018-03-30 17:25:54 +02:00
declare const NativeMathf : INativeMath < f32 > ;
2018-03-26 23:46:41 +02:00
/** Alias of {@link NativeMath} or {@link JSMath} respectively. Defaults to `NativeMath`. */
2018-03-26 16:54:25 +02:00
declare const Math : IMath < f64 > ;
2018-03-31 18:15:59 +03:00
/** Alias of {@link NativeMathf} or {@link JSMath} respectively. Defaults to `NativeMathf`. */
declare const Mathf : IMath < f32 > ;
2018-03-24 17:18:15 +01:00
2018-01-13 23:38:07 +01:00
// Internal decorators
2017-12-16 17:54:53 +01:00
2018-01-13 23:38:07 +01:00
/** Annotates an element as a program global. */
2018-02-25 23:21:32 +01:00
declare function global ( target : Function , propertyKey : string , descriptor : any ) : void ;
2017-12-21 10:14:53 +01:00
2018-04-24 23:11:11 +02:00
/** Annotates a method as an operator overload for the specified `token`. */
2018-02-25 23:21:32 +01:00
declare function operator ( token : string ) : ( target : any , propertyKey : string , descriptor : any ) = > void ;
2017-12-23 00:48:54 +01:00
2018-01-27 05:35:14 +01:00
/** Annotates a class as being unmanaged with limited capabilities. */
declare function unmanaged ( target : Function ) : any ;
2018-01-13 23:38:07 +01:00
2018-03-23 12:45:29 +01:00
/** Annotates a class as being sealed / non-derivable. */
declare function sealed ( target : Function ) : any ;
2018-04-11 23:35:19 +02:00
/** Annotates a method or function as always inlined. */
declare function inline ( target : any , propertyKey : any , descriptor : any ) : any ;