A WebAssembly interpreter written in C for demonstration.
This repository implements a WebAssembly interpreter. It is written to clarify how a WebAssembly interpreter works and try out the latest proposal. So the code is easy to understand, and there are lots of code comments to explain the intention behind the code.
You can get the executable via Makefile or CMake.
cmake ./ make
You can call the executable with
[wasmc executable path] [wasm file path]
Wasmc loads the wasm file and return a REPL(read-eval-print-loop). You can invoke some exported function of the wasm file as shown below.
Note: the interpreter now only supports the wasm file compiled from wat file.
Here is description for
|./examples/arith.wasm||Export add/sub/mul/div_u function with two i32 type of parameters|
|./examples/fib.wasm||Export recursive fibonacci function with an i32 type of parameter|
|./examples/fac.wasm||Export recursive factorial function with an i32 type of parameter|
Here are core modules.
├── cli.c // the entry of interpreter ├── module.c // decode from binary format to memory format ├── interpreter.c // stack based virtual machine ├── opcode.h // webassembly opcode enum └── utils.c // utility libraries
Learn more via article below.