glyph_runtime/
lib.rs

1//! Glyph Runtime VM
2//!
3//! Stack-based virtual machine for executing Glyph bytecode with
4//! capability-based security and immutable-first design.
5
6pub mod ast_to_ir;
7pub mod capability;
8pub mod compiler;
9pub mod frame;
10pub mod instruction;
11pub mod ir;
12pub mod ir_to_bytecode;
13pub mod memory;
14pub mod stack;
15pub mod vm;
16
17#[cfg(test)]
18mod test_loops;
19
20#[cfg(test)]
21mod test_pattern_matching;
22
23pub use capability::{Capability, CapabilitySet};
24pub use compiler::{
25    compile, compile_and_run, compile_and_run_with_config, CompileError, CompiledProgram,
26};
27pub use glyph_types::Value;
28pub use instruction::Instruction;
29pub use vm::{VMConfig, VMError, VM};
30
31use thiserror::Error;
32
33#[derive(Debug, Error)]
34pub enum RuntimeError {
35    #[error("Type error: {0}")]
36    TypeError(String),
37
38    #[error("Capability error: {0}")]
39    CapabilityError(String),
40
41    #[error("Stack overflow")]
42    StackOverflow,
43
44    #[error("Stack underflow")]
45    StackUnderflow,
46
47    #[error("Division by zero")]
48    DivisionByZero,
49
50    #[error("Index out of bounds: {index} for length {length}")]
51    IndexOutOfBounds { index: i64, length: usize },
52
53    #[error("Key not found: {0}")]
54    KeyNotFound(String),
55
56    #[error("Undefined variable: {0}")]
57    UndefinedVariable(String),
58
59    #[error("Function not found: {0}")]
60    FunctionNotFound(usize),
61
62    #[error("Native function error: {0}")]
63    NativeFunctionError(String),
64}