Refactor: Simplify type checking context
The type checker's fallback logic for non-lambda nodes was unnecessarily complex. This commit simplifies it by directly checking the node within a new, basic type context. Additionally, the environment now explicitly wraps non-lambda AST nodes in a lambda before type checking, ensuring consistent handling. This aligns the type checking process for all top-level expressions.
This commit is contained in:
+19
-13
@@ -447,22 +447,28 @@ impl VM {
|
||||
}
|
||||
|
||||
let lambda_val = self.eval_internal(obs, lambda)?;
|
||||
let lambda_obj = if let Value::Object(obj) = lambda_val {
|
||||
obj
|
||||
} else {
|
||||
return Err("Pipe lambda must be a function/closure".to_string());
|
||||
};
|
||||
|
||||
// Create the persistent execution closure for the PipeStream
|
||||
let mut pipe_vm = crate::ast::vm::VM::new(self.globals.clone());
|
||||
let my_closure = lambda_obj.clone();
|
||||
let executor: Box<crate::ast::types::PipeFn> =
|
||||
Box::new(move |args: &[Value]| -> Value {
|
||||
match pipe_vm.run_with_args(my_closure.clone(), args) {
|
||||
Ok(res) => res,
|
||||
Err(e) => panic!("Pipeline lambda execution failed: {}", e),
|
||||
}
|
||||
});
|
||||
|
||||
let executor: Box<crate::ast::types::PipeFn> = match lambda_val {
|
||||
Value::Object(obj) => {
|
||||
let my_closure = obj.clone();
|
||||
Box::new(move |args: &[Value]| -> Value {
|
||||
match pipe_vm.run_with_args(my_closure.clone(), args) {
|
||||
Ok(res) => res,
|
||||
Err(e) => panic!("Pipeline lambda execution failed: {}", e),
|
||||
}
|
||||
})
|
||||
}
|
||||
Value::Function(func) => {
|
||||
let my_func = func.clone();
|
||||
Box::new(move |args: &[Value]| -> Value {
|
||||
(my_func.func)(args)
|
||||
})
|
||||
}
|
||||
_ => return Err("Pipe lambda must be a function/closure".to_string()),
|
||||
};
|
||||
|
||||
// Delegate to the RTL Factory for specialized buffer instantiation
|
||||
let node =
|
||||
|
||||
Reference in New Issue
Block a user