glyph-runtime 0.0.1

Runtime execution engine for the Glyph programming language
Documentation
//! Glyph Runtime VM
//!
//! Stack-based virtual machine for executing Glyph bytecode with
//! capability-based security and immutable-first design.

pub mod ast_to_ir;
pub mod capability;
pub mod compiler;
pub mod frame;
pub mod instruction;
pub mod ir;
pub mod ir_to_bytecode;
pub mod memory;
pub mod stack;
pub mod vm;

#[cfg(test)]
mod test_loops;

#[cfg(test)]
mod test_pattern_matching;

pub use capability::{Capability, CapabilitySet};
pub use compiler::{
    compile, compile_and_run, compile_and_run_with_config, CompileError, CompiledProgram,
};
pub use glyph_types::Value;
pub use instruction::Instruction;
pub use vm::{VMConfig, VMError, VM};

use thiserror::Error;

#[derive(Debug, Error)]
pub enum RuntimeError {
    #[error("Type error: {0}")]
    TypeError(String),

    #[error("Capability error: {0}")]
    CapabilityError(String),

    #[error("Stack overflow")]
    StackOverflow,

    #[error("Stack underflow")]
    StackUnderflow,

    #[error("Division by zero")]
    DivisionByZero,

    #[error("Index out of bounds: {index} for length {length}")]
    IndexOutOfBounds { index: i64, length: usize },

    #[error("Key not found: {0}")]
    KeyNotFound(String),

    #[error("Undefined variable: {0}")]
    UndefinedVariable(String),

    #[error("Function not found: {0}")]
    FunctionNotFound(usize),

    #[error("Native function error: {0}")]
    NativeFunctionError(String),
}