mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-13 15:01:28 +00:00
Initial GC integration (#196)
This commit is contained in:
@ -65,7 +65,7 @@ Instances are automatically populated with useful utility:
|
||||
|
||||
```js
|
||||
import "allocator/tlsf";
|
||||
export { allocate_memory, free_memory };
|
||||
export { memory };
|
||||
```
|
||||
|
||||
* **getString**(ptr: `number`): `string`<br />
|
||||
@ -126,7 +126,7 @@ var str = "Hello world!";
|
||||
var ptr = module.newString(str);
|
||||
|
||||
// Disposing a string that is no longer needed (requires free_memory to be exported)
|
||||
module.free_memory(ptr);
|
||||
module.memory.free(ptr);
|
||||
|
||||
// Obtaining a string, i.e. as returned by an export
|
||||
var ptrToString = ...;
|
||||
|
4
lib/loader/index.d.ts
vendored
4
lib/loader/index.d.ts
vendored
@ -44,8 +44,8 @@ export declare function instantiate<T extends {}>(module: WebAssembly.Module, im
|
||||
/** Instantiates an AssemblyScript module from a buffer using the specified imports. */
|
||||
export declare function instantiateBuffer<T extends {}>(buffer: Uint8Array, imports?: ImportsObject): ASUtil & T;
|
||||
|
||||
/** Instantiates an AssemblyScript module from a response using the sspecified imports. */
|
||||
export declare function instantiateStreaming<T extends {}>(response: Response, imports?: ImportsObject): Promise<ASUtil & T>;
|
||||
/** Instantiates an AssemblyScript module from a response using the specified imports. */
|
||||
export declare function instantiateStreaming<T extends {}>(result: Promise<Response>, imports?: ImportsObject): Promise<ASUtil & T>;
|
||||
|
||||
/** Demangles an AssemblyScript module's exports to a friendly object structure. */
|
||||
export declare function demangle<T extends {}>(exports: {}): T;
|
||||
|
@ -45,7 +45,7 @@ function instantiate(module, imports) {
|
||||
/** Allocates a new string in the module's memory and returns its pointer. */
|
||||
function newString(str) {
|
||||
var dataLength = str.length;
|
||||
var ptr = exports.allocate_memory(4 + (dataLength << 1));
|
||||
var ptr = exports["memory.allocate"](4 + (dataLength << 1));
|
||||
var dataOffset = (4 + ptr) >>> 1;
|
||||
checkMem();
|
||||
U32[ptr >>> 2] = dataLength;
|
||||
|
@ -4,6 +4,7 @@
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"test:build": "asc tests/assembly/index.ts -b tests/build/untouched.wasm",
|
||||
"test": "node tests"
|
||||
},
|
||||
"files": [
|
||||
|
@ -1,5 +1,7 @@
|
||||
import "allocator/arena";
|
||||
|
||||
export { memory };
|
||||
|
||||
export const COLOR: string = "red";
|
||||
|
||||
export function strlen(str: string): i32 {
|
||||
@ -14,7 +16,7 @@ export namespace math {
|
||||
|
||||
export class Car {
|
||||
static readonly MAX_DOORS: i32 = 5;
|
||||
static usualDoors: i32 = 3;
|
||||
static readonly usualDoors: i32 = 3;
|
||||
|
||||
numDoors: i32;
|
||||
private doorsOpen: bool = false;
|
||||
@ -42,5 +44,3 @@ export class Car {
|
||||
memory.free(changetype<usize>(this));
|
||||
}
|
||||
}
|
||||
|
||||
export { memory };
|
||||
|
Binary file not shown.
@ -23,6 +23,7 @@ assert(typeof proto.getString === "function");
|
||||
|
||||
// should export memory
|
||||
assert(module.memory instanceof WebAssembly.Memory);
|
||||
assert(typeof module.memory.free === "function");
|
||||
|
||||
// should be able to get an exported string
|
||||
assert.strictEqual(module.getString(module.COLOR), "red");
|
||||
|
Reference in New Issue
Block a user