simple-vm

Crates.iosimple-vm
lib.rssimple-vm
version0.1.1
created_at2025-02-13 20:43:54.892099+00
updated_at2025-02-13 20:47:12.56998+00
descriptionA simple bytecode VM with a custom compiler
homepage
repositoryhttps://github.com/andropixels/simple-vm
max_upload_size
id1554763
size25,885
Sangeet (andropixels)

documentation

README

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

Commit count: 27

cargo fmt