A Jupyter kernel for compiling WebAssembly modules. Implemented using the Wasmer Python library, WebAssembly Binary Toolkit, and IPython Kernel. The motivation for the project is to be able to utilize WebAssembly within Jupyter notebooks as well as have cross language capabilities between WebAssembly and Python. This is achieved using the Wasmer Python library as well as extending the IPython kernel.
-
Python 3
-
Jupyter
-
iPykernel
WebAssembly Binary Toolkit is required for the compilation of WebAssembly code. After installing the binary toolkit, make sure it is in your PATH. If you install from source, add the /bin/ folder to your PATH:
export PATH=$PATH:/.../wabt/bin
pip install wasmer
Once your system has the requirements - navigate to the combinedWasmerKernel folder and add the kernel to jupyter.
$ cd combinedWasmerKernel
$ jupyter kernelspec install wasmerKernel
Screenshots from an example notebook have been provided to show some use cases.
in the above image we demonstrate the ability to create a function in WebAssembly, and call that function within python. To differentiate between WebAssembly code and Python code, headers are used to identify the language. *WASM* is used for WebAssembly and *PYTHON* is used for Python.
To access created WebAssembly modules, the modules are stored in a dictionary called self.instances
where the key is the module name, and the value is an instance of the WebAssembly module. To access exported functions within a module, you would access them like so:
self.instances["module_name"].exports.function_name(input_params)
to print output of a cell, assign output to self.output
This project is a final project for the course COMP SCI 4TB3 / 6TB3 Syntax-Based Tools and Compilers at McMaster University.
Authors:
- Jakub Pawlikowski
- Anthony Mella
- Tyler Philips