Refactor bound node types for clarity
Introduce generic `CompilerPhase` trait to unify different stages of the bound AST. Rename `LocalSlot` to `VirtualId` and introduce `StackOffset` for clearer distinction between compile-time and run-time addressing. Update type aliases and implementations to reflect these changes.
This commit is contained in:
+7
-8
@@ -1,5 +1,4 @@
|
||||
use crate::ast::compiler::bound_nodes::{Address, AnalyzedNode, BoundKind};
|
||||
use crate::ast::compiler::lowering::ExecNode;
|
||||
use crate::ast::compiler::bound_nodes::{Address, AnalyzedNode, BoundKind, ExecNode, StackOffset};
|
||||
use crate::ast::types::{Object, Value};
|
||||
use std::any::Any;
|
||||
use std::cell::RefCell;
|
||||
@@ -335,7 +334,7 @@ impl VM {
|
||||
val.clone()
|
||||
};
|
||||
|
||||
self.set_value(addr.clone(), store_val)?;
|
||||
self.set_value(*addr, store_val)?;
|
||||
// Define always evaluates to the unwrapped value for immediate use.
|
||||
Ok(val)
|
||||
}
|
||||
@@ -351,7 +350,7 @@ impl VM {
|
||||
}
|
||||
Ok(val)
|
||||
}
|
||||
BoundKind::Get { addr, .. } => self.get_value(addr.clone()),
|
||||
BoundKind::Get { addr, .. } => self.get_value(*addr),
|
||||
|
||||
BoundKind::FieldAccessor(k) => Ok(Value::FieldAccessor(k.clone())),
|
||||
|
||||
@@ -399,7 +398,7 @@ impl VM {
|
||||
|
||||
BoundKind::Set { addr, value } => {
|
||||
let val = self.eval_internal(obs, value)?;
|
||||
self.set_value(addr.clone(), val.clone())?;
|
||||
self.set_value(*addr, val.clone())?;
|
||||
Ok(val)
|
||||
}
|
||||
BoundKind::If {
|
||||
@@ -882,7 +881,7 @@ impl VM {
|
||||
}
|
||||
}
|
||||
|
||||
fn capture_upvalue(&mut self, addr: Address) -> Result<Rc<RefCell<Value>>, String> {
|
||||
fn capture_upvalue(&mut self, addr: Address<StackOffset>) -> Result<Rc<RefCell<Value>>, String> {
|
||||
match addr {
|
||||
Address::Local(slot) => {
|
||||
let frame = self.frames.last().ok_or("No call frame")?;
|
||||
@@ -918,7 +917,7 @@ impl VM {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_value(&self, addr: Address) -> Result<Value, String> {
|
||||
fn get_value(&self, addr: Address<StackOffset>) -> Result<Value, String> {
|
||||
match addr {
|
||||
Address::Local(slot) => {
|
||||
let frame = self.frames.last().ok_or("No call frame")?;
|
||||
@@ -958,7 +957,7 @@ impl VM {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_value(&mut self, addr: Address, value: Value) -> Result<(), String> {
|
||||
fn set_value(&mut self, addr: Address<StackOffset>, value: Value) -> Result<(), String> {
|
||||
match addr {
|
||||
Address::Local(slot) => {
|
||||
let frame = self.frames.last().ok_or("No call frame")?;
|
||||
|
||||
Reference in New Issue
Block a user