Added a universal pattern match

This commit is contained in:
Emi Simpson 2022-04-24 21:56:40 -04:00
parent b4faad9214
commit ac62dc4e2d
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
3 changed files with 10 additions and 1 deletions

View File

@ -9,6 +9,7 @@ pub enum Pattern {
Literal(Literal), Literal(Literal),
Binding(Identifier), Binding(Identifier),
Variant(Identifier, Vec<Pattern>), Variant(Identifier, Vec<Pattern>),
Universal,
} }
impl Pattern { impl Pattern {
@ -37,6 +38,7 @@ impl Pattern {
} else { } else {
None None
}, },
(_, Pattern::Universal) => Some(LinkedList::new()),
_ => None, _ => None,
} }
} }

View File

@ -104,9 +104,14 @@ impl Expr {
.enumerate() .enumerate()
.map(|(v, expr)| .map(|(v, expr)|
expr.gen_ir(bindings, &self_ident, v as u32, type_context).map(|expr| expr.gen_ir(bindings, &self_ident, v as u32, type_context).map(|expr|
(Pattern::Literal(Literal::Int(v as u64)), expr) if v == 1 {
(Pattern::Literal(Literal::Int(1)), expr)
} else {
(Pattern::Universal, expr)
}
) )
) )
.rev()
.collect() .collect()
} }
}?); }?);

View File

@ -14,6 +14,7 @@ pub enum TightBindingPattern {
Literal(Literal), Literal(Literal),
Symbol(String), Symbol(String),
Group(BindingPattern), Group(BindingPattern),
Universal,
} }
impl TightBindingPattern { impl TightBindingPattern {
@ -28,6 +29,7 @@ impl TightBindingPattern {
)) ))
} }
TightBindingPattern::Group(bp) => bp.gen_ir(scope, parent_ident, index), TightBindingPattern::Group(bp) => bp.gen_ir(scope, parent_ident, index),
TightBindingPattern::Universal => Ok((Vec::new(), Pattern::Universal)),
} }
} }
} }