mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
implement mono / lowering for tuples
This commit is contained in:
parent
65f8bb3d0d
commit
5a6be05ead
42 changed files with 1773 additions and 290 deletions
|
@ -81,6 +81,8 @@ enum IndexCtor<'a> {
|
|||
Opaque,
|
||||
/// Index a record type. The arguments are the types of the record fields.
|
||||
Record(&'a [Lowercase]),
|
||||
/// Index a tuple type.
|
||||
Tuple,
|
||||
/// Index a guard constructor. The arguments are a faux guard pattern, and then the real
|
||||
/// pattern being guarded. E.g. `A B if g` becomes Guard { [True, (A B)] }.
|
||||
Guard,
|
||||
|
@ -113,6 +115,7 @@ impl<'a> IndexCtor<'a> {
|
|||
}
|
||||
RenderAs::Opaque => Self::Opaque,
|
||||
RenderAs::Record(fields) => Self::Record(fields),
|
||||
RenderAs::Tuple => Self::Tuple,
|
||||
RenderAs::Guard => Self::Guard,
|
||||
}
|
||||
}
|
||||
|
@ -366,6 +369,30 @@ fn sketch_pattern(pattern: &crate::pattern::Pattern) -> SketchedPattern {
|
|||
SP::KnownCtor(union, tag_id, patterns)
|
||||
}
|
||||
|
||||
TupleDestructure { destructs, .. } => {
|
||||
let tag_id = TagId(0);
|
||||
let mut patterns = std::vec::Vec::with_capacity(destructs.len());
|
||||
|
||||
for Loc {
|
||||
value: destruct,
|
||||
region: _,
|
||||
} in destructs
|
||||
{
|
||||
patterns.push(sketch_pattern(&destruct.typ.1.value));
|
||||
}
|
||||
|
||||
let union = Union {
|
||||
render_as: RenderAs::Tuple,
|
||||
alternatives: vec![Ctor {
|
||||
name: CtorName::Tag(TagName("#Record".into())),
|
||||
tag_id,
|
||||
arity: destructs.len(),
|
||||
}],
|
||||
};
|
||||
|
||||
SP::KnownCtor(union, tag_id, patterns)
|
||||
}
|
||||
|
||||
List {
|
||||
patterns,
|
||||
list_var: _,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue