Skip to content

Commit dc0f271

Browse files
authored
Initial GC integration (AssemblyScript#196)
1 parent 671121b commit dc0f271

File tree

139 files changed

+7300
-4946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+7300
-4946
lines changed

lib/lint/base.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@
9090
"no-unsafe-any": {
9191
"severity": "error"
9292
},
93-
"no-unused-variable": {
94-
"options": [{
95-
"ignore-pattern": "^_"
96-
}]
97-
},
9893
"no-void-expression": {
9994
"severity": "error"
10095
},

lib/loader/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Instances are automatically populated with useful utility:
6565

6666
```js
6767
import "allocator/tlsf";
68-
export { allocate_memory, free_memory };
68+
export { memory };
6969
```
7070

7171
* **getString**(ptr: `number`): `string`<br />
@@ -126,7 +126,7 @@ var str = "Hello world!";
126126
var ptr = module.newString(str);
127127

128128
// Disposing a string that is no longer needed (requires free_memory to be exported)
129-
module.free_memory(ptr);
129+
module.memory.free(ptr);
130130

131131
// Obtaining a string, i.e. as returned by an export
132132
var ptrToString = ...;

lib/loader/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export declare function instantiate<T extends {}>(module: WebAssembly.Module, im
4444
/** Instantiates an AssemblyScript module from a buffer using the specified imports. */
4545
export declare function instantiateBuffer<T extends {}>(buffer: Uint8Array, imports?: ImportsObject): ASUtil & T;
4646

47-
/** Instantiates an AssemblyScript module from a response using the sspecified imports. */
48-
export declare function instantiateStreaming<T extends {}>(response: Response, imports?: ImportsObject): Promise<ASUtil & T>;
47+
/** Instantiates an AssemblyScript module from a response using the specified imports. */
48+
export declare function instantiateStreaming<T extends {}>(result: Promise<Response>, imports?: ImportsObject): Promise<ASUtil & T>;
4949

5050
/** Demangles an AssemblyScript module's exports to a friendly object structure. */
5151
export declare function demangle<T extends {}>(exports: {}): T;

lib/loader/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function instantiate(module, imports) {
4545
/** Allocates a new string in the module's memory and returns its pointer. */
4646
function newString(str) {
4747
var dataLength = str.length;
48-
var ptr = exports.allocate_memory(4 + (dataLength << 1));
48+
var ptr = exports["memory.allocate"](4 + (dataLength << 1));
4949
var dataOffset = (4 + ptr) >>> 1;
5050
checkMem();
5151
U32[ptr >>> 2] = dataLength;

lib/loader/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"main": "index.js",
55
"types": "index.d.ts",
66
"scripts": {
7+
"test:build": "asc tests/assembly/index.ts -b tests/build/untouched.wasm",
78
"test": "node tests"
89
},
910
"files": [

lib/loader/tests/assembly/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import "allocator/arena";
22

3+
export { memory };
4+
35
export const COLOR: string = "red";
46

57
export function strlen(str: string): i32 {
@@ -14,7 +16,7 @@ export namespace math {
1416

1517
export class Car {
1618
static readonly MAX_DOORS: i32 = 5;
17-
static usualDoors: i32 = 3;
19+
static readonly usualDoors: i32 = 3;
1820

1921
numDoors: i32;
2022
private doorsOpen: bool = false;
@@ -42,5 +44,3 @@ export class Car {
4244
memory.free(changetype<usize>(this));
4345
}
4446
}
45-
46-
export { memory };

lib/loader/tests/build/untouched.wasm

3.7 KB
Binary file not shown.

lib/loader/tests/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ assert(typeof proto.getString === "function");
2323

2424
// should export memory
2525
assert(module.memory instanceof WebAssembly.Memory);
26+
assert(typeof module.memory.free === "function");
2627

2728
// should be able to get an exported string
2829
assert.strictEqual(module.getString(module.COLOR), "red");

0 commit comments

Comments
 (0)