Refactor: Use Rc/RefCell for shared mutable state

This commit replaces `Arc<Mutex<T>>` with `Rc<RefCell<T>>` for managing
shared mutable state within the AST and VM. This change is primarily an
internal refactoring to leverage Rust's standard library more
effectively for single-threaded scenarios, improving performance by
avoiding the overhead of mutexes.

The following types and their usage have been updated:
- `Environment.global_names` and `Environment.global_values`
- `Binder.globals`
- `bound_nodes::BoundKind::Lambda.body` (now `Rc<Node>`)
- `ast::types::NodeIdentity` (now `Rc<NodeIdentity>`)
- `ast::types::Value::List`, `Value::Record`, `Value::Function`,
  `Value::Object`, `Value::Cell`
- `ast::nodes::Scope` and `ast::nodes::Context`
- `ast::vm::Closure.function_node` and `Closure.upvalues`
- `ast::vm::VM.globals`

This change does not alter the external behavior of the library but
streamlines internal data management.
This commit is contained in:
Michael Schimmel
2026-02-17 13:00:25 +01:00
parent ce166f39e3
commit d55422272b
9 changed files with 112 additions and 148 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::rc::Rc;
use crate::ast::types::{Value, StaticType};
use crate::ast::nodes::Node;
@@ -39,7 +39,7 @@ pub enum BoundKind {
param_count: u32,
// The list of variables captured from enclosing scopes
upvalues: Vec<Address>,
body: Arc<Node<BoundKind, StaticType>>,
body: Rc<Node<BoundKind, StaticType>>,
},
Call {