Raymer's Assembler and Loader — a simple register-based VM with its own assembler, written in Rust.
ralr is a lightweight virtual machine with a custom register-based instruction set. It comes with:
| Component | Description |
|---|---|
ralr-asm |
Assembler — compiles .ralr source to .abin bytecode |
ralr |
VM runtime — loads and executes .abin files |
vm-isa |
Shared library — instruction set architecture types |
The VM supports variables, control flow (if/else/while), functions with parameters and return values, classes with fields and methods, I/O operations, and a full expression system with operator precedence.
git clone https://github.com/Raymer8639/ralr.git
cd ralr
./install.shThis builds the release binaries and installs them to ~/.cargo/bin/. Requires Rust 1.85+ (edition 2024).
cargo build --release
# Binaries are at target/release/ralr and target/release/ralr-asm./uninstall.sh# Assemble a source file
ralr-asm examples/add.ralr -o add.abin
# Run the bytecode
ralr add.abin$a1 = (1 + 2) * 3; // arithmetic with precedence
$a2 = $a1 < 10; // comparison → Bool
$a3 = true && false; // logical
$a4 = 255 & 15; // bitwise
$a5 = -5; // unary negation
io writeln "Hello, world!";
io write "Enter a number: ";
io read $a1;
io writeln $a1;
if $a1 > 0 {
io writeln "positive";
} else if $a1 == 0 {
io writeln "zero";
} else {
io writeln "negative";
}
while $a1 < 10 {
$a1 = $a1 + 1;
}
let x = 42;
let mut y = 10;
y = y + 1;
io writeln y;
fn add(a, b) {
return a + b;
}
$a1 = call add(3, 5);
io writeln $a1; // 8
class Point {
let x = 0;
let y = 0;
fn init(self, x, y) {
self.x = x;
self.y = y;
}
fn sum(self) {
return self.x + self.y;
}
}
let mut p = new Point(3, 4);
$a1 = p.sum(); // 7
p.x = 100;
io writeln p; // Point { x: 100, y: 4 }
.ralr (text) ──[ralr-asm]──→ .abin (bincode) ──[ralr]──→ register state
- 5 general-purpose registers (
$a1–$a5) + 1 internal buffer - Variable store — hashmap-backed, mutable/immutable
- Function table — definitions registered at runtime, replayed on each call
- Class table — classes registered at runtime; objects carry their fields and dispatch methods by name
- Binary format —
bincodeserialization of theOpCodeAST
See CLAUDE.md for the full architecture reference.
| File | Demonstrates |
|---|---|
add.ralr |
Arithmetic with register chaining |
print.ralr |
Output and escape sequences |
block.ralr |
Nested { } code blocks |
expr.ralr |
Expression system with full operator precedence |
if_else.ralr |
Conditional branching |
while.ralr |
While loops |
io.ralr |
I/O operations |
var.ralr |
Variables and mutation |
fn.ralr |
Functions, parameters, closures |
oop.ralr |
Classes, fields, methods, new |
Multi-language docs under docs/:
| Language | Directory |
|---|---|
| 中文 | docs/zh/ |
| English | docs/en/ |
Start at docs/INDEX.md for the language selector.
See CONTRIBUTING.md for guidelines. Pull requests are welcome.