Added a universal pattern match
This commit is contained in:
parent
b4faad9214
commit
ac62dc4e2d
|
@ -9,6 +9,7 @@ pub enum Pattern {
|
|||
Literal(Literal),
|
||||
Binding(Identifier),
|
||||
Variant(Identifier, Vec<Pattern>),
|
||||
Universal,
|
||||
}
|
||||
|
||||
impl Pattern {
|
||||
|
@ -37,6 +38,7 @@ impl Pattern {
|
|||
} else {
|
||||
None
|
||||
},
|
||||
(_, Pattern::Universal) => Some(LinkedList::new()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,9 +104,14 @@ impl Expr {
|
|||
.enumerate()
|
||||
.map(|(v, 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()
|
||||
}
|
||||
}?);
|
||||
|
|
|
@ -14,6 +14,7 @@ pub enum TightBindingPattern {
|
|||
Literal(Literal),
|
||||
Symbol(String),
|
||||
Group(BindingPattern),
|
||||
Universal,
|
||||
}
|
||||
|
||||
impl TightBindingPattern {
|
||||
|
@ -28,6 +29,7 @@ impl TightBindingPattern {
|
|||
))
|
||||
}
|
||||
TightBindingPattern::Group(bp) => bp.gen_ir(scope, parent_ident, index),
|
||||
TightBindingPattern::Universal => Ok((Vec::new(), Pattern::Universal)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue