1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! 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_std` core 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`:
//!
//! ```no_run
//! 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(),
//! lv: None,
//! catch_target_pos: Vec::new(),
//! };
//!
//! let mut vm = vm::VM::new_by_raw_irep(irep);
//! let value = vm.run()?;
//! println!("{:?}", value);
//! Ok(())
//! }
//! ```
//!
//! # Ruby Compatibility
//!
//! mruby/edge implements a subset of the Ruby standard library.
//! The built-in classes and methods that are currently supported are listed in
//! [`COVERAGE.md`](https://github.com/mrubyedge/mrubyedge/blob/master/mrubyedge/COVERAGE.md).
//!
//! In brief, the following classes are available out of the box:
//! `Object`, `Integer`, `Float`, `String`, `Array`, `Hash`, `Range`,
//! `Symbol`, `Proc`, `NilClass`, `TrueClass`, `FalseClass`, `Module`,
//! `Class`, `Exception` (and standard subclasses), and the `Enumerable`
//! module. Additional classes such as `Random` and `Regexp` are available
//! behind Cargo feature flags (`mruby-random` and `mruby-regexp`).
//! A `SharedMemory` class unique to mruby/edge provides zero-copy access to
//! WASM linear memory.
//!
//! Loading a precompiled `*.mrb` produced by `mrbc` is also straightforward
//! using `include_bytes!`:
//!
//! ```no_run
//! 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 for easier access
pub use Error;
pub use ;
pub use RObject;
pub use VM;
/// The version of the mrubyedge crate
pub const VERSION: &str = version!;