W16 — runtime.
Hi !
For the past 3 months, I’ve been working on W16. What is this project about? Here is a brief overview (for more details, feel free to visit the repository).
In Short
>W16 is a multi-stage pipeline language runtime written in Rust.
What does "Multi-stage Pipeline" mean here?
It means that W16 doesn't just use a simple Bytecode -> VM approach. Instead, it utilizes HIR, MIR, Bytecode, and multiple bytecode execution engines.
The pipeline looks like this:
Pipeline Breakdown
- HIR:
- What it is: A high-level, structured, and typed intermediate representation.
- Why: To allow any language frontend to easily translate its source code into a representation that is convenient for the runtime.
- Why not jump straight to bytecode or MIR?: Because it is much more convenient for a developer to target a high-level HIR rather than low-level bytecode right away.
- MIR:
- What it is: A mid-level
SSA IR. - Why: It is the perfect place for optimizations. The SSA form makes writing an optimizer clean and straightforward, and since the representation isn't as low-level as bytecode, it makes development even more convenient.
- Bytecode:
- What it is: A register-based, 3-address (two source operands and one destination register), 32-bit bytecode.
- Why: This is the most efficient format for interpretation, as well as for JIT/AOT compilation.
- Bytecode Layout:
| 8-bit | 8-bit | 8-bit | 8-bit | Total |
|---|---|---|---|---|
| Opcode | Destination Register | First Operand | Second Operand | 32-bit |
- Standard VM:
- What it is: A standard virtual machine for executing bytecode. It's called "standard" because the runtime actually features two different VMs.
- Why: Because a standard VM is more stable than the alternative executor.
- Orca VM:
- What it is: An experimental VM. It is experimental because it skips runtime checks and the codebase is
very unsafe. - Why: Fewer checks = faster execution speed.
- JIT Compiler:
- What it is: A Just-In-Time compiler that compiles bytecode into native machine code on the fly.
- Why: For maximum bytecode execution performance.
- AOT Compiler:
- What it is: An experimental Ahead-Of-Time compiler. In W16, it generates an object file and then invokes an external host linker (
link.exefrom MSVC on Windows,ccon macOS & Linux). It is considered experimental precisely because it relies on this external linker invocation. - Why: To make it possible to compile bytecode directly into a standalone executable file.
Have any languages been built using W16 as a backend?
>So far, no stable compilers have been created using W16 for code generation.
HOWEVER! As part of the project, I built an experimental C compiler (C11 standard) that has most core features implemented (though some are still missing). You can find its codebase in the exact same repository where W16 lives.
Libraries I use
cranelift(and its sub-crates) — used for both JIT and AOT code generation.target-lexicon— required for handling target architectures during AOT compilation.cc— also used for AOT compilation to locate the system linker.
Links
Project Status
>Currently paused
Recently, I decided that I want to completely rewrite w16-ir (a workspace crate within the project). Because of this, I am currently actively focusing on implementing this new crate.
Feedback
I would be incredibly happy if you find the project interesting! If you have any questions, thoughts, or advice — I'm right here.