Skip to content

Commit

Permalink
refactor: switch to wast
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed May 24, 2018
1 parent 7184bb4 commit acc45fd
Show file tree
Hide file tree
Showing 33 changed files with 101 additions and 23 deletions.
5 changes: 0 additions & 5 deletions lib/WebpackOptionsDefaulter.js
Expand Up @@ -73,11 +73,6 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
{
test: /\.wasm$/i,
type: "webassembly/experimental"
},
{
test: /\.wast$/i,
loader: "@webassemblyjs/wast-loader",
type: "webassembly/experimental"
}
]);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -8,7 +8,6 @@
"@webassemblyjs/ast": "1.4.3",
"@webassemblyjs/wasm-edit": "1.4.3",
"@webassemblyjs/wasm-parser": "1.4.3",
"@webassemblyjs/wast-loader": "^1.5.4",
"acorn": "^5.0.0",
"acorn-dynamic-import": "^3.0.0",
"ajv": "^6.1.0",
Expand Down Expand Up @@ -73,6 +72,7 @@
"url-loader": "^0.6.2",
"val-loader": "^1.0.2",
"vm-browserify": "~0.0.0",
"wast-loader": "^1.5.5",
"webpack-dev-middleware": "^1.9.0",
"worker-loader": "^1.1.1",
"xxhashjs": "^0.2.1"
Expand Down
5 changes: 5 additions & 0 deletions test/TestCases.template.js
Expand Up @@ -141,6 +141,11 @@ const describeCases = config => {
{
test: /\.pug/,
loader: "pug-loader"
},
{
test: /\.wat$/i,
loader: "wast-loader",
type: "webassembly/experimental"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion test/cases/wasm/import-wasm-wasm/index.js
@@ -1,5 +1,5 @@
it("should allow to run a WebAssembly module with imports", function() {
return import("./wasm.wasm").then(function(wasm) {
return import("./wasm.wat").then(function(wasm) {
const result = wasm.addNumber(20);
expect(result).toEqual(42);
});
Expand Down
Binary file removed test/cases/wasm/import-wasm-wasm/wasm.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions test/cases/wasm/import-wasm-wasm/wasm.wat
@@ -0,0 +1,9 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (param i32) (result i32)))
(import "./wasm2.wat" "getNumber" (func $./wasm2.wasm.getNumber (type $t0)))
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
(i32.add
(get_local $p0)
(call $./wasm2.wasm.getNumber))))

Binary file removed test/cases/wasm/import-wasm-wasm/wasm2.wasm
Binary file not shown.
5 changes: 5 additions & 0 deletions test/cases/wasm/import-wasm-wasm/wasm2.wat
@@ -0,0 +1,5 @@
(module
(type $t0 (func (result i32)))
(func $getNumber (export "getNumber") (type $t0) (result i32)
(i32.const 22)))

2 changes: 1 addition & 1 deletion test/cases/wasm/imports-circular/module.js
@@ -1,4 +1,4 @@
import { addNumber } from "./wasm.wasm";
import { addNumber } from "./wasm.wat";

export var result = addNumber(22);

Expand Down
Binary file removed test/cases/wasm/imports-circular/wasm.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions test/cases/wasm/imports-circular/wasm.wat
@@ -0,0 +1,9 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (param i32) (result i32)))
(import "./module" "getNumber" (func $./module.getNumber (type $t0)))
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
(i32.add
(get_local $p0)
(call $./module.getNumber))))

2 changes: 1 addition & 1 deletion test/cases/wasm/imports/index.js
@@ -1,5 +1,5 @@
it("should allow to run a WebAssembly module with imports", function() {
return import("./wasm.wasm?1").then(function(wasm) {
return import("./wasm.wat?1").then(function(wasm) {
const result = wasm.addNumber(3);
expect(result).toEqual(11);
});
Expand Down
Binary file removed test/cases/wasm/imports/wasm.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions test/cases/wasm/imports/wasm.wat
@@ -0,0 +1,9 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (param i32) (result i32)))
(import "./module" "getNumber" (func $./module.getNumber (type $t0)))
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
(i32.add
(get_local $p0)
(call $./module.getNumber))))

Binary file removed test/cases/wasm/memory/mem-access.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions test/cases/wasm/memory/mem-access.wat
@@ -0,0 +1 @@
(module (type $t0 (func (result i32))) (type $t1 (func (param i32))) (import "./memory.wat" "memory" (memory $./memory.wasm.memory 1)) (func $get (export "get") (type $t0) (result i32) (i32.load (i32.const 0))) (func $set (export "set") (type $t1) (param $p i32) (i32.store (i32.const 0) (get_local $p))))
Expand Down
Binary file removed test/cases/wasm/memory/memory.wasm
Binary file not shown.
4 changes: 4 additions & 0 deletions test/cases/wasm/memory/memory.wat
@@ -0,0 +1,4 @@
(module
(memory $memory (export "memory") 1)
(data (i32.const 12) "\00\00\00\00"))

4 changes: 2 additions & 2 deletions test/cases/wasm/memory/run.js
@@ -1,5 +1,5 @@
import * as a1 from "./mem-access.wasm?1";
import * as a2 from "./mem-access.wasm?2";
import * as a1 from "./mem-access.wat?1";
import * as a2 from "./mem-access.wat?2";

a1.set(42);
export const x1 = a1.get();
Expand Down
2 changes: 1 addition & 1 deletion test/cases/wasm/order/a.js
@@ -1,6 +1,6 @@
import { trackA, results } from "./tracker";
import "./b.js";
import "./wasm.wasm";
import "./wasm.wat";

