git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit e729c860b2eaa16901cefd395558a96c683a5cad

added wast2json

wanderer committed on 2/12/2018, 11:49:13 PM
Parent: 72a22e2c56fb1973e226eac66319ef4ea3909a6f

Files changed

package-lock.jsonchanged
package.jsonchanged
tests/wasm/caller.wasmchanged
tests/wasmContainer.jschanged
tests/wast/caller.wastchanged
tests/wast/reciever.jsondeleted
tests/wast2wasm.jsadded
wasmContainer.jschanged
package-lock.jsonView
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.jsonView
@@ -43,11 +43,13 @@
4343 "devDependencies": {
4444 "coveralls": "^3.0.0",
4545 "dfinity-radix-tree": "0.0.9",
4646 "documentation": "^5.3.5",
47+ "js-yaml": "^3.10.0",
4748 "level-browserify": "^1.1.1",
4849 "nyc": "^11.4.1",
4950 "primea-abstract-container": "0.0.6",
5051 "standard": "10.0.3",
51- "tape": "^4.6.3"
52+ "tape": "^4.6.3",
53+ "wabt": "^1.0.0"
5254 }
5355 }
tests/wasm/caller.wasmView
@@ -1,2 +1,4 @@
1-asm ``func internalizeptablecall
2- A A
1+asm
2+type`` typeMap
3+``func internalizeptablecall
4+A AA
tests/wasmContainer.jsView
@@ -14,10 +14,10 @@
1414 constructor (actor) {
1515 super(actor)
1616 this._storage = new Map()
1717 }
18- getInteface (funcRef) {
19- const orginal = super.getInteface(funcRef)
18+ getInterface (funcRef) {
19+ const orginal = super.getInterface(funcRef)
2020 return Object.assign(orginal, {
2121 test: {
2222 check: (a, b) => {
2323 tester.equals(a, b)
@@ -65,8 +65,36 @@
6565 tape('two communicating actors', async t => {
6666 t.plan(2)
6767 tester = t
6868 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 = {
6997 '/': Buffer.from('f3cc5ba63d6b1737bea2c33bd1942e5488787b82', 'hex')
7098 }
7199
72100 const tree = new RadixTree({
tests/wast/caller.wastView
@@ -1,11 +1,12 @@
11 (module
2- (import "func" "internalize" (func $internalize (param i32 i32) (result i32)))
2+ (import "func" "internalize" (func $internalize (param i32 i32)))
33 (table (export "table") 1 1 anyfunc)
44 (func $call (param i32)
55 i32.const 5
66 get_local 0
77 i32.const 0
88 call $internalize
9+ i32.const 0
910 call_indirect (param i32)
1011 )
1112 (export "call" (func $call)))
tests/wast/reciever.jsonView
@@ -1,4 +1,0 @@
1-{
2- "type": [],
3- "typeMap": []
4-}
tests/wast2wasm.jsView
@@ -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.jsView
@@ -135,9 +135,9 @@
135135 sendMessage () {
136136 console.log('send')
137137 }
138138
139- getInteface (funcRef) {
139+ getInterface (funcRef) {
140140 const self = this
141141 return {
142142 func: {
143143 externalize: () => {},
@@ -220,9 +220,9 @@
220220 }
221221
222222 async onMessage (message) {
223223 const funcRef = message.funcRef
224- const intef = this.getInteface(funcRef)
224+ const intef = this.getInterface(funcRef)
225225 this.instance = WebAssembly.Instance(this.mod, intef)
226226 if (this.instance.exports.table) {
227227 this._orginalTable = this.instance.exports.table
228228 }

Built with git-ssb-web