#interpreter

bin+lib lovm2

a lightweight virtual machine with a focus on simplicity and extendability

13 releases

0.4.8 Feb 4, 2021
0.4.7 Dec 15, 2020
0.4.5 Nov 16, 2020
0.3.8 Nov 1, 2020
0.2.2 Aug 6, 2020

#39 in Emulators

Download history 40/week @ 2021-03-31 13/week @ 2021-04-07 22/week @ 2021-04-14 23/week @ 2021-04-21 13/week @ 2021-04-28 14/week @ 2021-05-12 16/week @ 2021-06-09 1/week @ 2021-06-30 13/week @ 2021-07-14

111 downloads per month

Custom license

210KB
5K SLoC

crates.io badge docs.rs badge

lovm2

lovm2 is a library for building your own programming language in the blink of an eye. It offers you easy to use constructs to generate bytecode for its virtual machine.

Features

  • Dynamic typing
  • Generate bytecode using a High-Level Intermediate Representation
  • Define own instructions as Interrupts
  • Extend your programs with Rust: lovm2 extend
  • Standard library included: lovm2_std
  • Python bindings: pylovm2

Examples

Add this line to your Cargo.toml:

lovm2 = "0.4.8"

Projects

Generating Bytecode

use lovm2::prelude::*;

let mut module = ModuleBuilder::new();

// a module needs a code object called `main`
// if you want to make it runnable
let main_hir = module.entry();

// set the local variable n to 10
main_hir.step(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.step(Call::new("print").arg(lv2_var!(n)).arg("Hello World"));
// ... this is equivalent to the developer-friendly version:
main_hir.step(lv2_call!(print, n, "Hello World"));

// creates a `Module` from the `ModuleBuilder`
let module = module.build().unwrap();
println!("{}", module);

// load the module and run it
let mut vm = create_vm_with_std();
vm.add_main_module(module).expect("load error");
vm.run().expect("run error");

Internal Source Code References

Customer Reviews

This Thing Fast - Sonic

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

Dependencies

~4.5–8MB
~169K SLoC