Crate lovm2

Source
Expand description

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::create_vm_with_std;
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"));

// 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 = create_vm_with_std();
vm.add_main_module(module).expect("load error");
vm.run().expect("run error");

Modules§

code
Runnable bytecode objects
error
Error values for compilation and runtime
extend
lovm2::extend bundles functionality for writing lovm2 extensions using Rust. You can either statically import functions or produce a shared object that can be loaded at runtime.
gen
Tools for generating bytecode
module
Generic protocol for module like objects
prelude
Important structs, enums and constants for using lovm2 as library
util
Helper functionality for solving small tasks
value
Representation and operations for lovm2 values
vm
Runs modules and maintains program state

Macros§

lv2_access
Creates an Access expression
lv2_call
Creates a Call expression
lv2_dict
Creates a dict Initialize expression using Expr as items
lv2_list
Creates a list Initialize expression using Expr as items
lv2_var
Creates a Variable from a rust identifier

Structs§

Variable
A thin wrapper around an identifier name.

Enums§

Instruction
Definition of the bytecode

Functions§

create_vm_with_std
Create a new instance with standard functions already imported