Importer module:
(module
(type $GG (func (param i32) (result i32)))
(import "low" "load" (func $load (param i32) (result i32)))
(table (import "low" "table") 2 anyfunc)
(func (export "func_0") (result i32)
(call_indirect $GG (i32.const 0) (i32.const 0))
)
)
Exporter module:
(module
(table 2 anyfunc)
(memory $0 100)
(export "memory" (memory $0))
(export "load" (func $local))
(func $local (param $0 i32) (result i32)
(i32.load (get_local $0))
)
)
I am trying to compile following two modules to wasm and then load using JS API. I am trying to use following JS code to make the import work:
var h = fetch("test.wasm")
.then(function(response) {
return response.arrayBuffer();
})
var l = fetch("low.wasm").
then(function(response){
return response.arrayBuffer();
})
var exp = l.then( function(buffer){
var moduleBufferView = new Uint8Array(buffer);
WebAssembly.instantiate(moduleBufferView)
.then(function(instantiated) {
const instance = instantiated.instance;
return instance.exports
})
})
fetch("test.wasm")
.then(function(response) {
return response.arrayBuffer();
})
.then(function(buffer) {
var moduleBufferView = new Uint8Array(buffer);
WebAssembly.instantiate(moduleBufferView, exp)
.then(function(instantiated) {
const instance = instantiated.instance;
document.getElementById('res').innerHTML = instance.exports.func_0();
})
});
While compiling using reference interpreter I am getting following error:
test.wast:4.8-4.67: link failure: unknown import "low"."load".
Error does make sense that test module is unaware of low while compiling, but how can I link them together?