| Crates.io | simple-vm |
| lib.rs | simple-vm |
| version | 0.1.1 |
| created_at | 2025-02-13 20:43:54.892099+00 |
| updated_at | 2025-02-13 20:47:12.56998+00 |
| description | A simple bytecode VM with a custom compiler |
| homepage | |
| repository | https://github.com/andropixels/simple-vm |
| max_upload_size | |
| id | 1554763 |
| size | 25,885 |
A bytecode virtual machine and compiler written in Rust.
cargo add simple-vm
let x = 5;
while x > 0 {
print x;
x = x - 1;
}
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
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()?;
MIT