bin+lib lovm2

a lightweight virtual machine with a focus on simplicity and extendability

11 releases

0.4.5 Nov 16, 2020
0.4.0 Nov 3, 2020
0.3.8 Nov 1, 2020
0.2.11 Jul 24, 2020
0.2.2 Aug 6, 2020

#15 in Emulators

44 downloads per month

Custom license

3.5K SLoC

crates.io badge docs.rs badge


Is a lightweight virtual machine with a focus on simplicity and extendability.

lovm2 = "0.4.5"


  • dynamic typing
  • generate bytecode using highlevel intermediate representation
  • call into shared objects: lovm2_extend
  • python bindings: pylovm2
  • define own callbacks for interrupts



Source Code References

Generating Bytecode

use lovm2::prelude::*;
use lovm2::vm::Vm;

fn main() {
    let mut main_hir = HIR::new();

    // set the local variable n to 10
    main_hir.push(Assign::local(lv2_var!(n), 10));

    // `print` is a builtin function. the `lv2_var!` macro
    // ensures that the given identifier is not confused
    // with a string.
    main_hir.push(Call::new("print").arg(lv2_var!(n)).arg("Hello World"));
    // ... this is equivalent to the developer-friendly version:
    main_hir.push(lv2_call!(print, n, "Hello World"));

    let mut module = ModuleBuilder::new();

    // a module needs a code object called `main`
    // if you want to make it runnable

    // consumes the `ModuleBuilder` and transforms
    // it into a `Module`
    let module = module.build().unwrap();
    println!("{:#?}", module);

    // load the module and run it
    let mut vm = Vm::with_std();
    vm.load_and_import_all(module).expect("load error");
    vm.run().expect("run error");

Customer Reviews

This Thing Fast - Sonic

And I thought I was simple... - Pythagorean Theorem


~40K SLoC