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:
dcodeIO
2018-09-18 15:17:44 +02:00
parent 16d1a833dd
commit 9c770d801e
11 changed files with 132 additions and 9 deletions

28
lib/loader/index.d.ts vendored
View File

@ -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. */