Added a universal pattern match
This commit is contained in:
parent
b4faad9214
commit
ac62dc4e2d
|
@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
}?);
|
}?);
|
||||||
|
|
|
@ -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)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue