Skip to content

Commit 00303fd

Browse files
committed
Keep builtins in assembly.d.ts, not really stdlib
1 parent c0300c1 commit 00303fd

File tree

3 files changed

+67
-61
lines changed

3 files changed

+67
-61
lines changed

assembly.d.ts

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// types
2+
13
/** An 8-bit signed integer. */
24
declare type i8 = number;
35
/** A 16-bit signed integer. */
@@ -25,16 +27,76 @@ declare type f32 = number;
2527
/** A 64-bit float. */
2628
declare type f64 = number;
2729

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+
2890
/** A decorator marking a function or class as global. */
2991
declare function global(name?: string): any;
3092
/** A decorator marking a function as ideally being inlined. */
3193
declare function inline(): any;
3294
/** A decorator marking a class that manually manages its memory. */
3395
declare function allocates(): any;
34-
3596
declare function operator(token: string, fn: any): any;
3697

37-
/// <reference path="./std/builtins.d.ts" />
98+
// standard library
99+
38100
/// <reference path="./std/array.d.ts" />
39101
/// <reference path="./std/map.d.ts" />
40102
/// <reference path="./std/math.d.ts" />

src/compiler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,9 @@ export class Compiler extends DiagnosticEmitter {
13521352
sb.push(type.toString());
13531353
}
13541354
functionInstance = <Function | null>functionPrototype.instances.get(sb.join(","));
1355+
if (!functionInstance) {
1356+
// TODO: sizeof, load, store, see program.ts/initializeBuiltins
1357+
}
13551358
} else {
13561359
functionInstance = (<FunctionPrototype>element).resolveInclTypeArguments(expression.typeArguments, this.currentFunction.contextualTypeArguments, expression); // reports
13571360
}

std/builtins.d.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)