mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-14 23:41:30 +00:00
Add initial newArray and getArray helpers to loader
Essentially creates an unmanaged typed array in memory that one can work with and free again respectively obtain from the AS side. No support for GC or generic arrays yet, and is likely to change substentially once WASM GC becomes a thing.
This commit is contained in:
28
lib/loader/index.d.ts
vendored
28
lib/loader/index.d.ts
vendored
@ -10,6 +10,26 @@ interface ImportsObject {
|
||||
}
|
||||
}
|
||||
|
||||
type TypedArray
|
||||
= Int8Array
|
||||
| Uint8Array
|
||||
| Int16Array
|
||||
| Uint16Array
|
||||
| Int32Array
|
||||
| Uint32Array
|
||||
| Float32Array
|
||||
| Float64Array;
|
||||
|
||||
type TypedArrayConstructor
|
||||
= Int8ArrayConstructor
|
||||
| Uint8ArrayConstructor
|
||||
| Int16ArrayConstructor
|
||||
| Uint16ArrayConstructor
|
||||
| Int32ArrayConstructor
|
||||
| Uint32ArrayConstructor
|
||||
| Float32ArrayConstructor
|
||||
| Float32ArrayConstructor;
|
||||
|
||||
/** Utility mixed in by the loader. */
|
||||
interface ASUtil {
|
||||
/** An 8-bit signed integer view on the memory. */
|
||||
@ -36,6 +56,14 @@ interface ASUtil {
|
||||
newString(str: string): number;
|
||||
/** Gets a string from the module's memory by its pointer. */
|
||||
getString(ptr: number): string;
|
||||
/** Copies a typed array into the module's memory and returns its pointer. */
|
||||
newArray(view: TypedArray, length?: number): number;
|
||||
/** Creates a typed array in the module's memory and returns its pointer. */
|
||||
newArray(ctor: TypedArrayConstructor, length: number, unsafe?: boolean): number;
|
||||
/** Gets a view on a typed array in the module's memory by its pointer. */
|
||||
getArray(ctor: TypedArrayConstructor, ptr: number): TypedArray;
|
||||
/** Frees a typed array in the module's memory. Must not be accessed anymore afterwards. */
|
||||
freeArray(ptr: number): void;
|
||||
}
|
||||
|
||||
/** Instantiates an AssemblyScript module using the specified imports. */
|
||||
|
Reference in New Issue
Block a user