diff --git a/src/main.rs b/src/main.rs index 0c12a63..b00a73f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,28 @@ use crate::base::*; pub fn main() { let src = " +fn fancy_add { + () -> 0 + (n as :number) -> n + (x as :number, y as :number) -> add (x, y) +} +fn fancy_sub { + () -> 0 + (n as :number) -> n + (x as :number, y as :number) -> sub (x, y) +} + +fn fib { + (1) -> 1 + (2) -> 1 + (n) -> fancy_add( + fib (fancy_sub (n, 1)) + fib (fancy_sub (n, 2)) + ) +} + +fib (30) "; let (tokens, lex_errs) = lexer().parse(src).into_output_errors(); if lex_errs.len() > 0 { diff --git a/src/vm.rs b/src/vm.rs index 1bf1967..aa94b2f 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -67,9 +67,15 @@ pub fn match_pattern<'src, 'a>( ctx.push((w, val.clone())); Some(ctx) } - (Pattern::As(word, type_kw), value) => { + (Pattern::As(word, type_str), value) => { let ludus_type = value.ludus_type(); - None + let type_kw = Value::Keyword(type_str); + if type_kw == ludus_type { + ctx.push((word, value.clone())); + Some(ctx) + } else { + None + } } // todo: add splats to these match clauses (Pattern::Tuple(x), Value::Tuple(y)) => {