pseudocode splatted dict algo

This commit is contained in:
Scott Richmond 2025-06-19 12:44:29 -04:00
parent 35d7d3b1c8
commit 4dd4b8ff7e
2 changed files with 6 additions and 1 deletions

View File

@ -848,6 +848,11 @@ impl<'a> Compiler<'a> {
self.match_depth = match_depth + members.len();
}
DictPattern(pairs) => {
// here's an algorithm for dealing with splatted dicts
// check len to see it's at least as long as the pattern
// then, match against all the values
// then push the dict itself as last value
// and then emit an opcode and constant/keyword to OMIT that key from the dict
self.emit_op(Op::MatchDict);
self.emit_byte(pairs.len());
let before_load_dict_idx = self.stub_jump(Op::JumpIfNoMatch);

View File

@ -75,7 +75,7 @@ pub fn run(src: &'static str) {
pub fn main() {
env::set_var("RUST_BACKTRACE", "1");
let src = "
let (...y) = (1, 2)
let (...y) = (1, 2, 3, 4, 5)
y
";
run(src);