Skip to content

Commit 5ca284d

Browse files
committed
Prepare for latest API changes [ci skip]
1 parent 4ad41f6 commit 5ca284d

File tree

10 files changed

+60
-860
lines changed

10 files changed

+60
-860
lines changed

.gitattributes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
bin/* text eol=lf
2-
*.sh text eol=lf
1+
bin/* binary
2+
index.js binary

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
node_modules/
22
npm-debug.*
3-
index.js.mem
4-
shared.bc

API.md

Lines changed: 0 additions & 756 deletions
This file was deleted.

README.md

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var binaryen = require("binaryen");
1818
// Create a module with a single function
1919
var myModule = new binaryen.Module();
2020

21-
myModule.addFunction("add", myModule.addFunctionType("iii", binaryen.i32, [ binaryen.i32, binaryen.i32 ]), [ binaryen.i32 ],
21+
myModule.addFunction("add", binaryen.createType([ binaryen.i32, binaryen.i32 ]), binaryen.i32, [ binaryen.i32 ],
2222
myModule.block(null, [
2323
myModule.setLocal(2,
2424
myModule.i32.add(
@@ -71,7 +71,6 @@ or you can use one of the [previous versions](https://github.com/AssemblyScript/
7171

7272
API
7373
---
74-
<!-- START API.md -->
7574

7675
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
7776
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -132,6 +131,12 @@ API
132131
* **auto**: `Type`<br />
133132
Special type used in **Module#block** exclusively. Lets the API figure out a block's result type automatically.
134133

134+
* **createType**(types: `Type[]`): `Type`<br />
135+
Creates a multi-value type from an array of types.
136+
137+
* **expandType**(type: `Type`): `Type[]`<br />
138+
Expands a multi-value type to an array of types.
139+
135140
### Module construction
136141

137142
* new **Module**(): `Module`<br />
@@ -145,25 +150,16 @@ API
145150

146151
### Module manipulation
147152

148-
* Module#**addFunctionType**(name: `string`, resultType: `Type`, paramTypes: `Type[]`): `Signature`<br />
149-
Adds a new function type.
150-
151-
* Module#**getFunctionTypeBySignature**(resultType: `Type`, paramTypes: `Type[]`): `Signature`<br />
152-
Gets an existing function type by its parametric signature. Returns `0` if there is no such function type.
153-
154-
* Module#**removeFunctionType**(name: `string`): `void`<br />
155-
Removes a function type.
156-
157-
* Module#**addFunction**(name: `string`, functionType: `Signature`, varTypes: `Type[]`, body: `Expression`): `Function`<br />
158-
Adds a function. `varTypes` indicate additional locals, in the given order.
153+
* Module#**addFunction**(name: `string`, params: `Type`, results: `Type`, vars: `Type[]`, body: `Expression`): `Function`<br />
154+
Adds a function. `vars` indicate additional locals, in the given order.
159155

160156
* Module#**getFunction**(name: `string`): `Function`<br />
161157
Gets a function, by name,
162158

163159
* Module#**removeFunction**(name: `string`): `void`<br />
164160
Removes a function, by name.
165161

166-
* Module#**addFunctionImport**(internalName: `string`, externalModuleName: `string`, externalBaseName: `string`, functionType: `Signature`): `Import`<br />
162+
* Module#**addFunctionImport**(internalName: `string`, externalModuleName: `string`, externalBaseName: `string`, params: `Type`, results: `Type`): `Import`<br />
167163
Adds a function import.
168164

169165
* Module#**addTableImport**(internalName: `string`, externalModuleName: `string`, externalBaseName: `string`): `Import`<br />
@@ -211,22 +207,14 @@ API
211207
* Module#**autoDrop**(): `void`<br />
212208
Enables automatic insertion of `drop` operations where needed. Lets you not worry about dropping when creating your code.
213209

214-
* **getFunctionTypeInfo**(ftype: `FunctionType`: `FunctionTypeInfo`<br />
215-
Obtains information about a function type.
216-
217-
* FunctionTypeInfo#**name**: `string | null`
218-
* FunctionTypeInfo#**params**: `Type[]`
219-
* FunctionTypeInfo#**result**: `Type`
220-
221210
* **getFunctionInfo**(ftype: `Function`: `FunctionInfo`<br />
222211
Obtains information about a function.
223212

224213
* FunctionInfo#**name**: `string`
225214
* FunctionInfo#**module**: `string | null` (if imported)
226215
* FunctionInfo#**base**: `string | null` (if imported)
227-
* FunctionInfo#**type**: `FunctionType`
228-
* FunctionInfo#**params**: `Type[]`
229-
* FunctionInfo#**result**: `Type`
216+
* FunctionInfo#**params**: `Type`
217+
* FunctionInfo#**results**: `Type`
230218
* FunctionInfo#**vars**: `Type`
231219
* FunctionInfo#**body**: `Expression`
232220

@@ -513,12 +501,18 @@ API
513501

514502
#### [Function calls](http://webassembly.org/docs/semantics/#calls)
515503

516-
* Module#**call**(name: `string`, operands: `Expression[]`, returnType: `Type`): `Expression`<br />
517-
Creates a call to a function. Note that we must specify the return type here as we may not have created the function being called yet.
504+
* Module#**call**(name: `string`, operands: `Expression[]`, params: `Type`, results: `Type`): `Expression`<br />
505+
Creates a call to a function. Note that we must specify the parameter and result type here.
506+
507+
* Module#**return_call**(name: `string`, operands: `Expression[]`, params: `Type`, results: `Type`): `Expression`<br />
508+
Like **call**, but creates a tail-call. 🦄
518509

519-
* Module#**call_indirect/callIndirect**(target: `Expression`, operands: `Expression[]`, returnType: `Type`): `Expression`<br />
510+
* Module#**call_indirect**(target: `Expression`, operands: `Expression[]`, params: `Type`, results: `Type`): `Expression`<br />
520511
Similar to **call**, but calls indirectly, i.e., via a function pointer, so an expression replaces the name as the called value.
521512

513+
* Module#**return_call_indirect**(target: `Expression`, operands: `Expression[]`, params: `Type`, results: `Type`): `Expression`<br />
514+
Like **call_indirect**, but creates a tail-call. 🦄
515+
522516
#### [Linear memory accesses](http://webassembly.org/docs/semantics/#linear-memory-accesses)
523517

524518
* Module#i32.**load**(offset: `number`, align: `number`, ptr: `Expression`): `Expression`<br />
@@ -818,5 +812,3 @@ API
818812

819813
* Module#**interpret**(): `void`<br />
820814
Runs the module in the interpreter, calling the start function.
821-
822-
<!-- END API.md -->

index.d.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ declare module binaryen {
88
const f32: Type;
99
const f64: Type;
1010
const v128: Type;
11-
const except_ref: Type;
11+
const anyref: Type;
12+
const exnref: Type;
1213
const unreachable: Type;
1314
const auto: Type;
1415

16+
function createType(types: Type[]): Type;
17+
function expandType(type: Type): Type[];
18+
1519
type ExpressionId = number;
1620

1721
const InvalidId: ExpressionId;
@@ -353,7 +357,6 @@ declare module binaryen {
353357
const ConvertUVecI64x2ToVecF64x2: Op;
354358

355359
type ExpressionRef = number;
356-
type FunctionTypeRef = number;
357360
type FunctionRef = number;
358361
type GlobalRef = number;
359362
type ImportRef = number;
@@ -373,8 +376,10 @@ declare module binaryen {
373376
loop(label: string, body: ExpressionRef): ExpressionRef;
374377
br(label: string, condition?: ExpressionRef, value?: ExpressionRef): ExpressionRef;
375378
br_if(label: string, condition?: ExpressionRef, value?: ExpressionRef): ExpressionRef;
376-
call(name: string, operands: ExpressionRef[], type: Type): ExpressionRef;
377-
call_indirect(target: ExpressionRef, operands: ExpressionRef[], type: Type): ExpressionRef;
379+
call(name: string, operands: ExpressionRef[], params: Type, results: Type): ExpressionRef;
380+
return_call(name: string, operands: ExpressionRef[], params: Type, results: Type): ExpressionRef;
381+
call_indirect(target: ExpressionRef, operands: ExpressionRef[], params: Type, results: Type): ExpressionRef;
382+
return_call_indirect(target: ExpressionRef, operands: ExpressionRef[], params: Type, results: Type): ExpressionRef;
378383
local: {
379384
get(index: number, type: Type): ExpressionRef;
380385
set(index: number, value: ExpressionRef): ExpressionRef;
@@ -838,16 +843,13 @@ declare module binaryen {
838843
unreachable(): ExpressionRef;
839844
notify(ptr: ExpressionRef, wakeCount: ExpressionRef): ExpressionRef;
840845

841-
addFunctionType(name: string, resultType: Type, paramTypes: Type[]): FunctionTypeRef;
842-
getFunctionTypeBySignature(resultType: Type, paramTypes: Type[]): FunctionTypeRef;
843-
removeFunctionType(name: string): void;
844-
addFunction(name: string, functionType: FunctionTypeRef, varTypes: Type[], body: ExpressionRef): FunctionRef;
846+
addFunction(name: string, params: Type, results: Type, vars: Type[], body: ExpressionRef): FunctionRef;
845847
getFunction(name: string): FunctionRef;
846848
removeFunction(name: string): void;
847849
addGlobal(name: string, type: Type, mutable: boolean, init: ExpressionRef): GlobalRef;
848850
getGlobal(name: string): GlobalRef;
849851
removeGlobal(name: string): void;
850-
addFunctionImport(internalName: string, externalModuleName: string, externalBaseName: string, functionType: FunctionTypeRef): ImportRef;
852+
addFunctionImport(internalName: string, externalModuleName: string, externalBaseName: string, params: Type, results: Type): ImportRef;
851853
addTableImport(internalName: string, externalModuleName: string, externalBaseName: string): ImportRef;
852854
addMemoryImport(internalName: string, externalModuleName: string, externalBaseName: string): ImportRef;
853855
addGlobalImport(internalName: string, externalModuleName: string, externalBaseName: string, globalType: Type): ImportRef;
@@ -1089,23 +1091,14 @@ declare module binaryen {
10891091
size: ExpressionRef;
10901092
}
10911093

1092-
function getFunctionTypeInfo(ftype: FunctionTypeRef): FunctionTypeInfo;
1093-
1094-
interface FunctionTypeInfo {
1095-
name: string;
1096-
params: Type[];
1097-
result: Type;
1098-
}
1099-
11001094
function getFunctionInfo(func: FunctionRef): FunctionInfo;
11011095

11021096
interface FunctionInfo {
11031097
name: string;
11041098
module: string | null;
11051099
base: string | null;
1106-
type: FunctionTypeRef;
1107-
params: Type[];
1108-
result: Type;
1100+
params: Type;
1101+
results: Type;
11091102
vars: Type[];
11101103
body: ExpressionRef;
11111104
}

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"wasm-opt": "bin/wasm-opt"
1818
},
1919
"scripts": {
20-
"readme": "doctoc API.md --github --title \"### Contents\" && node scripts/api",
20+
"readme": "doctoc README.md --github --title \"### Contents\"",
2121
"check": "tsc index.d.ts --noEmit --strict --noImplicitAny --strictNullChecks --listFiles --diagnostics",
2222
"test": "npm run check && node tests/sanity && node tests/example"
2323
},
@@ -30,11 +30,11 @@
3030
"bin/wasm-opt"
3131
],
3232
"devDependencies": {
33-
"dateformat": "^2.2.0",
33+
"dateformat": "^3.0.3",
3434
"doctoc": "^1.4.0",
35-
"semver": "^5.7.1",
36-
"simple-git": "^1.126.0",
37-
"typescript": "^2.9.2"
35+
"semver": "^6.3.0",
36+
"simple-git": "^1.128.0",
37+
"typescript": "^3.7.3"
3838
},
3939
"dependencies": {}
4040
}

scripts/api.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var binaryen = require("..");
33
// Create a module with a single function
44
var myModule = new binaryen.Module();
55

6-
myModule.addFunction("add", myModule.addFunctionType("iii", binaryen.i32, [ binaryen.i32, binaryen.i32 ]), [ binaryen.i32 ],
6+
myModule.addFunction("add", binaryen.createType([ binaryen.i32, binaryen.i32 ]), binaryen.i32, [ binaryen.i32 ],
77
myModule.block(null, [
88
myModule.local.set(2,
99
myModule.i32.add(

tests/sanity.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ console.log("constructing a module");
1111
var mod = new binaryen.Module();
1212
assert(mod);
1313

14-
console.log("adding a function type");
15-
var ftype = mod.addFunctionType("i", binaryen.i32, []);
16-
assert(ftype);
17-
1814
console.log("creating an expression");
1915
var expr = mod.i32.const(0);
2016
assert(expr);
@@ -24,11 +20,15 @@ var stmt = mod.return(expr);
2420
assert(stmt);
2521

2622
console.log("adding a function");
27-
var func = mod.addFunction("main", ftype, [], stmt);
23+
var func = mod.addFunction("main", binaryen.none, binaryen.i32, [], stmt);
2824
assert(func);
2925

26+
console.log("creating a multi-value type");
27+
var mvtype = binaryen.createType([ binaryen.i32, binaryen.f64 ]);
28+
assert(mvtype);
29+
3030
console.log("adding a function import");
31-
mod.addFunctionImport("func", "env", "func", ftype);
31+
mod.addFunctionImport("func", "env", "func", mvtype, mvtype);
3232

3333
console.log("adding a function export");
3434
mod.addFunctionExport("main", "main");

0 commit comments

Comments
 (0)