Refactor global variable access in VM and optimizer
Replaces `Rc<RefCell<Vec<Value>>>` with a new `GlobalStore` struct for accessing global variables. This provides a more structured way to manage global values and allows for future optimizations like sharing immutable RTL portions across environments. The `GlobalStore` also includes an `rtl_len` field to distinguish between RTL and user global slots, enabling debug-time checks for writes to immutable RTL slots.
This commit is contained in:
@@ -2,15 +2,15 @@ use crate::ast::nodes::{
|
||||
Address, AnalyzedNode, IdentifierBinding, Node, NodeKind, NodeMetrics,
|
||||
};
|
||||
use crate::ast::types::{Purity, RecordLayout, StaticType, Value};
|
||||
use std::cell::RefCell;
|
||||
use crate::ast::vm::GlobalStore;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Folder<'a> {
|
||||
pub globals: &'a Option<Rc<RefCell<Vec<Value>>>>,
|
||||
pub globals: &'a Option<GlobalStore>,
|
||||
}
|
||||
|
||||
impl<'a> Folder<'a> {
|
||||
pub fn new(globals: &'a Option<Rc<RefCell<Vec<Value>>>>) -> Self {
|
||||
pub fn new(globals: &'a Option<GlobalStore>) -> Self {
|
||||
Self { globals }
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ impl<'a> Folder<'a> {
|
||||
NodeKind::Identifier {
|
||||
binding: IdentifierBinding::Reference(Address::Global(idx)),
|
||||
..
|
||||
} => self.globals.as_ref()?.borrow().get(idx.0 as usize)?.clone(),
|
||||
} => self.globals.as_ref()?.get(idx.0 as usize)?,
|
||||
NodeKind::Constant(val) => val.clone(),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user