Skip to content
A WebAssembly interpreter written in pure Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Bump version to v0.4.5 Feb 23, 2019
pywasm
tests Support HostFunc for import Jan 23, 2019
.gitignore
.travis.yml Travis CI appended Jan 4, 2019
LICENSE Create LICENSE Dec 25, 2018
README.md Add tested environments description May 3, 2019
setup.py Bump version to v0.4.6 Mar 14, 2019

README.md

pywasm: A WebAssembly interpreter written in pure Python.

Build Status

A WebAssembly interpreter written in pure Python. JIT used.

The wasm version currently in use is: WebAssembly Core Specification W3C Working Draft, 4 September 2018. Just like Firefox or Chrome does.

Installation

$ pip3 install pywasm

Some simple examples

  1. First we need a wasm module! Grab our ./examples/fib.wasm file and save a copy in a new directory on your local machine. Note: fib.wasm was compiled from ./examples/fib.c by WasmFiddle.

  2. Now, compile and instantiate WebAssembly modules directly from underlying sources. This is achieved using the pywasm.load method.

import pywasm
# pywasm.on_debug()

vm = pywasm.load('./examples/fib.wasm')
r = vm.exec('fib', [10])
print(r) # 55

A brief description for ./examples

File Description
./examples/add.wasm Export i32.add function
./examples/env.wasm Call python/native function in wasm
./examples/fib.wasm Fibonacci, which contains loop and recursion
./examples/str.wasm Export a function which returns string
./examples/sum.wasm Equal difference series summation

Test

python ./tests/test_spec.py

Tested in the following environments:

  • Python 3.7.3
  • Python 3.6.5

Thanks

License

WTFPL

You can’t perform that action at this time.