Skip to content

Instantly share code, notes, and snippets.

@vibhavp

vibhavp/gsoc.md Secret

Last active September 16, 2017 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vibhavp/f6041cf6e21c2b2285f4056b3230a2b8 to your computer and use it in GitHub Desktop.
Save vibhavp/f6041cf6e21c2b2285f4056b3230a2b8 to your computer and use it in GitHub Desktop.
Launching Wagon, a WebAssembly interpreter in Go

Launching Wagon, a WebAssembly interpreter in Go

Talk slides

GSoC Page

Wagon exports multiple packages in accordance with the official WebAssembly specification:

  • Provides functions and strucutres for reading .wasm modules. The sub-package wasm/operators defines all WebAssembly operators, with their return and parameter types.

  • Main entry point: func ReadModule(r io.Reader, resolvePath ResolveFunc) (*Module, error). Module resolution is left to the user, to allow for non-WebAssembly/Go functions to be imported.

  • Functions Get{Function|Global|LinearMemoryData|TableElement} provide access to a module's index spaces.

  • validate allows users to validate a WebAssembly module.
  • It checks whether operators have correct intermediate values, type checks operands to operators and function calls, makes sure that control blocks or sequences have a consistent stack, verifies nesting depth for branching operators, etc.
  • However, validation isnt restricted to the package validate alone. For instance, wasm makes sure that all imported global variables are non-mutable, as per the WASM spec.
  • While not a part of the official API, disasm allows users to disassemble WASM bytecode.
  • It does so by providing various types that describe the structure of a WASM function - with stack and control information.

Work yet to be done:

JIT

Because I am not familiar with the code generation phase of the Go compiler (gc), and that JIT libraries produce code that wouldn't execute properly in a Go environment (calling conventions, lack of dynamic stacks), I was not able to add JIT functionality to wagon. However, since the recent work on a plugin architecture in Go has allowed for dynamic loading of Go code, JIT might be a posibility soon.

Interoperability with Go

As a part of the go-interpreter project, wagon should allow for WebAssembly code to refer to Go-land data and be able to call Go functions. This requires the development of an intermediate ABI for passing native Go types to WebAssembly.

Concurrency

One of Go's most promiment features is its concurrency constructs. Because they aren't yet avialable in WebAssembly, support for future concurrency APIs will have to be implemented in the future - perhaps with the help of an internal module imported by other modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment