Skip to content

Conversation

@jonasongg
Copy link

Implements a new Python to Wasm compilation and execution pipeline along with supporting infrastructure and some tests. All new files are placed in the src/wasm-compiler directory, except the Conductor executor and a wasm-compiler.specs.ts test file. The wabt dependency for compiling WAT (Wasm text format) into Wasm binary is also added.

An IR is also implemented to aid debugging and increase robustness of the compilation; WAT instructions are represented with structured TypeScript objects rather than with raw strings in the Python compilation. A builder API for building these objects is also included under src/wasm-compiler/wasm-util, but this is temporary and the plan is to publish wasm-util as a separate package.

Overall pipeline of compiler:

  • Python code
  • → parsed into Python AST (existing parser)
  • → translated to WAT IR
  • → translated to raw WAT
  • → compiled to Wasm binary (with wabt)

For Python compilation, a basic runtime is required to handle dynamic values, as well as defunctionalisation and lexical addressing to handle HOFs and closures. A suite of WebAssembly functions to take care of these, written with the builder API, can be found in src/wasm-compiler/constants.ts.

The translation from Python AST to WAT IR takes place in a generator class in src/wasm-compiler/builderGenerator.ts, which uses the visitor pattern. WAT IR to raw WAT translation, on the other hand, is handled by wasm-util, and is performed with another visitor generator.

The endpoint for the entire pipeline is the compileToWasmAndRun function under src/wasm-compiler/index.ts.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant