2017-12-01 02:18:36 +01:00
// types
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-08 04:03:44 +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-04 22:47:08 +01:00
/** Loads a value of the specified type from memory. */
declare function load < T > ( offset : usize ) : T ;
/** Stores a value of the specified type to memory. */
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 ;
/** Emits an unreachable operation that results in a runtime error when executed. */
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-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. */
declare function changetype < T1 , T2 > ( value : T1 ) : T2 ;
2017-12-01 02:18:36 +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-01 02:18:36 +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-03 23:04:33 +01:00
/** Traps if the specified value is `false`. */
declare function assert ( isTrue : bool ) : void ;
2017-12-01 02:18:36 +01:00
// internal decorators
2017-12-08 04:03:44 +01:00
/** Annotates an element being part of the global namespace. */
2017-12-07 04:37:14 +01:00
declare function global ( ) : any ;
2017-12-08 04:03:44 +01:00
/** Annotates a function being always inlined. */
2017-10-19 18:55:27 +02:00
declare function inline ( ) : any ;
2017-12-08 04:03:44 +01:00
/** Annotates a class using a C-style memory layout. */
declare function struct ( ) : any ;
2017-10-19 18:55:27 +02:00
2017-12-01 02:18:36 +01:00
// standard library
2017-12-07 04:37:14 +01:00
/// <reference path="./std/carray.d.ts" />
/// <reference path="./std/cstring.d.ts" />
2017-12-08 04:03:44 +01:00
/// <reference path="./std/heap.d.ts" />