Expand description
mruby/edge is a pure-Rust reimplementation of the mruby VM that keeps its
core execution engine no_std-friendly while striving for behavioral
compatibility with upstream mruby. It primarily targets WebAssembly
deployments, yet remains embeddable inside ordinary Rust binaries for host
tooling or native experimentation.
Key goals:
- Written in idiomatic Rust with a
no_stdcore so it can run in constrained environments. - Behavior compatible with the mruby VM so existing bytecode executes as-is.
- First-class WebAssembly target support.
- Ergonomic embedding in general Rust applications.
Basic initialization follows the pattern shown in examples/newvm.rs:
use mrubyedge::yamrb::{op, vm, value::RSym};
use mrubyedge::rite::insn::{Fetched, OpCode};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let irep = vm::IREP {
__id: 0,
nlocals: 0,
nregs: 7,
rlen: 0,
code: vec![
op::Op { code: OpCode::LOADI_1, operand: Fetched::B(1), pos: 0, len: 2 },
op::Op { code: OpCode::LOADI_2, operand: Fetched::B(2), pos: 2, len: 2 },
op::Op { code: OpCode::MOVE, operand: Fetched::BB(4, 1), pos: 4, len: 3 },
op::Op { code: OpCode::MOVE, operand: Fetched::BB(5, 2), pos: 7, len: 3 },
op::Op { code: OpCode::ADD, operand: Fetched::B(4), pos: 10, len: 2 },
op::Op { code: OpCode::SSEND, operand: Fetched::BBB(3, 0, 1), pos: 12, len: 4 },
op::Op { code: OpCode::RETURN, operand: Fetched::B(3), pos: 16, len: 2 },
op::Op { code: OpCode::STOP, operand: Fetched::Z, pos: 18, len: 1 },
],
syms: vec![RSym::new("puts".to_string())],
pool: Vec::new(),
reps: Vec::new(),
catch_target_pos: Vec::new(),
};
let mut vm = vm::VM::new_by_raw_irep(irep);
let value = vm.run()?;
println!("{:?}", value);
Ok(())
}Loading a precompiled *.mrb produced by mrbc is also straightforward
using include_bytes!:
use mrubyedge::rite;
use mrubyedge::yamrb::vm;
// Bundle the compiled script at build time.
const SCRIPT: &[u8] = include_bytes!("../examples/simple.mrb");
fn run_embedded() -> Result<(), Box<dyn std::error::Error>> {
let mut rite = rite::load(SCRIPT)?;
let mut vm = vm::VM::open(&mut rite);
let value = vm.run()?;
println!("{:?}", value);
Ok(())
}Re-exports§
pub use error::Error;
Modules§
- error
- eval
- rite
- Entry point that groups the mruby/rite (mrb) helpers.
It understands the binary layout, instruction stream, and marker metadata,
exposing higher-level APIs via the
ritesubmodule. - yamrb
- Yet Another mruby (yamrb) runtime layer. Provides value representation, opcode tables, helpers, and the VM itself so mruby bytecode can execute inside Rust.
Macros§
- version
- The version of the mrubyedge crate