Refactor multiple if let bindings

Replaces nested `if let` statements with sequential `if let` bindings,
improving readability. This change is applied to `Dumper::log_bound`,
`LambdaCollector::visit_bound`, `Environment::call_object_method`, and
`Environment::call_lambda`.
This commit is contained in:
Michael Schimmel
2026-02-19 23:56:50 +01:00
parent 1331aabbe1
commit 30cd73aa63
3 changed files with 16 additions and 16 deletions
+3 -3
View File
@@ -39,8 +39,9 @@ impl Dumper {
BoundKind::Constant(v) => { BoundKind::Constant(v) => {
self.log(&format!("Constant: {}", v), node); self.log(&format!("Constant: {}", v), node);
// Introspect Closure AST if possible // Introspect Closure AST if possible
if let Value::Object(obj) = v { if let Value::Object(obj) = v
if let Some(closure) = obj.as_any().downcast_ref::<Closure>() { && let Some(closure) = obj.as_any().downcast_ref::<Closure>()
{
self.indent += 1; self.indent += 1;
self.write_indent(); self.write_indent();
self.output.push_str("--- Specialized Body ---\n"); self.output.push_str("--- Specialized Body ---\n");
@@ -58,7 +59,6 @@ impl Dumper {
self.output.push('\n'); self.output.push('\n');
} }
self.indent -= 1; self.indent -= 1;
}
} }
}, },
BoundKind::Get { addr, name } => self.log(&format!("Get: {} ({:?})", name.name, addr), node), BoundKind::Get { addr, name } => self.log(&format!("Get: {} ({:?})", name.name, addr), node),
+4 -4
View File
@@ -32,10 +32,10 @@ impl<'a> LambdaCollector<'a> {
BoundKind::Set { addr, value } => { BoundKind::Set { addr, value } => {
// Also track assignments to globals if they hold lambdas. // Also track assignments to globals if they hold lambdas.
if let Address::Global(global_index) = addr { if let Address::Global(global_index) = addr
if let BoundKind::Lambda { .. } = &value.kind { && let BoundKind::Lambda { .. } = &value.kind
self.registry.insert(*global_index, (**value).clone()); {
} self.registry.insert(*global_index, (**value).clone());
} }
self.visit(value); self.visit(value);
} }
+9 -9
View File
@@ -233,11 +233,11 @@ impl Environment {
let mut vm = VM::new(self.global_values.clone()); let mut vm = VM::new(self.global_values.clone());
let result = vm.run(node)?; let result = vm.run(node)?;
if let Value::Object(obj) = &result { if let Value::Object(obj) = &result
if let Some(closure) = obj.as_any().downcast_ref::<crate::ast::vm::Closure>() { && let Some(closure) = obj.as_any().downcast_ref::<crate::ast::vm::Closure>()
// Execute the script body {
return vm.run(&closure.function_node); // Execute the script body
} return vm.run(&closure.function_node);
} }
Ok(result) Ok(result)
@@ -267,10 +267,10 @@ impl Environment {
let mut result = vm.run_with_observer(&mut observer, &linked); let mut result = vm.run_with_observer(&mut observer, &linked);
// If result is a closure (script entry), execute the body too // If result is a closure (script entry), execute the body too
if let Ok(Value::Object(obj)) = &result { if let Ok(Value::Object(obj)) = &result
if let Some(closure) = obj.as_any().downcast_ref::<crate::ast::vm::Closure>() { && let Some(closure) = obj.as_any().downcast_ref::<crate::ast::vm::Closure>()
result = vm.run_with_observer(&mut observer, &closure.function_node); {
} result = vm.run_with_observer(&mut observer, &closure.function_node);
} }
Ok((result, observer.logs)) Ok((result, observer.logs))