glyph-runtime 0.0.1

Runtime execution engine for the Glyph programming language
Documentation
//! Simple example of using the Glyph VM

use glyph_runtime::{Instruction, VMConfig, Value, VM};

fn main() {
    // Create VM with default configuration
    let config = VMConfig::default();
    let mut vm = VM::new(config);

    // Create a simple program that:
    // 1. Pushes two numbers
    // 2. Adds them
    // 3. Creates a list with the result
    // 4. Returns the list
    let program = vec![vec![
        Instruction::Push(Value::Int(10)),
        Instruction::Push(Value::Int(32)),
        Instruction::Add,
        Instruction::Push(Value::Str("Result".to_string())),
        Instruction::Swap,
        Instruction::MakeList(2),
        Instruction::Halt,
    ]];

    // Load and execute the program
    vm.load_bytecode(program);

    match vm.execute() {
        Ok(result) => {
            println!("Program result: {result}");

            // Show telemetry if any
            if !vm.telemetry().is_empty() {
                println!("\nTelemetry:");
                for (event, value) in vm.telemetry() {
                    println!("  {event}: {value}");
                }
            }

            // Show memory usage
            println!(
                "\nMemory usage: {} bytes ({:.2}%)",
                vm.memory_usage(),
                vm.memory_usage_percentage()
            );
        }
        Err(e) => {
            eprintln!("Execution error: {e}");
        }
    }
}