Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

wasm: implement imports #40

Open
sbinet opened this issue Dec 5, 2017 · 4 comments
Open

wasm: implement imports #40

sbinet opened this issue Dec 5, 2017 · 4 comments

Comments

@sbinet
Copy link
Contributor

sbinet commented Dec 5, 2017

wasm.ReadModule needs to be able to handle imports.

perhaps wasm.ResolveFunc should be an interface instead of a type X func to be able to import builtin functions (e.g. print)

@sbinet
Copy link
Contributor Author

sbinet commented Dec 5, 2017

@vibhavp do you want (and/or have the cycles) to have a stab at it?
(just asking to reduce the amount of duplicated work)

@vibhavp
Copy link
Collaborator

vibhavp commented Dec 7, 2017

If you take a look at the wasm fork, it uses JavaScript to provide access to some runtime functions that cannot be implemented alone in WebAssembly. We could allow the table of a wasm.Module to be populated with Go functions. Similarly, exec would also need some modification so as to call Table elements with reflect.

Making ResolveFunc an interface would only allow for a fixed number of functions to be imported, while the WebAssembly spec also allows importing variables, tables and memory elements.

I have plans for adding preliminary support for Go functions in wagon, but I'm a little busy with other projects right now.

sbinet added a commit that referenced this issue Dec 13, 2017
sbinet added a commit that referenced this issue Dec 14, 2017
@abourget
Copy link

I have some .wast code that looks like:

(module
...
 (type $FUNCSIG$iii (func (param i32 i32) (result i32)))
 (import "env" "assert" (func $assert (param i32 i32)))
 (import "env" "load_i64" (func $load_i64 (param i64 i64 i64 i32 i32) (result i32)))
 (import "env" "read_message" (func $read_message (param i32 i32) (result i32)))
 (import "env" "remove_i64" (func $remove_i64 (param i64 i64 i32) (result i32)))
 (import "env" "require_auth" (func $require_auth (param i64)))
 (import "env" "require_notice" (func $require_notice (param i64)))
 (import "env" "store_i64" (func $store_i64 (param i64 i64 i32 i32) (result i32)))
 (table 0 anyfunc)
 (memory $0 1)
 (data (i32.const 4) "\c0@\00\00")
...

and I'd like to have those "env" functions be provided by native Go code.. would that be possible somehow ? Is that what you wanted to do @vibhavp ?

I'm interested in participating.. if you have a few cues / pointers / thoughts on how we could implement that.. I'd be taker :)

@sbinet
Copy link
Contributor Author

sbinet commented Apr 3, 2018

ping @vibhavp ?

Robert's work (bringing GOARCH=wasm to the official gc toolchain) is starting to percolate.
it would be great to have this working for Go-1.11.x :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants