mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
record update foundations
This commit is contained in:
parent
c8e5acf142
commit
16ec417324
4 changed files with 71 additions and 1 deletions
|
@ -680,12 +680,18 @@ pub enum Expr<'a> {
|
|||
arguments: &'a [Symbol],
|
||||
},
|
||||
Struct(&'a [Symbol]),
|
||||
|
||||
AccessAtIndex {
|
||||
index: u64,
|
||||
field_layouts: &'a [Layout<'a>],
|
||||
structure: Symbol,
|
||||
wrapped: Wrapped,
|
||||
},
|
||||
Update {
|
||||
structure: Symbol,
|
||||
field_layouts: &'a [Layout<'a>],
|
||||
updates: &'a [(u64, Symbol)],
|
||||
},
|
||||
|
||||
Array {
|
||||
elem_layout: Layout<'a>,
|
||||
|
@ -846,6 +852,23 @@ impl<'a> Expr<'a> {
|
|||
.text(format!("Index {} ", index))
|
||||
.append(symbol_to_doc(alloc, *structure)),
|
||||
|
||||
Update {
|
||||
structure, updates, ..
|
||||
} => {
|
||||
let it = updates.iter().map(|(index, symbol)| {
|
||||
alloc
|
||||
.text(format!(".{} => ", index))
|
||||
.append(symbol_to_doc(alloc, *symbol))
|
||||
});
|
||||
|
||||
alloc
|
||||
.text("Update ")
|
||||
.append(symbol_to_doc(alloc, *structure))
|
||||
.append(alloc.text("{ "))
|
||||
.append(alloc.intersperse(it, ", "))
|
||||
.append(alloc.text(" }"))
|
||||
}
|
||||
|
||||
RuntimeErrorFunction(s) => alloc.text(format!("ErrorFunction {}", s)),
|
||||
}
|
||||
}
|
||||
|
@ -2017,7 +2040,12 @@ pub fn with_hole<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
Update { .. } => todo!("record access/accessor/update"),
|
||||
Update {
|
||||
record_var, // Variable,
|
||||
ext_var, // Variable,
|
||||
symbol, // Symbol,
|
||||
updates, // SendMap<Lowercase, Field>,
|
||||
} => todo!("record access/accessor/update"),
|
||||
|
||||
Closure {
|
||||
function_type,
|
||||
|
@ -2965,6 +2993,36 @@ fn substitute_in_expr<'a>(
|
|||
}),
|
||||
None => None,
|
||||
},
|
||||
|
||||
Update {
|
||||
structure,
|
||||
field_layouts,
|
||||
updates,
|
||||
} => {
|
||||
let mut did_change = false;
|
||||
let new_updates = Vec::from_iter_in(
|
||||
updates.iter().map(|(index, s)| match substitute(subs, *s) {
|
||||
None => (*index, *s),
|
||||
Some(s) => {
|
||||
did_change = true;
|
||||
(*index, s)
|
||||
}
|
||||
}),
|
||||
arena,
|
||||
);
|
||||
|
||||
if did_change {
|
||||
let updates = new_updates.into_bump_slice();
|
||||
|
||||
Some(Update {
|
||||
structure: *structure,
|
||||
field_layouts,
|
||||
updates,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue