Update support for the module linking proposal
This commit updates the various tooling used by wasmtime which has new updates to the module linking proposal. This is done primarily to sync with WebAssembly/module-linking#26. The main change implemented here is that wasmtime now supports creating instances from a set of values, nott just from instantiating a module. Additionally subtyping handling of modules with respect to imports is now properly handled by desugaring two-level imports to imports of instances. A number of small refactorings are included here as well, but most of them are in accordance with the changes to `wasmparser` and the updated binary format for module linking.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
(instance $a (instantiate $m))
|
||||
|
||||
(func (export "get") (result i32)
|
||||
call $a.$foo)
|
||||
call (func $a "foo"))
|
||||
)
|
||||
(assert_return (invoke "get") (i32.const 1))
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
(instance $a (instantiate $m))
|
||||
|
||||
(func (export "get") (result i32)
|
||||
global.get $a.$g)
|
||||
global.get (global $a "g"))
|
||||
)
|
||||
(assert_return (invoke "get") (i32.const 2))
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
(data (i32.const 0) "\03\00\00\00")
|
||||
)
|
||||
(instance $a (instantiate $m))
|
||||
(alias (instance $a) (memory $m))
|
||||
(alias $m (memory $a "m"))
|
||||
|
||||
(func (export "get") (result i32)
|
||||
i32.const 0
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
(func (export "get") (result i32)
|
||||
i32.const 0
|
||||
call_indirect $a.$t (result i32))
|
||||
call_indirect (table $a "t") (result i32))
|
||||
)
|
||||
(assert_return (invoke "get") (i32.const 4))
|
||||
|
||||
@@ -62,11 +62,10 @@
|
||||
i32.const 5))
|
||||
)
|
||||
(instance $a (instantiate $m))
|
||||
(instance $b (instantiate $a.$sub))
|
||||
(alias $b.$f (instance $b) (func 0))
|
||||
(instance $b (instantiate (module $a "module")))
|
||||
|
||||
(func (export "get") (result i32)
|
||||
call $b.$f)
|
||||
call (func $b ""))
|
||||
)
|
||||
(assert_return (invoke "get") (i32.const 5))
|
||||
|
||||
@@ -79,11 +78,9 @@
|
||||
(instance $i (export "") (instantiate $sub))
|
||||
)
|
||||
(instance $a (instantiate $m))
|
||||
(alias $a.$i (instance $a) (instance 0))
|
||||
(alias $a.$i.$f (instance $a.$i) (func 0))
|
||||
|
||||
(func (export "get") (result i32)
|
||||
call $a.$i.$f)
|
||||
call (func $a "" ""))
|
||||
)
|
||||
(assert_return (invoke "get") (i32.const 6))
|
||||
|
||||
@@ -91,48 +88,51 @@
|
||||
(module
|
||||
(type $t (func))
|
||||
(module $m
|
||||
(func $f (type $t))
|
||||
(func $f (type outer 0 $t))
|
||||
)
|
||||
(instance $a (instantiate $m))
|
||||
)
|
||||
|
||||
;; alias parent -- module
|
||||
(; TODO
|
||||
(module
|
||||
(module $a)
|
||||
(module $m
|
||||
(instance (instantiate $a))
|
||||
(instance (instantiate (module outer 0 $a)))
|
||||
)
|
||||
(instance (instantiate $m))
|
||||
)
|
||||
;)
|
||||
|
||||
;; The alias, import, type, module, and instance sections can all be interleaved
|
||||
(module
|
||||
(module $ROOT
|
||||
(module $a)
|
||||
(type $t (func))
|
||||
(module $m
|
||||
;; alias
|
||||
(alias $thunk parent (type $t))
|
||||
(alias $thunk (type outer 0 $t))
|
||||
;; import
|
||||
(import "" "" (func (type $thunk)))
|
||||
;; module (referencing parent type)
|
||||
(module
|
||||
(func (type $thunk))
|
||||
(func (type outer $m $thunk))
|
||||
(func (type outer $ROOT $t))
|
||||
)
|
||||
;; type
|
||||
(type $thunk2 (func))
|
||||
;; module (referencing previous alias)
|
||||
(module $m2
|
||||
(func (export "") (type $thunk2))
|
||||
(func (export "") (type outer $m $thunk2))
|
||||
)
|
||||
;; instance
|
||||
(instance $i (instantiate $m2))
|
||||
;; alias that instance
|
||||
(alias $my_f (instance $i) (func 0))
|
||||
(alias $my_f (func $i ""))
|
||||
;; module
|
||||
(module $m3
|
||||
(import "" (func)))
|
||||
;; use our aliased function to create the module
|
||||
(instance $i2 (instantiate $m3 (func $my_f)))
|
||||
(instance $i2 (instantiate $m3 "" (func $my_f)))
|
||||
;; module
|
||||
(module $m4
|
||||
(import "" (func)))
|
||||
@@ -141,5 +141,5 @@
|
||||
;; instantiate the above module
|
||||
(module $smol (func $f (export "")))
|
||||
(instance $smol (instantiate $smol))
|
||||
(instance (instantiate $m (func $smol.$f)))
|
||||
(instance (instantiate $m "" (instance $smol)))
|
||||
)
|
||||
|
||||
@@ -9,22 +9,36 @@
|
||||
|
||||
(module
|
||||
(import "a" "m" (module))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "" (func))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "a" (func))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "b" (global i32))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module
|
||||
(export "" (func))
|
||||
(export "a" (func))
|
||||
))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module
|
||||
(export "a" (func))
|
||||
(export "" (func))
|
||||
))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module
|
||||
(export "a" (func))
|
||||
(export "" (func))
|
||||
(export "b" (global i32))
|
||||
))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module
|
||||
(export "b" (global i32))
|
||||
(export "a" (func))
|
||||
@@ -37,64 +51,60 @@
|
||||
(module (export "m")
|
||||
(func (export ""))))
|
||||
|
||||
(module
|
||||
(import "a" "m" (module))
|
||||
(import "a" "m" (module (export "" (func))))
|
||||
)
|
||||
(module (import "a" "m" (module)))
|
||||
(module (import "a" "m" (module (export "" (func)))))
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (func (param i32))))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (func (result i32))))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (global i32)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (table 1 funcref)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (memory 1)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (module)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (instance)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
|
||||
(module $a
|
||||
(module (export "m")
|
||||
(global (export "") i32 (i32.const 0))))
|
||||
|
||||
;; globals
|
||||
(module
|
||||
(import "a" "m" (module))
|
||||
(import "a" "m" (module (export "" (global i32))))
|
||||
)
|
||||
(module (import "a" "m" (module)))
|
||||
(module (import "a" "m" (module (export "" (global i32)))))
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(import "a" "m" (module (export "" (global (mut i32)))))
|
||||
)
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (global f32)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (func)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (table 1 funcref)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (memory 1)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (module)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (instance)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
|
||||
;; tables
|
||||
(module $a
|
||||
@@ -105,40 +115,52 @@
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "" (table 1 funcref))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "" (table 0 funcref))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "max" (table 1 10 funcref))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "max" (table 0 10 funcref))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "max" (table 0 11 funcref))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "max" (table 0 funcref))))
|
||||
)
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (global f32)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (func)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (table 2 funcref)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (table 1 10 funcref)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "max" (table 2 10 funcref)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "max" (table 1 9 funcref)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (memory 1)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (module)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (instance)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
|
||||
;; memories
|
||||
(module $a
|
||||
@@ -149,40 +171,52 @@
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "" (memory 1))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "" (memory 0))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "max" (memory 1 10))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "max" (memory 0 10))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "max" (memory 0 11))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "max" (memory 0))))
|
||||
)
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (global f32)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (func)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (table 1 funcref)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (memory 2)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (memory 1 10)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "max" (memory 2 10)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "max" (memory 2)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (module)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (instance)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
|
||||
;; modules
|
||||
(module $a
|
||||
@@ -206,72 +240,102 @@
|
||||
)
|
||||
;; import a mixture
|
||||
(module (export "e")
|
||||
(import "" (func))
|
||||
(import "" (func))
|
||||
(import "" (global i32))
|
||||
(import "a" (func))
|
||||
(import "b" (func))
|
||||
(import "c" (global i32))
|
||||
)
|
||||
)
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "a" (module))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "b" (module))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "b" (module (export "" (func))))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "c" (module))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "c" (module
|
||||
(export "a" (func))
|
||||
))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "c" (module
|
||||
(export "a" (func))
|
||||
(export "b" (func (result i32)))
|
||||
))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "c" (module
|
||||
(export "c" (global i32))
|
||||
))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "c" (module
|
||||
(export "c" (global i32))
|
||||
(export "a" (func))
|
||||
))))
|
||||
|
||||
;; for now import strings aren't matched at all, imports must simply pairwise
|
||||
;; line up
|
||||
(import "a" "m" (module (export "d" (module (import "" (func))))))
|
||||
(import "a" "m" (module (export "d" (module (import "x" (func))))))
|
||||
(import "a" "m" (module (export "d" (module (import "x" "y" (func))))))
|
||||
|
||||
(import "a" "m" (module (export "e" (module
|
||||
(import "x" "y" (func))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "d" (module
|
||||
(import "" (func))
|
||||
(import "a" (func))
|
||||
(import "z" (global i32))
|
||||
))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "d" (module (import "" (func))))))
|
||||
)
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(import "a" "m" (module (export "d" (module (import "x" (func))))))
|
||||
)
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(import "a" "m" (module (export "d" (module (import "x" "y" (func))))))
|
||||
)
|
||||
"incompatible import type for `a`")
|
||||
(module
|
||||
(import "a" "m" (module (export "e" (module
|
||||
(import "a" (func))
|
||||
(import "b" (func))
|
||||
(import "c" (global i32))
|
||||
))))
|
||||
)
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (module (export "a" (func)))))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "d" (module)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "d" (module (import "" (module)))))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (global f32)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (func)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (table 1 funcref)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (memory 2)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (module (export "foo" (func)))))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (instance)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
|
||||
;; instances
|
||||
(module $a
|
||||
@@ -303,46 +367,65 @@
|
||||
)
|
||||
(module
|
||||
(import "a" "a" (instance))
|
||||
)
|
||||
(module
|
||||
(import "a" "b" (instance))
|
||||
)
|
||||
(module
|
||||
(import "a" "b" (instance (export "" (func))))
|
||||
)
|
||||
(module
|
||||
(import "a" "c" (instance))
|
||||
)
|
||||
(module
|
||||
(import "a" "c" (instance (export "a" (func))))
|
||||
)
|
||||
(module
|
||||
(import "a" "c" (instance (export "b" (func (result i32)))))
|
||||
)
|
||||
(module
|
||||
(import "a" "c" (instance (export "c" (global i32))))
|
||||
)
|
||||
(module
|
||||
(import "a" "c" (instance
|
||||
(export "a" (func))
|
||||
(export "b" (func (result i32)))
|
||||
(export "c" (global i32))
|
||||
))
|
||||
)
|
||||
(module
|
||||
(import "a" "c" (instance
|
||||
(export "c" (global i32))
|
||||
(export "a" (func))
|
||||
))
|
||||
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "i" (instance))))
|
||||
)
|
||||
(module
|
||||
(import "a" "m" (module (export "i" (instance (export "" (func))))))
|
||||
)
|
||||
(assert_unlinkable
|
||||
(module (import "a" "a" (instance (export "" (global f32)))))
|
||||
"instance types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "i" (instance (export "x" (func)))))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (func)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (table 1 funcref)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (memory 2)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (memory 1 10)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "max" (memory 2 10)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
(assert_unlinkable
|
||||
(module (import "a" "m" (module (export "" (module)))))
|
||||
"module types incompatible")
|
||||
"incompatible import type for `a`")
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
(module
|
||||
(import "" (func))
|
||||
(start 0))
|
||||
(instance $a (instantiate 0 (func $set)))
|
||||
(instance $a (instantiate 0 "" (func $set)))
|
||||
)
|
||||
|
||||
(assert_return (invoke $a "get") (i32.const 1))
|
||||
@@ -49,7 +49,7 @@
|
||||
global.set 0)
|
||||
(start 0))
|
||||
|
||||
(instance $a (instantiate 0 (global $g)))
|
||||
(instance $a (instantiate 0 "" (global $g)))
|
||||
)
|
||||
(assert_return (invoke $a "get") (i32.const 2))
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
call_indirect)
|
||||
(start 0))
|
||||
|
||||
(instance $a (instantiate 0 (table $t)))
|
||||
(instance $a (instantiate 0 "" (table $t)))
|
||||
)
|
||||
(assert_return (invoke $a "get") (i32.const 3))
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
i32.store)
|
||||
(start 0))
|
||||
|
||||
(instance $a (instantiate 0 (memory $m)))
|
||||
(instance $a (instantiate 0 "" (memory $m)))
|
||||
)
|
||||
(assert_return (invoke $a "load") (i32.const 100))
|
||||
|
||||
@@ -88,13 +88,13 @@
|
||||
|
||||
(module $m1
|
||||
(import "" (instance (export "" (func))))
|
||||
(alias (instance 0) (func 0))
|
||||
(alias (func 0 ""))
|
||||
(start 0))
|
||||
|
||||
(module $m2
|
||||
(func (export "") (import "")))
|
||||
(instance $i (instantiate $m2 (func $set)))
|
||||
(instance (instantiate $m1 (instance $i)))
|
||||
(instance $i (instantiate $m2 "" (func $set)))
|
||||
(instance (instantiate $m1 "" (instance $i)))
|
||||
)
|
||||
(assert_return (invoke $a "get") (i32.const 4))
|
||||
|
||||
@@ -106,14 +106,14 @@
|
||||
(import "" (module $m (export "" (func $f (result i32)))))
|
||||
(instance $i (instantiate $m))
|
||||
(func $get (export "") (result i32)
|
||||
call $i.$f))
|
||||
call (func $i "")))
|
||||
|
||||
(module $m2
|
||||
(func (export "") (result i32)
|
||||
i32.const 5))
|
||||
(instance $i (instantiate $m1 (module $m2)))
|
||||
(instance $i (instantiate $m1 "" (module $m2)))
|
||||
(func (export "get") (result i32)
|
||||
call $i.$get)
|
||||
call (func $i ""))
|
||||
)
|
||||
(assert_return (invoke "get") (i32.const 5))
|
||||
|
||||
@@ -122,16 +122,16 @@
|
||||
(module $m
|
||||
(import "" (module $m (export "get" (func (result i32)))))
|
||||
(instance $i (instantiate $m))
|
||||
(alias $f (instance $i) (func 0))
|
||||
(alias $f (func $i "get"))
|
||||
(export "" (func $f))
|
||||
)
|
||||
(module $m2
|
||||
(func (export "get") (result i32)
|
||||
i32.const 6))
|
||||
(instance $a (instantiate $m (module $m2)))
|
||||
(instance $a (instantiate $m "" (module $m2)))
|
||||
|
||||
(func (export "get") (result i32)
|
||||
call $a.$f)
|
||||
call (func $a ""))
|
||||
)
|
||||
(assert_return (invoke "get") (i32.const 6))
|
||||
|
||||
@@ -143,10 +143,10 @@
|
||||
(import "a" "memory" (memory $m 1))
|
||||
|
||||
(module
|
||||
(import "" (memory 1))
|
||||
(import "" (global (mut i32)))
|
||||
(import "" (table 1 funcref))
|
||||
(import "" (func))
|
||||
(import "m" (memory 1))
|
||||
(import "g" (global (mut i32)))
|
||||
(import "t" (table 1 funcref))
|
||||
(import "f" (func))
|
||||
(func $start
|
||||
call 0
|
||||
|
||||
@@ -163,10 +163,10 @@
|
||||
|
||||
(instance $a
|
||||
(instantiate 0
|
||||
(memory $m)
|
||||
(global $g)
|
||||
(table $t)
|
||||
(func $f)
|
||||
"m" (memory $m)
|
||||
"g" (global $g)
|
||||
"t" (table $t)
|
||||
"f" (func $f)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -183,10 +183,10 @@
|
||||
(module $mt (import "" (table 1 funcref)))
|
||||
(module $mg (import "" (global (mut i32))))
|
||||
|
||||
(instance (instantiate $mm (memory $m)))
|
||||
(instance (instantiate $mf (func $f)))
|
||||
(instance (instantiate $mt (table $t)))
|
||||
(instance (instantiate $mg (global $g)))
|
||||
(instance (instantiate $mm "" (memory $m)))
|
||||
(instance (instantiate $mf "" (func $f)))
|
||||
(instance (instantiate $mt "" (table $t)))
|
||||
(instance (instantiate $mg "" (global $g)))
|
||||
)
|
||||
|
||||
;; instantiate nested
|
||||
@@ -204,13 +204,13 @@
|
||||
(import "" (func))
|
||||
(start 0)
|
||||
)
|
||||
(instance (instantiate 0 (func 0)))
|
||||
(instance (instantiate 0 "" (func 0)))
|
||||
)
|
||||
(instance (instantiate 0 (func 0)))
|
||||
(instance (instantiate 0 "" (func 0)))
|
||||
)
|
||||
(instance (instantiate 0 (func 0)))
|
||||
(instance (instantiate 0 "" (func 0)))
|
||||
)
|
||||
(instance (instantiate 0 (func 0)))
|
||||
(instance (instantiate 0 "" (func 0)))
|
||||
)
|
||||
(assert_return (invoke $a "get") (i32.const 1))
|
||||
|
||||
@@ -219,20 +219,14 @@
|
||||
(module (export "m"))
|
||||
(instance (export "i") (instantiate 0))
|
||||
)
|
||||
(module
|
||||
(import "b" "m" (module))
|
||||
(import "b" "i" (instance))
|
||||
)
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(import "b" "m" (module (import "" (func))))
|
||||
)
|
||||
"module types incompatible")
|
||||
(module (import "b" "m" (module)))
|
||||
(module (import "b" "m" (module (import "" (func)))))
|
||||
(module (import "b" "i" (instance)))
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(import "b" "i" (instance (export "" (func))))
|
||||
)
|
||||
"instance types incompatible")
|
||||
"incompatible import type")
|
||||
|
||||
;; ensure we ignore other exported items
|
||||
(module $b
|
||||
@@ -250,7 +244,7 @@
|
||||
))
|
||||
|
||||
(func (export "get") (result i32)
|
||||
global.get $i.$g)
|
||||
global.get (global $i "g"))
|
||||
)
|
||||
(assert_return (invoke "get") (i32.const 0xfeed))
|
||||
|
||||
@@ -270,15 +264,45 @@
|
||||
(module
|
||||
(import "b" "i" (instance $i
|
||||
;; notice that this order is swapped
|
||||
(export "g" (func $g (param i32) (result i32)))
|
||||
(export "f" (func $f (result i32)))
|
||||
(export "g" (func (param i32) (result i32)))
|
||||
(export "f" (func (result i32)))
|
||||
))
|
||||
|
||||
(func (export "f") (result i32)
|
||||
call $i.$f)
|
||||
call (func $i "f"))
|
||||
(func (export "g") (param i32) (result i32)
|
||||
local.get 0
|
||||
call $i.$g)
|
||||
call (func $i "g"))
|
||||
)
|
||||
(assert_return (invoke "f") (i32.const 300))
|
||||
(assert_return (invoke "g" (i32.const 3000)) (i32.const 3100))
|
||||
|
||||
(module $a
|
||||
(func (export "f")))
|
||||
|
||||
(module
|
||||
(import "a" "f" (func))
|
||||
|
||||
(module $m1
|
||||
(import "a" "f" (func)))
|
||||
(instance (instantiate $m1 "a" (instance 0)))
|
||||
)
|
||||
|
||||
(module
|
||||
(import "a" "f" (func))
|
||||
|
||||
;; this module provides nothing
|
||||
(module $m1)
|
||||
|
||||
;; this module imports a module which it says imports something
|
||||
(module $m2
|
||||
(module $a
|
||||
(func (export "")))
|
||||
(instance $i (instantiate $a))
|
||||
(import "m" (module $b (import "" (func))))
|
||||
(instance $b (instantiate $b "" (func $i ""))))
|
||||
|
||||
;; we should be able to instantiate m2 with m1 because m1 doesn't actually
|
||||
;; import anything (always safe to remove imports!)
|
||||
(instance (instantiate $m2 "m" (module $m1)))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user