glyph-runtime 0.0.1

Runtime execution engine for the Glyph programming language
Documentation
#!/usr/bin/env cargo +nightly -Zscript
//! ```cargo
//! [dependencies]
//! glyph-runtime = { path = ".." }
//! glyph-types = { path = "../../glyph-types" }
//! ```

use glyph_runtime::compiler::compile_and_run;

fn main() {
    // Simple arithmetic
    let source = r#"
@program(name="arithmetic_demo", version="1.0")

def main():
    let x = 10
    let y = 20
    return x + y
"#;

    match compile_and_run(source) {
        Ok(result) => println!("Result: {result:?}"),
        Err(e) => eprintln!("Error: {e}"),
    }

    // Function calls
    let source = r#"
@program(name="function_demo", version="1.0")

def greet(name: str) -> str:
    return "Hello, " + name

def main():
    return greet("World")
"#;

    match compile_and_run(source) {
        Ok(result) => println!("Result: {result:?}"),
        Err(e) => eprintln!("Error: {e}"),
    }

    // List operations
    let source = r#"
@program(name="list_demo", version="1.0")

def sum_list(numbers: list) -> int:
    let total = 0
    # Note: loops not yet implemented
    return total

def main():
    let nums = [1, 2, 3, 4, 5]
    return nums
"#;

    match compile_and_run(source) {
        Ok(result) => println!("Result: {result:?}"),
        Err(e) => eprintln!("Error: {e}"),
    }
}