Refactor Destructure to handle assignments
Renames `DefDestructure` to `Destructure` to better reflect its use in both definitions and assignments. Introduces `bind_assign_pattern` to handle assignment destructuring in the binder. Adds `test_assign_destructuring` to verify assignment destructuring functionality.
This commit is contained in:
+7
-2
@@ -281,7 +281,7 @@ impl VM {
|
||||
globals[idx] = val.clone();
|
||||
Ok(val)
|
||||
}
|
||||
BoundKind::DefDestructure { pattern, value } => {
|
||||
BoundKind::Destructure { pattern, value } => {
|
||||
let val = self.eval_internal(obs, value)?;
|
||||
let mut offset = 0;
|
||||
|
||||
@@ -289,7 +289,7 @@ impl VM {
|
||||
if let Some(vals) = val.as_slice() {
|
||||
self.unpack(pattern, vals, &mut offset)?;
|
||||
} else {
|
||||
self.unpack(pattern, &[val.clone()], &mut offset)?;
|
||||
self.unpack(pattern, std::slice::from_ref(&val), &mut offset)?;
|
||||
}
|
||||
Ok(val)
|
||||
}
|
||||
@@ -704,6 +704,11 @@ impl VM {
|
||||
globals[idx] = val;
|
||||
Ok(())
|
||||
}
|
||||
BoundKind::Set { addr, .. } => {
|
||||
let val = values.get(*offset).cloned().unwrap_or(Value::Void);
|
||||
*offset += 1;
|
||||
self.set_value(*addr, val)
|
||||
}
|
||||
BoundKind::Tuple { elements } => {
|
||||
if let Some(sub_values) = values.get(*offset).and_then(|v| v.as_slice()) {
|
||||
*offset += 1;
|
||||
|
||||
Reference in New Issue
Block a user