Simplify tuple flattening and destructuring
The `flatten_tuple` function was unnecessarily recursive. It can now simply return the elements of the tuple directly. The VM's destructuring logic has been updated to handle nested destructuring more efficiently. A new integration test case for multi-level destructuring has been added.
This commit is contained in:
+9
-1
@@ -416,7 +416,15 @@ impl VM {
|
||||
{
|
||||
self.stack.extend(arg_vals);
|
||||
} else {
|
||||
self.unpack(&closure.parameter_node, &arg_vals, &mut 0)?;
|
||||
// Map each parameter pattern to the provided arguments
|
||||
if let BoundKind::Tuple { elements } = &closure.parameter_node.kind {
|
||||
let mut offset = 0;
|
||||
for el in elements {
|
||||
self.unpack(el, &arg_vals, &mut offset)?;
|
||||
}
|
||||
} else {
|
||||
self.unpack(&closure.parameter_node, &arg_vals, &mut 0)?;
|
||||
}
|
||||
}
|
||||
let result = self.eval_internal(obs, &closure.exec_node);
|
||||
self.frames.pop();
|
||||
|
||||
Reference in New Issue
Block a user