Refactor closure instantiation and inlining
This commit makes several changes related to how closures are handled: - **Dumper:** Removes redundant introspection of closure ASTs, as this is no longer relevant. - **Optimizer:** Updates `try_inline` to accept `ExecNode` for parameters and adds a check to ensure the `function_node` is a `Lambda` before attempting inlining. - **Environment:** Simplifies closure creation by passing an `ExecNode` for parameters and ensuring the correct `stack_size` is used. - **VM:** Adjusts `Closure` to store an `ExecNode` for parameters and updates `VM::unpack` to accept an `ExecNode`.
This commit is contained in:
+6
-7
@@ -1,6 +1,5 @@
|
||||
use crate::ast::compiler::bound_nodes::{Address, AnalyzedNode, BoundKind};
|
||||
use crate::ast::compiler::lowering::ExecNode;
|
||||
use crate::ast::compiler::bound_nodes::Node;
|
||||
use crate::ast::types::{Object, Value};
|
||||
use std::any::Any;
|
||||
use std::cell::RefCell;
|
||||
@@ -8,8 +7,8 @@ use std::rc::Rc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Closure {
|
||||
/// The analyzed parameter pattern.
|
||||
pub parameter_node: Rc<AnalyzedNode>,
|
||||
/// The executable parameter pattern.
|
||||
pub parameter_node: Rc<ExecNode>,
|
||||
/// The analyzed body (before TCO).
|
||||
pub function_node: Rc<AnalyzedNode>,
|
||||
/// The executable node (after TCO).
|
||||
@@ -23,7 +22,7 @@ pub struct Closure {
|
||||
impl Closure {
|
||||
#[inline]
|
||||
pub fn new(
|
||||
params: Rc<AnalyzedNode>,
|
||||
params: Rc<ExecNode>,
|
||||
body: Rc<AnalyzedNode>,
|
||||
exec: Rc<ExecNode>,
|
||||
upvalues: Vec<Rc<RefCell<Value>>>,
|
||||
@@ -512,7 +511,7 @@ impl VM {
|
||||
}
|
||||
let stack_size = node.ty.stack_size;
|
||||
let closure = Closure::new(
|
||||
params.ty.original.clone(),
|
||||
params.clone(),
|
||||
body.ty.original.clone(),
|
||||
body.clone(),
|
||||
captured,
|
||||
@@ -1026,9 +1025,9 @@ impl VM {
|
||||
}
|
||||
}
|
||||
|
||||
fn unpack<T>(
|
||||
fn unpack(
|
||||
&mut self,
|
||||
pattern: &Node<T>,
|
||||
pattern: &ExecNode,
|
||||
values: &[Value],
|
||||
offset: &mut usize,
|
||||
) -> Result<(), String> {
|
||||
|
||||
Reference in New Issue
Block a user