2 releases
new 0.1.1 | Feb 13, 2025 |
---|---|
0.1.0 | Feb 13, 2025 |
#330 in Programming languages
253 downloads per month
25KB
644 lines
simple-bytecode-vm
A bytecode virtual machine and compiler written in Rust.
Install
cargo add simple-vm
Example
let x = 5;
while x > 0 {
print x;
x = x - 1;
}
Features
- Basic arithmetic (add, subtract, multiply, divide)
- Variables
- While loops
- If/else statements
- Print statements
How it works
The VM takes your code, breaks it into simple instructions using a compiler, and runs them one by one. Like when you write x = x + 1, it becomes:
Load x Add 1 Save back to x
Usage
use simple_vm::{VM, compiler::{Parser, Compiler}};
let code = "let x = 5; print x;";
let bytecode = Compiler::new().compile(Parser::new(code).parse()?);
VM::new(bytecode, 1024).run()?;
License
MIT
Dependencies
~305–780KB
~18K SLoC