Introduce boxing for captured variables
The binder now uses an `UpvalueAnalyzer` to identify local variables that are captured by nested functions. These identified variables are marked with `is_boxed: true` during `DefLocal` node creation. The VM then uses this flag to wrap such variables in a `Value::Cell` (using `Rc<RefCell<_>>`) to ensure they can be mutated across function calls. feat: Introduce boxing for captured variables Add UpvalueAnalyzer to identify variables captured by nested lambdas. Modify Binder to use the analyzer and mark captured local variables for boxing. Update BoundKind::DefLocal to include an `is_boxed` flag. Update VM to box captured variables when they are defined. Add tests for upvalue capture detection.
This commit is contained in:
@@ -17,12 +17,19 @@ pub enum BoundKind {
|
||||
// Variable Access (Resolved)
|
||||
Get(Address),
|
||||
|
||||
// Variable Update (Resolved)
|
||||
// Variable Update (Assignment)
|
||||
Set {
|
||||
addr: Address,
|
||||
value: Box<Node<BoundKind, StaticType>>,
|
||||
},
|
||||
|
||||
// Variable Declaration (Local)
|
||||
DefLocal {
|
||||
slot: u32,
|
||||
value: Box<Node<BoundKind, StaticType>>,
|
||||
is_boxed: bool,
|
||||
},
|
||||
|
||||
If {
|
||||
cond: Box<Node<BoundKind, StaticType>>,
|
||||
then_br: Box<Node<BoundKind, StaticType>>,
|
||||
|
||||
Reference in New Issue
Block a user