Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 2.05 KB

ARCHITECTURE.md

File metadata and controls

42 lines (34 loc) · 2.05 KB

Architecture

Lunatic is a runtime for WebAssembly that runs Wasm modules as lightweight processes with its own heap/stack and preemptively schedules them on a multi-threaded executor. A running Wasm module can spawn new Lunatic processes using a guest library currently available for Rust and AssemblyScript. Scheduling is implemented by modifying a Wasm module and adding "gas"/"reduction counts" (similar to Erlang).

Lunatic uses Wasmtime to JIT compile and run Wasm

Main components

  • LunaticModule represents a Wasm module. It is created from a Wasm binary &[u8]. Before creating a Wasmtime module, it modifies it using walrus by adding reduction counts and other (see module::normalisation).
  • HostFunctions provide guest APIs for spawning processes, channels, WebAssembly System Interface (WASI), and networking (until WASI gets support for networking). An API implements uptown_funk::HostFunctions trait. This trait is usually implemented automatically using uptown_funk_macro.
  • LunaticLinker abstracts Wasmtime linking. It takes a Lunatic module and an API (impl HostFunctions) and returns an ready to execute instance.
  • Process (found in api::process module) takes LunaticModule and HostFunctions, links them, creates an AsyncWormhole (see AsyncWormhole crate) and runs the Wasm instance inside it. AsyncWormhole implements the Future trait.

Guest APIs and Uptown Funk

AsyncWormhole and Switcheroo