|
| 1 | +// types |
| 2 | + |
1 | 3 | /** An 8-bit signed integer. */
|
2 | 4 | declare type i8 = number;
|
3 | 5 | /** A 16-bit signed integer. */
|
@@ -25,16 +27,76 @@ declare type f32 = number;
|
25 | 27 | /** A 64-bit float. */
|
26 | 28 | declare type f64 = number;
|
27 | 29 |
|
| 30 | +// builtins |
| 31 | + |
| 32 | +/** 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. */ |
| 33 | +declare function clz<T>(value: T): T; |
| 34 | +/** 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. */ |
| 35 | +declare function ctz<T>(value: T): T; |
| 36 | +/** Performs the sign-agnostic count number of one bits operation on a 32-bit or 64-bit integer. */ |
| 37 | +declare function popcnt<T>(value: T): T; |
| 38 | +/** Performs the sign-agnostic rotate left operation on a 32-bit or 64-bit integer. */ |
| 39 | +declare function rotl<T>(value: T, shift: T): T; |
| 40 | +/** Performs the sign-agnostic rotate right operation on a 32-bit or 64-bit integer. */ |
| 41 | +declare function rotr<T>(value: T, shift: T): T; |
| 42 | + |
| 43 | +/** Computes the absolute value of a 32-bit or 64-bit float. */ |
| 44 | +declare function abs<T>(value: T): T; |
| 45 | +/** Performs the ceiling operation on a 32-bit or 64-bit float. */ |
| 46 | +declare function ceil<T>(value: T): T; |
| 47 | +/** Composes a 32-bit or 64-bit float from the magnitude of `x` and the sign of `y`. */ |
| 48 | +declare function copysign<T>(x: T, y: T): T; |
| 49 | +/** Performs the floor operation on a 32-bit or 64-bit float. */ |
| 50 | +declare function floor<T>(value: T): T; |
| 51 | +/** Determines the maximum of two 32-bit or 64-bit floats. If either operand is `NaN`, returns `NaN`. */ |
| 52 | +declare function max<T>(left: T, right: T): T; |
| 53 | +/** Determines the minimum of two 32-bit or 64-bit floats. If either operand is `NaN`, returns `NaN`. */ |
| 54 | +declare function min<T>(left: T, right: T): T; |
| 55 | +/** Rounds to the nearest integer tied to even of a 32-bit or 64-bit float. */ |
| 56 | +declare function nearest<T>(value: T): T; |
| 57 | +/** Reinterprets the bits of a value of type `T1` as type `T2`. Valid reinterpretations are i32 to/from f32 and i64 to/from f64. */ |
| 58 | +declare function reinterpret<T1,T2>(value: T1): T2; |
| 59 | +/** Calculates the square root of a 32-bit or 64-bit float. */ |
| 60 | +declare function sqrt<T>(value: T): T; |
| 61 | +/** Rounds to the nearest integer towards zero of a 32-bit or 64-bit float. */ |
| 62 | +declare function trunc<T>(value: T): T; |
| 63 | + |
| 64 | +/** Returns the current memory size in units of pages. One page is 64kb. */ |
| 65 | +declare function current_memory(): i32; |
| 66 | +/** 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. */ |
| 67 | +declare function grow_memory(value: i32): i32; |
| 68 | +/** Emits an unreachable operation that results in a runtime error when executed. */ |
| 69 | +declare function unreachable(): void; |
| 70 | + |
| 71 | +/** Loads a value of the specified type from memory. */ |
| 72 | +declare function load<T>(offset: usize): T; |
| 73 | +/** Stores a value of the specified type to memory. */ |
| 74 | +declare function store<T>(offset: usize, value: T): void; |
| 75 | +/** Determines the byte size of the specified core or class type. Compiles to a constant. */ |
| 76 | +declare function sizeof<T>(): usize; |
| 77 | + |
| 78 | +/** NaN (not a number) as a 32-bit or 64-bit float depending on context. */ |
| 79 | +declare const NaN: number; |
| 80 | +/** Positive infinity as a 32-bit or 64-bit float depending on context. */ |
| 81 | +declare const Infinity: number; |
| 82 | + |
| 83 | +/** Tests if a 32-bit or 64-bit float is NaN. */ |
| 84 | +declare function isNaN<T>(value: T): bool; |
| 85 | +/** Tests if a 32-bit or 64-bit float is finite, that is not NaN or +/-Infinity. */ |
| 86 | +declare function isFinite<T>(value: T): bool; |
| 87 | + |
| 88 | +// internal decorators |
| 89 | + |
28 | 90 | /** A decorator marking a function or class as global. */
|
29 | 91 | declare function global(name?: string): any;
|
30 | 92 | /** A decorator marking a function as ideally being inlined. */
|
31 | 93 | declare function inline(): any;
|
32 | 94 | /** A decorator marking a class that manually manages its memory. */
|
33 | 95 | declare function allocates(): any;
|
34 |
| - |
35 | 96 | declare function operator(token: string, fn: any): any;
|
36 | 97 |
|
37 |
| -/// <reference path="./std/builtins.d.ts" /> |
| 98 | +// standard library |
| 99 | + |
38 | 100 | /// <reference path="./std/array.d.ts" />
|
39 | 101 | /// <reference path="./std/map.d.ts" />
|
40 | 102 | /// <reference path="./std/math.d.ts" />
|
|
0 commit comments