generic_identity/
generic_identity.rs1use keleusma::compiler::compile;
14use keleusma::lexer::tokenize;
15use keleusma::parser::parse;
16use keleusma::vm::{DEFAULT_ARENA_CAPACITY, Vm, VmState};
17use keleusma::{Arena, Value};
18
19fn main() {
20 let src = r#"
21 fn id<T>(x: T) -> T { x }
22 fn main() -> i64 { id(42) }
23 "#;
24 let tokens = tokenize(src).expect("lex");
25 let program = parse(&tokens).expect("parse");
26 let module = compile(&program).expect("compile");
27 let arena = Arena::with_capacity(DEFAULT_ARENA_CAPACITY);
28 let mut vm = Vm::new(module, &arena).expect("verify");
29 match vm.call(&[]) {
30 Ok(VmState::Finished(Value::Int(n))) => {
31 println!("id(42) = {}", n);
32 assert_eq!(n, 42);
33 println!("generic identity executed end to end");
34 }
35 other => panic!("unexpected: {:?}", other),
36 }
37}