crates.io badge docs.rs badge

lovm2

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

lovm2 = "0.4.7"

Features

Examples

Projects

Source Code References

Generating Bytecode

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

let mut module = ModuleBuilder::new();

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

// set the local variable n to 10 mainhir.step(Assign::local(&lv2var!(n), 10));

// print is a builtin function. the lv2_var! macro // ensures that the given identifier is not confused // with a string. mainhir.step(Call::new("print").arg(lv2var!(n)).arg("Hello World")); // ... this is equivalent to the developer-friendly version: mainhir.step(lv2call!(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 = Vm::withstd(); vm.addmain_module(module).expect("load error"); vm.run().expect("run error"); ```

Customer Reviews

This Thing Fast - Sonic

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