git ssb

0+

wanderer🌟 / js-primea-wasm-container



Commit 609307921c4c0a7292513248cc13f16b199ec5f0

added i64 test

wanderer committed on 3/30/2018, 6:04:23 PM
Parent: 0f31d31650ad897c852214495d044937472b54b9

Files changed

index.jschanged
tests/index.jschanged
tests/wasm/i64.wasmadded
tests/wast/i64.wastadded
tests/wast/private_caller.wasmdeleted
index.jsView
@@ -250,21 +250,25 @@
250250 }
251251 this.instance.exports.setter_globals(...refs)
252252 }
253253
254- // call entrypoint function
255- let wasmFunc
256- if (funcRef.identifier[0]) {
257- wasmFunc = this.instance.exports.table.get(funcRef.identifier[1])
258- } else {
259- wasmFunc = this.instance.exports[funcRef.identifier[1]]
254+ try {
255+ // call entrypoint function
256+ let wasmFunc
257+ if (funcRef.identifier[0]) {
258+ wasmFunc = this.instance.exports.table.get(funcRef.identifier[1])
259+ } else {
260+ wasmFunc = this.instance.exports[funcRef.identifier[1]]
261+ }
262+
263+ const wrapper = generateWrapper(funcRef)
264+ wrapper.exports.table.set(0, wasmFunc)
265+ wrapper.exports.invoke(...args)
266+ await this.onDone()
267+ } catch (e) {
268+ console.log(e)
260269 }
261270
262- const wrapper = generateWrapper(funcRef)
263- wrapper.exports.table.set(0, wasmFunc)
264- wrapper.exports.invoke(...args)
265- await this.onDone()
266-
267271 // store globals
268272 numOfGlobals = this.json.persist.length
269273 if (numOfGlobals) {
270274 const storage = []
tests/index.jsView
@@ -36,47 +36,27 @@
3636 })
3737 }
3838 }
3939
40-tape.skip('bwasic', async t => {
41- // t.plan(1)
40+tape('i64', async t => {
41+ t.plan(1)
4242 tester = t
43-
44- const typeInfo = {
45- 'types': [{
46- 'form': 'func',
47- 'params': [
48- 'i64',
49- 'data'
50- ]
51- }],
52- 'typeMap': [{
53- 'func': 46,
54- 'type': 0
55- }]
56- }
57-
5843 const tree = new RadixTree({db})
44+ let wasm = fs.readFileSync(WASM_PATH + '/i64.wasm')
5945
60- let wasm = fs.readFileSync('./test.wasm')
61- wasm = annotations.encodeAndInject(typeInfo, wasm)
62-
6346 const hypervisor = new Hypervisor(tree)
6447 hypervisor.registerContainer(TestWasmContainer)
6548
6649 const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm)
67- const funcRef = module.getFuncRef('#main')
50+ const funcRef = module.getFuncRef('main')
6851 funcRef.gas = 322000
6952
7053 const message = new Message({
7154 funcRef
7255 }).on('execution:error', e => {
7356 console.log(e)
7457 })
7558 hypervisor.send(message)
76- // const stateRoot = await hypervisor.createStateRoot()
77- // t.deepEquals(stateRoot, expectedState, 'expected root!')
78- t.end()
7959 })
8060
8161 tape('basic', async t => {
8262 t.plan(1)
tests/wasm/i64.wasmView
@@ -1,0 +1,2 @@
1+asm`````~Tfunc internalizetestcheckmoduleselfmoduleexportmemory externalizep$memorytablemaincallback
2+#AAABA A � A callback
tests/wast/i64.wastView
@@ -1,0 +1,26 @@
1+(module
2+ (import "func" "internalize" (func $func.internalize (param i32 i32)))
3+ (import "test" "check" (func $check (param i32 i32)))
4+ (import "module" "self" (func $self (result i32)))
5+ (import "module" "export" (func $exports (param i32 i32) (result i32)))
6+ (import "memory" "externalize" (func $mem.externalize (param i32 i32) (result i32)))
7+ (memory (export "memory") 1)
8+ (data (i32.const 0) "callback")
9+ (table (export "table") 1 1 anyfunc)
10+ (func $main
11+ (call $func.internalize
12+ (i32.const 0)
13+ (call $exports
14+ (call $self)
15+ (call $mem.externalize (i32.const 0) (i32.const 8))
16+ )
17+ )
18+ (call_indirect (param i64) (i64.const 8) (i32.const 0))
19+ )
20+ (func $callback (param i64)
21+ (i32.const 8)
22+ (i32.wrap/i64 (get_local 0))
23+ call $check
24+ )
25+ (export "main" (func $main))
26+ (export "callback" (func $callback)))
tests/wast/private_caller.wasmView
@@ -1,2 +1,0 @@
1-asm```4func internalizefunc externalizetestcheckpmemorytablecall A 
2-AA A  A

Built with git-ssb-web