Skip to content

Instantly share code, notes, and snippets.

@vibhavp vibhavp/ Secret

Last active Sep 16, 2017
What would you like to do?
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:


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.


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
You can’t perform that action at this time.