yamt / toywasm

A WebAssembly interpreter written in C
BSD 2-Clause "Simplified" License
75 stars 8 forks source link
interpreter runtime wasi wasm webassembly

What's this?

A WebAssembly interpreter written in C.

Goals

Non-goals

What are implemented?

Feature cmake config Notes
WebAssembly 2.0 (Draft 2022-06-27)
extended-const TOYWASM_ENABLE_WASM_EXTENDED_CONST
exception-handling TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING See the top comment in insn_impl_eh.h
multi-memory TOYWASM_ENABLE_WASM_MULTI_MEMORY
tail-call TOYWASM_ENABLE_WASM_TAILCALL
threads TOYWASM_ENABLE_WASM_THREADS
custom-page-sizes TOYWASM_ENABLE_WASM_CUSTOM_PAGE_SIZES
wasi_snapshot_preview1 TOYWASM_ENABLE_WASI See the top comment in wasi.c
wasi-threads TOYWASM_ENABLE_WASI_THREADS
dynamic-linking TOYWASM_ENABLE_DYLD
littlefs for WASI TOYWASM_ENABLE_WASI_LITTLEFS

Note: As this runtime is relatively new, all proposals which had finished when I started this implementation are just included in the WebAssembly in the above table. It includes mutable-global, nontrapping-float-to-int-conversions, sign-extension-ops, multi-value, reference-types, bulk-memory-operations, simd.

Where can this run?

Platform Tested on CI Notes
macOS/amd64 Yes
wasm32-wasi Yes (on toywasm)
Ubuntu/amd64 Yes
Ubuntu/i386 Yes 32-bit, smaller alignment
Ubuntu/arm64 Yes (on qemu)
Ubuntu/armhf Disabled 32-bit
Ubuntu/s390x Disabled Big endian
Ubuntu/riscv64 Yes (on qemu)
Windows/X64 Yes Core wasm only
wasm32-wasi-threads No Occasionally tested manually
NuttX/esp32 No Occasionally tested manually
NuttX/sim on macOS/amd64 No Occasionally tested manually
NetBSD/amd64 No Occasionally tested manually

Use as a command

See toywasm command help message.

Usage:
    toywasm [OPTIONS] [--] <MODULE> [WASI-ARGS...]
Options:
    --allow-unresolved-functions
    --disable-jump-table
    --disable-localtype-cellidx
    --disable-resulttype-cellidx
    --dyld
    --dyld-bindnow
    --dyld-dlfcn
    --dyld-path LIBRARY_DIR
    --dyld-stack-size C_STACK_SIZE_FOR_PIE_IN_BYTES
    --invoke FUNCTION[ FUNCTION_ARGS...]
    --load MODULE_PATH
    --max-frames NUMBER_OF_FRAMES
    --max-memory MEMORY_LIMIT_IN_BYTES
    --max-stack-cells NUMBER_OF_CELLS
    --repl
    --repl-prompt STRING
    --print-build-options
    --print-stats
    --timeout TIMEOUT_MS
    --version
    --wasi
    --wasi-dir HOST_DIR[::GUEST_DIR]
    --wasi-env NAME=VAR
    --wasi-littlefs-dir LITTLEFS_IMAGE_PATH::LFS_DIR[::GUEST_DIR]
Examples:
    Run a wasi module
        toywasm --wasi module
    Load a module and invoke its function
        toywasm --load module --invoke "func arg1 arg2"

Use as a library

See example apps:

Toywasm provides cmake config files for its libraries. If your app is using cmake, you can use find_package to find toywasm libraries as it's done in the CMakeLists.txt of the above example apps.

Release binaries

Warning Toywasm version numbers are NOT a semver. It's just an increasing number, which doesn't imply anything about compatibilities or features.

Build from source

How slow/fast is this?

Why is this slow?

Internals

References