dict patterns prolly work? one-level nested patterns work

This commit is contained in:
Scott Richmond 2025-05-25 19:14:34 -04:00
parent 45d2e7e742
commit 04c96c9edb
3 changed files with 4 additions and 3 deletions

View File

@ -559,7 +559,7 @@ impl Compiler {
let before_load_dict_idx = self.len();
self.emit_byte(0xff);
let mut jump_idxes = vec![];
let dict_stack_pos = self.stack_depth;
let dict_stack_pos = self.stack_depth - 1;
for pair in pairs {
let (PairPattern(key, pattern), _) = pair else {
unreachable!()

View File

@ -74,8 +74,8 @@ pub fn run(src: &'static str) {
pub fn main() {
env::set_var("RUST_BACKTRACE", "1");
let src = "
let #{:a x} = #{:a 1}
x
let #{a, :b #{c}} = #{:a 1, :b #{:c 3}}
[a, c]
";
run(src);
}

View File

@ -313,6 +313,7 @@ impl<'a> Vm<'a> {
};
let value = dict.get(&key).unwrap_or(&Value::Nil);
self.push(value.clone());
self.ip += 2;
}
MatchDict => {
let idx = self.stack.len() - self.match_depth as usize - 1;