mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-15 07:51:32 +00:00
Builtins rewrite with type parameter inference; Small integer math optimizations; Switchify
This commit is contained in:
6
std/assembly.d.ts
vendored
6
std/assembly.d.ts
vendored
@ -173,14 +173,14 @@ declare const Infinity: f32 | f64;
|
||||
declare const HEAP_BASE: usize;
|
||||
/** Determines the byte size of the specified core or class type. Compiles to a constant. */
|
||||
declare function sizeof<T>(): usize;
|
||||
/** Changes the type of a value to another one. Useful for casting class instances to their pointer values and vice-versa. */
|
||||
/** 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.*/
|
||||
declare function changetype<T>(value: any): T;
|
||||
/** Tests if a 32-bit or 64-bit float is `NaN`. */
|
||||
declare function isNaN<T = f32 | f64>(value: T): bool;
|
||||
/** Tests if a 32-bit or 64-bit float is finite, that is not `NaN` or +/-`Infinity`. */
|
||||
declare function isFinite<T = f32 | f64>(value: T): bool;
|
||||
/** Traps if the specified value evaluates to `false`. */
|
||||
declare function assert(isTrue: bool, message?: string): void;
|
||||
/** Traps if the specified value is not true-ish, otherwise returns the value. */
|
||||
declare function assert<T>(isTrueish: T, message?: string): T & object; // any better way to model `: T != null`?
|
||||
/** 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. */
|
||||
|
13
std/assembly/regexp.ts
Normal file
13
std/assembly/regexp.ts
Normal file
@ -0,0 +1,13 @@
|
||||
@global
|
||||
class RegExp {
|
||||
|
||||
// @binding(CALL_NEW, [ STRING, STRING], OBJECT_HANDLE)
|
||||
constructor(pattern: string, flags: string = "") { throw new Error("unreachable"); }
|
||||
|
||||
// @binding(CALL_THIS, [ STRING ], PASS_THRU)
|
||||
test(search: string): bool { throw new Error("unreachable"); }
|
||||
|
||||
// @binding(CALL_THIS, [], STRING)
|
||||
toString(): string { throw new Error("unreachable"); }
|
||||
|
||||
}
|
@ -196,3 +196,15 @@ function isWhiteSpaceOrLineTerminator(c: u16): bool {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// @global
|
||||
// @binding(CALL, [ STRING, PASS_THRU ], PASS_THRU)
|
||||
export function parseInt(str: string, radix: i32 = 10): f64 {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
// @global
|
||||
// @binding(CALL, [ STRING ], PASS_THRU)
|
||||
export function parseFloat(str: string): f64 {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
6
std/portable.d.ts
vendored
6
std/portable.d.ts
vendored
@ -123,10 +123,10 @@ declare function store<T = u8>(offset: usize, value: T): void;
|
||||
/** Emits an unreachable operation that results in a runtime error when executed. */
|
||||
declare function unreachable(): any; // sic
|
||||
|
||||
/** Changes the type of a value to another one. Useful for casting class instances to their pointer values and vice-versa. */
|
||||
/** 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.*/
|
||||
declare function changetype<T>(value: any): T;
|
||||
/** Traps if the specified value evaluates to `false`. */
|
||||
declare function assert(isTrue: bool, message?: string): void;
|
||||
/** Traps if the specified value is not true-ish, otherwise returns the value. */
|
||||
declare function assert<T>(isTrueish: T, message?: string): T & object; // any better way to model `: T != null`?
|
||||
/** Parses an integer string to a 64-bit float. */
|
||||
declare function parseInt(str: string, radix?: i32): f64;
|
||||
/** Parses a floating point string to a 64-bit float. */
|
||||
|
@ -93,7 +93,7 @@ function AssertionError(message) {
|
||||
AssertionError.prototype = Object.create(Error.prototype);
|
||||
AssertionError.prototype.name = "AssertionError";
|
||||
|
||||
globalScope["assert"] = function assert(isTrue, message) { if (!isTrue) throw new AssertionError(message); };
|
||||
globalScope["assert"] = function assert(isTrueish, message) { if (isTrueish) return isTrueish; throw new AssertionError(message); };
|
||||
globalScope["changetype"] = function changetype(value) { return value; }
|
||||
|
||||
String["fromCharCodes"] = function fromCharCodes(arr) { return String.fromCharCode.apply(String, arr); }
|
||||
|
Reference in New Issue
Block a user