Commit e729c860b2eaa16901cefd395558a96c683a5cad
added wast2json
wanderer committed on 2/12/2018, 11:49:13 PMParent: 72a22e2c56fb1973e226eac66319ef4ea3909a6f
Files changed
package-lock.json | changed |
package.json | changed |
tests/wasm/caller.wasm | changed |
tests/wasmContainer.js | changed |
tests/wast/caller.wast | changed |
tests/wast/reciever.json | deleted |
tests/wast2wasm.js | added |
wasmContainer.js | changed |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 344090 bytes New file size: 344343 bytes |
package.json | ||
---|---|---|
@@ -43,11 +43,13 @@ | ||
43 | 43 | "devDependencies": { |
44 | 44 | "coveralls": "^3.0.0", |
45 | 45 | "dfinity-radix-tree": "0.0.9", |
46 | 46 | "documentation": "^5.3.5", |
47 | + "js-yaml": "^3.10.0", | |
47 | 48 | "level-browserify": "^1.1.1", |
48 | 49 | "nyc": "^11.4.1", |
49 | 50 | "primea-abstract-container": "0.0.6", |
50 | 51 | "standard": "10.0.3", |
51 | - "tape": "^4.6.3" | |
52 | + "tape": "^4.6.3", | |
53 | + "wabt": "^1.0.0" | |
52 | 54 | } |
53 | 55 | } |
tests/wasm/caller.wasm | ||
---|---|---|
@@ -1,2 +1,4 @@ | ||
1 | - asm `` funcinternalize ptable call | |
2 | - A A | |
1 | + asm | |
2 | +type`` typeMap | |
3 | +` ` funcinternalize ptable call | |
4 | + A A A |
tests/wasmContainer.js | ||
---|---|---|
@@ -14,10 +14,10 @@ | ||
14 | 14 | constructor (actor) { |
15 | 15 | super(actor) |
16 | 16 | this._storage = new Map() |
17 | 17 | } |
18 | - getInteface (funcRef) { | |
19 | - const orginal = super.getInteface(funcRef) | |
18 | + getInterface (funcRef) { | |
19 | + const orginal = super.getInterface(funcRef) | |
20 | 20 | return Object.assign(orginal, { |
21 | 21 | test: { |
22 | 22 | check: (a, b) => { |
23 | 23 | tester.equals(a, b) |
@@ -65,8 +65,36 @@ | ||
65 | 65 | tape('two communicating actors', async t => { |
66 | 66 | t.plan(2) |
67 | 67 | tester = t |
68 | 68 | const expectedState = { |
69 | + '/': Buffer.from('123bcbf52421f0ebf0c9a28d6546a3b374f5d56d', 'hex') | |
70 | + } | |
71 | + | |
72 | + const tree = new RadixTree({db}) | |
73 | + | |
74 | + const recieverWasm = fs.readFileSync('./wasm/reciever.wasm') | |
75 | + const callerWasm = fs.readFileSync('./wasm/caller.wasm') | |
76 | + | |
77 | + const hypervisor = new Hypervisor(tree) | |
78 | + hypervisor.registerContainer(TestWasmContainer) | |
79 | + | |
80 | + const {exports: receiverExports} = await hypervisor.createActor(TestWasmContainer.typeId, recieverWasm) | |
81 | + const {exports: callerExports} = await hypervisor.createActor(TestWasmContainer.typeId, callerWasm) | |
82 | + | |
83 | + const message = new Message({ | |
84 | + funcRef: callerExports.call, | |
85 | + funcArguments: [receiverExports.receive] | |
86 | + }) | |
87 | + | |
88 | + hypervisor.send(message) | |
89 | + const stateRoot = await hypervisor.createStateRoot() | |
90 | + t.deepEquals(stateRoot, expectedState, 'expected root!') | |
91 | +}) | |
92 | + | |
93 | +tape.skip('two communicating actors with callback', async t => { | |
94 | + t.plan(2) | |
95 | + tester = t | |
96 | + const expectedState = { | |
69 | 97 | '/': Buffer.from('f3cc5ba63d6b1737bea2c33bd1942e5488787b82', 'hex') |
70 | 98 | } |
71 | 99 | |
72 | 100 | const tree = new RadixTree({ |
tests/wast/caller.wast | ||
---|---|---|
@@ -1,11 +1,12 @@ | ||
1 | 1 | (module |
2 | - (import "func" "internalize" (func $internalize (param i32 i32) (result i32))) | |
2 | + (import "func" "internalize" (func $internalize (param i32 i32))) | |
3 | 3 | (table (export "table") 1 1 anyfunc) |
4 | 4 | (func $call (param i32) |
5 | 5 | i32.const 5 |
6 | 6 | get_local 0 |
7 | 7 | i32.const 0 |
8 | 8 | call $internalize |
9 | + i32.const 0 | |
9 | 10 | call_indirect (param i32) |
10 | 11 | ) |
11 | 12 | (export "call" (func $call))) |
tests/wast2wasm.js | ||
---|---|---|
@@ -1,0 +1,31 @@ | ||
1 | +const wabt = require('wabt') | |
2 | +const fs = require('fs') | |
3 | +const types = require('../customTypes') | |
4 | + | |
5 | +function filesWast2wasm () { | |
6 | + const srcFiles = fs.readdirSync(`${__dirname}/wast`) | |
7 | + const wastFiles = srcFiles.filter(name => name.split('.').pop() === 'wast') | |
8 | + for (let file of wastFiles) { | |
9 | + const wat = fs.readFileSync(`${__dirname}/wast/${file}`).toString() | |
10 | + file = file.split('.')[0] | |
11 | + let json | |
12 | + try { | |
13 | + json = fs.readFileSync(`${__dirname}/wast/${file}.json`) | |
14 | + json = JSON.parse(json) | |
15 | + } catch (e) { | |
16 | + console.log('no json') | |
17 | + } | |
18 | + | |
19 | + console.log(wat) | |
20 | + const mod = wabt.parseWat('module.wast', wat) | |
21 | + let binary = Buffer.from(mod.toBinary({log: true}).buffer) | |
22 | + if (json) { | |
23 | + console.log(json) | |
24 | + const buf = types.encodeJSON(json) | |
25 | + binary = types.injectCustomSection(buf, binary) | |
26 | + } | |
27 | + fs.writeFileSync(`${__dirname}/wasm/${file}.wasm`, binary) | |
28 | + } | |
29 | +} | |
30 | + | |
31 | +filesWast2wasm() |
wasmContainer.js | ||
---|---|---|
@@ -135,9 +135,9 @@ | ||
135 | 135 | sendMessage () { |
136 | 136 | console.log('send') |
137 | 137 | } |
138 | 138 | |
139 | - getInteface (funcRef) { | |
139 | + getInterface (funcRef) { | |
140 | 140 | const self = this |
141 | 141 | return { |
142 | 142 | func: { |
143 | 143 | externalize: () => {}, |
@@ -220,9 +220,9 @@ | ||
220 | 220 | } |
221 | 221 | |
222 | 222 | async onMessage (message) { |
223 | 223 | const funcRef = message.funcRef |
224 | - const intef = this.getInteface(funcRef) | |
224 | + const intef = this.getInterface(funcRef) | |
225 | 225 | this.instance = WebAssembly.Instance(this.mod, intef) |
226 | 226 | if (this.instance.exports.table) { |
227 | 227 | this._orginalTable = this.instance.exports.table |
228 | 228 | } |
Built with git-ssb-web