2017-12-08 19:08:03 +01:00
// Definitions for the "AssemblyScript" subset.
// 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. */
declare type bool = any ; // sic
/** 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 {
export const MIN_VALUE : i8 ;
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 {
export const MIN_VALUE : i16 ;
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 {
export const MIN_VALUE : i32 ;
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 {
export const MIN_VALUE : i64 ;
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 {
export const MIN_VALUE : isize ;
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 {
export const MIN_VALUE : u8 ;
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 {
export const MIN_VALUE : u16 ;
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 {
export const MIN_VALUE : u32 ;
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 {
export const MIN_VALUE : u64 ;
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 {
export const MIN_VALUE : usize ;
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 {
export const MIN_VALUE : bool ;
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 {
export const MIN_SAFE_INTEGER : f32 ;
export const MAX_SAFE_INTEGER : f32 ;
}
/** 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 {
export const MIN_SAFE_INTEGER : f64 ;
export const MAX_SAFE_INTEGER : f64 ;
}
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 ;
2017-12-01 02:18:36 +01:00
/** Reinterprets the bits of a value of type `T1` as type `T2`. Valid reinterpretations are i32 to/from f32 and i64 to/from f64. */
2017-12-04 02:00:48 +01:00
declare function reinterpret < T1 = i32 | i64 | f32 | f64 , T2 = i32 | i64 | f32 | f64 > ( value : T1 ) : T2 ;
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. */
2017-12-04 22:47:08 +01:00
declare function load < T > ( offset : 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. */
2017-12-04 22:47:08 +01:00
declare function store < T > ( offset : usize , value : T ) : 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 ;
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
/** 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 ;
2017-12-04 22:47:08 +01:00
/** Determines the byte size of the specified core or class type. Compiles to a constant. */
declare function sizeof < T > ( ) : usize ;
2017-12-08 04:03:44 +01:00
/** Changes the type of a value to another one. Useful for casting class instances to their pointer values and vice-versa. */
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 ;
2017-12-08 19:08:03 +01:00
/** Traps if the specified value evaluates to `false`. */
2017-12-14 11:55:35 +01:00
declare function assert ( isTrue : bool , message? : string ) : void ;
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 ;
/** Parses a string to a 64-bit float. */
declare function parseFloat ( str : string ) : f64 ;
2017-12-01 02:18:36 +01:00
2017-12-16 17:54:53 +01:00
// Standard library (not yet implemented)
2017-12-01 02:18:36 +01:00
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-10-19 18:55:27 +02:00
2017-12-16 17:54:53 +01:00
/** Current maximum capacity of the array. */
readonly capacity : i32 ;
2017-12-01 02:18:36 +01:00
2017-12-16 17:54:53 +01:00
/** Current length of the array. */
length : i32 ;
2017-12-12 09:32:03 +01:00
2017-12-16 17:54:53 +01:00
/** Constructs a new array. */
constructor ( capacity? : i32 ) ;
}
/** 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 ;
startsWith ( other : string ) : bool ;
substr ( start : u32 , length? : u32 ) : string ;
substring ( start : u32 , end? : u32 ) : string ;
trim ( ) : string ;
trimLeft ( ) : string ;
trimRight ( ) : 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 { }
/** A static class representing the heap. */
declare class Heap {
/** Gets the amount of used heap space, in bytes. */
static readonly used : usize ;
/** Gets the amount of free heap space, in bytes. */
static readonly free : usize ;
/** Gets the size of the heap, in bytes. */
static readonly size : usize ;
/** Allocates a chunk of memory and returns a pointer to it. */
static allocate ( size : usize ) : usize ;
/** Disposes a chunk of memory by its pointer. */
static dispose ( ptr : usize ) : void ;
/** Copies a chunk of memory from one location to another. */
static copy ( dest : usize , src : usize , n : usize ) : usize ;
2017-12-21 10:14:53 +01:00
/** Fills a chunk of memory with the specified byte value. */
static fill ( dest : usize , c : u8 , n : usize ) : usize ;
/** Compares two chunks of memory. Returns `0` if equal, otherwise the difference of the first differing bytes. */
static compare ( vl : usize , vr : usize , n : usize ) : i32 ;
2017-12-16 17:54:53 +01:00
private constructor ( ) ;
}
interface Boolean { }
interface Function { }
interface IArguments { }
interface Number { }
interface Object { }
interface RegExp { }
// Internal decorators (not yet implemented)
/** Annotates an element being part of the global namespace. */
declare function global ( ) : any ;
2017-12-21 10:14:53 +01:00
/** Annotates a method being an operator overload. */
declare function operator ( token : string ) : any ;
2017-12-23 00:48:54 +01:00
declare function struct ( ) : any ;
declare function size ( size : usize ) : any ;