mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
start of destructure patterns
This commit is contained in:
parent
94267cf7ab
commit
e81daf25cb
4 changed files with 54 additions and 3 deletions
|
@ -873,7 +873,15 @@ pub(crate) fn sort_can_defs_new(
|
|||
);
|
||||
}
|
||||
},
|
||||
_ => todo!("{:?}", &def.loc_pattern.value),
|
||||
_ => {
|
||||
declarations.push_destructure_def(
|
||||
def.loc_pattern,
|
||||
def.loc_expr,
|
||||
def.expr_var,
|
||||
def.annotation,
|
||||
def.pattern_vars.into_iter().collect(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2047,6 +2047,34 @@ impl Declarations {
|
|||
index
|
||||
}
|
||||
|
||||
/// Any def with a weird pattern
|
||||
pub fn push_destructure_def(
|
||||
&mut self,
|
||||
loc_pattern: Loc<Pattern>,
|
||||
loc_expr: Loc<Expr>,
|
||||
expr_var: Variable,
|
||||
annotation: Option<Annotation>,
|
||||
pattern_vars: VecMap<Symbol, Variable>,
|
||||
) -> usize {
|
||||
let index = self.declarations.len();
|
||||
|
||||
let destruct_def = DestructureDef {
|
||||
loc_pattern,
|
||||
pattern_vars,
|
||||
};
|
||||
|
||||
let destructure_def_index = Index::push_new(&mut self.destructs, destruct_def);
|
||||
|
||||
self.declarations.push(DeclarationTag::Destructure(destructure_def_index));
|
||||
self.variables.push(expr_var);
|
||||
self.symbols.push(Loc::at_zero(Symbol::ATTR_ATTR));
|
||||
self.annotations.push(annotation);
|
||||
|
||||
self.expressions.push(loc_expr);
|
||||
|
||||
index
|
||||
}
|
||||
|
||||
pub fn push_def(&mut self, def: Def) {
|
||||
match def.loc_pattern.value {
|
||||
Pattern::Identifier(symbol) => match def.loc_expr.value {
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::effect_module::HostedGeneratedFunctions;
|
|||
use crate::env::Env;
|
||||
use crate::expr::{ClosureData, Declarations, Expr, Output};
|
||||
use crate::operator::desugar_def;
|
||||
use crate::pattern::Pattern;
|
||||
use crate::pattern::{BindingsFromPattern, Pattern};
|
||||
use crate::scope::Scope;
|
||||
use bumpalo::Bump;
|
||||
use roc_collections::{MutMap, SendMap, VecSet};
|
||||
|
@ -526,7 +526,13 @@ pub fn canonicalize_module_defs<'a>(
|
|||
|
||||
index += 1;
|
||||
}
|
||||
Destructure(_) => todo!(),
|
||||
Destructure(d_index) => {
|
||||
let destruct_def = &declarations.destructs[d_index.index()];
|
||||
|
||||
for (symbol, _) in BindingsFromPattern::new(&destruct_def.loc_pattern) {
|
||||
exposed_but_not_defined.remove(&symbol);
|
||||
}
|
||||
}
|
||||
MutualRecursion(_) => todo!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,15 @@ impl<K: PartialEq, V> VecMap<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<K: Ord, V> std::iter::FromIterator<(K, V)> for VecMap<K, V> {
|
||||
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
|
||||
let mut this = Self::default();
|
||||
this.extend(iter);
|
||||
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Ord, V> Extend<(K, V)> for VecMap<K, V> {
|
||||
#[inline(always)]
|
||||
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue