add as patterns
This commit is contained in:
parent
f1d19b73db
commit
938033ab5d
21
src/main.rs
21
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 {
|
||||
|
|
10
src/vm.rs
10
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)) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user