Assemblyscript: Compilation error when trying to use call_indirect

Created on 19 Dec 2019  ·  4Comments  ·  Source: AssemblyScript/assemblyscript

Despite that it's described in the index.d.ts its usage produces an error "ERROR TS2304: Cannot find name 'call_indirect'" during compilation. The same goes for call_direct.

Most helpful comment

Yeah, these have been removed because of expected problems with a closure implementation. But one can still do this:

changetype<(a: i32, b: i32) => i32>(someTableIndex)(1, 2);

respectively

var tableIndex = changetype<usize>(someFunction);

All 4 comments

Seems like they were removed in here - https://github.com/AssemblyScript/assemblyscript/pull/974. Are there / will there be any replacements? In my case I need to associate a callback provided from the JS side with a wasm class. My plan was to pass a table to wasm module (using a --importTable flag) and then call it using something like call_indirect( this.callbackId )

After some considerations I came up with 2 possible solutions:
1) Maintain callback table in JS (just an array of callbacks) and provide invokeCallback(callbackId: i32): void method to wasm module.
2) Add a --tableBase option to compiler, so user will be able to reserve some space in the table specifically for callbacks. May work, but will probably complicate things on the compiler side.

Anyway, feel free to close this issue. The only thing is that call_indirect and call_direct should be removed from index.d.ts if they won't be added back in the feature

Yeah, these have been removed because of expected problems with a closure implementation. But one can still do this:

changetype<(a: i32, b: i32) => i32>(someTableIndex)(1, 2);

respectively

var tableIndex = changetype<usize>(someFunction);

fixed in #1017

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dcodeIO picture dcodeIO  ·  4Comments

kungfooman picture kungfooman  ·  5Comments

MaxGraey picture MaxGraey  ·  3Comments

Iainmon picture Iainmon  ·  3Comments

pannous picture pannous  ·  4Comments