Crates.io | lovm2 |
lib.rs | lovm2 |
version | 0.4.8 |
source | src |
created_at | 2020-06-29 16:43:01.156834 |
updated_at | 2021-02-04 13:54:50.508605 |
description | a lightweight virtual machine with a focus on simplicity and extendability. |
homepage | https://github.com/lausek/lovm2 |
repository | https://github.com/lausek/lovm2 |
max_upload_size | |
id | 259474 |
size | 111,701 |
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.
Interrupt
sAdd this line to your Cargo.toml
:
lovm2 = "0.4.8"
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");
This Thing Fast - Sonic
And I thought I was simple... - Pythagorean Theorem