trackA();

Expand Down
Binary file removed test/cases/wasm/order/wasm.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion test/cases/wasm/simple/index.js
Expand Up @@ -6,7 +6,7 @@ it("should allow to run a WebAssembly module (indirect)", function() {
});

it("should allow to run a WebAssembly module (direct)", function() {
return import("./wasm.wasm?2").then(function(wasm) {
return import("./wasm.wat?2").then(function(wasm) {
const result = wasm.add(wasm.getNumber(), 2);
expect(result).toEqual(42);
});
Expand Down
2 changes: 1 addition & 1 deletion test/cases/wasm/simple/module.js
@@ -1,4 +1,4 @@
import { add, getNumber } from "./wasm.wasm?1";
import { add, getNumber } from "./wasm.wat?1";

export function run() {
return add(getNumber(), 2);
Expand Down
Binary file removed test/cases/wasm/simple/wasm.wasm
Binary file not shown.
10 changes: 10 additions & 0 deletions test/cases/wasm/simple/wasm.wat
@@ -0,0 +1,10 @@
(module
(type $t0 (func (param i32 i32) (result i32)))
(type $t1 (func (result i32)))
(func $add (export "add") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
(i32.add
(get_local $p0)
(get_local $p1)))
(func $getNumber (export "getNumber") (type $t1) (result i32)
(i32.const 40)))

6 changes: 3 additions & 3 deletions test/cases/wasm/table/index.js
Expand Up @@ -2,15 +2,15 @@
const UNKNOWN_FUNCTION_TABLE = /invalid index into function table|invalid function/;

it("should support tables", function() {
return import("./wasm-table.wasm").then(function(wasm) {
return import("./wasm-table.wat").then(function(wasm) {
expect(wasm.callByIndex(0)).toEqual(42);
expect(wasm.callByIndex(1)).toEqual(13);
expect(() => wasm.callByIndex(2)).toThrow(UNKNOWN_FUNCTION_TABLE);
});
});

it("should support exported tables", function() {
return import("./wasm-table-export.wasm").then(function(wasm) {
return import("./wasm-table-export.wat").then(function(wasm) {
expect(wasm.table).toBeInstanceOf(WebAssembly.Table);
expect(wasm.table.length).toBe(2);
const e0 = wasm.table.get(0);
Expand All @@ -23,7 +23,7 @@ it("should support exported tables", function() {
});

it("should support imported tables", function() {
return import("./wasm-table-imported.wasm").then(function(wasm) {
return import("./wasm-table-imported.wat").then(function(wasm) {
expect(wasm.callByIndex(0)).toEqual(42);
expect(wasm.callByIndex(1)).toEqual(13);
expect(() => wasm.callByIndex(2)).toThrow(UNKNOWN_FUNCTION_TABLE);
Expand Down
Binary file removed test/cases/wasm/table/wasm-table-export.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions test/cases/wasm/table/wasm-table-export.wat
@@ -0,0 +1,9 @@
(module
(type $t0 (func (result i32)))
(func $f1 (type $t0) (result i32)
(i32.const 42))
(func $f2 (type $t0) (result i32)
(i32.const 13))
(table $table (export "table") 2 anyfunc)
(elem (i32.const 0) $f1 $f2))

Binary file removed test/cases/wasm/table/wasm-table-imported.wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions test/cases/wasm/table/wasm-table-imported.wat
@@ -0,0 +1,8 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (param i32) (result i32)))
(import "./wasm-table-export.wat" "table" (table $./wasm-table-export.wasm.table 2 anyfunc))
(func $callByIndex (export "callByIndex") (type $t1) (param $i i32) (result i32)
(call_indirect (type $t0)
(get_local $i))))

Binary file removed test/cases/wasm/table/wasm-table.wasm
Binary file not shown.
14 changes: 14 additions & 0 deletions test/cases/wasm/table/wasm-table.wat
@@ -0,0 +1,14 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (result i32)))
(type $t2 (func (param i32) (result i32)))
(func $f0 (type $t0) (result i32)
(i32.const 42))
(func $f1 (type $t0) (result i32)
(i32.const 13))
(func $callByIndex (export "callByIndex") (type $t2) (param $p0 i32) (result i32)
(call_indirect (type $t1)
(get_local $p0)))
(table $T0 2 anyfunc)
(elem (i32.const 0) $f0 $f1))

12 changes: 6 additions & 6 deletions yarn.lock
Expand Up @@ -125,12 +125,6 @@
"@webassemblyjs/wasm-parser" "1.4.3"
webassemblyjs "1.4.3"

"@webassemblyjs/wast-loader@^1.5.4":
version "1.5.4"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-loader/-/wast-loader-1.5.4.tgz#6db66671edc5955cb77cbf90a6c4f627f6335a6a"
dependencies:
wabt "^1.0.0"

"@webassemblyjs/wast-parser@1.4.3":
version "1.4.3"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.4.3.tgz#3250402e2c5ed53dbe2233c9de1fe1f9f0d51745"
Expand Down Expand Up @@ -6273,6 +6267,12 @@ walker@~1.0.5:
dependencies:
makeerror "1.0.x"

wast-loader@^1.5.5:
version "1.5.5"
resolved "https://registry.yarnpkg.com/wast-loader/-/wast-loader-1.5.5.tgz#a1d6cdc468b6963a6e479de683dc74755f09b81a"
dependencies:
wabt "^1.0.0"

watch@~0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/watch/-/watch-0.18.0.tgz#28095476c6df7c90c963138990c0a5423eb4b986"
Expand Down

0 comments on commit acc45fd

Please sign in to comment.