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:
+7
-7
@@ -1,6 +1,6 @@
|
||||
use std::iter::Peekable;
|
||||
use std::str::Chars;
|
||||
use std::sync::Arc;
|
||||
use std::rc::Rc;
|
||||
use crate::ast::types::SourceLocation;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -9,11 +9,11 @@ pub enum TokenKind {
|
||||
LeftBracket, RightBracket,
|
||||
LeftBrace, RightBrace,
|
||||
Quote, Backtick, Tilde, At,
|
||||
Identifier(Arc<str>),
|
||||
Keyword(Arc<str>),
|
||||
Identifier(Rc<str>),
|
||||
Keyword(Rc<str>),
|
||||
Integer(i64),
|
||||
Float(f64),
|
||||
String(Arc<str>),
|
||||
String(Rc<str>),
|
||||
EOF,
|
||||
}
|
||||
|
||||
@@ -65,9 +65,9 @@ impl<'a> Lexer<'a> {
|
||||
'@' => TokenKind::At,
|
||||
':' => {
|
||||
let id = self.read_while(|c| !c.is_whitespace() && !"()[]{}\"'`~@;".contains(c));
|
||||
TokenKind::Keyword(Arc::from(id))
|
||||
TokenKind::Keyword(Rc::from(id))
|
||||
}
|
||||
'"' => TokenKind::String(Arc::from(self.read_string()?)),
|
||||
'"' => TokenKind::String(Rc::from(self.read_string()?)),
|
||||
c if c.is_ascii_digit() || (c == '-' && self.input.peek().is_some_and(|p| p.is_ascii_digit())) => {
|
||||
let mut num_str = String::from(c);
|
||||
while let Some(&next) = self.peek() {
|
||||
@@ -88,7 +88,7 @@ impl<'a> Lexer<'a> {
|
||||
c if is_ident_start(c) => {
|
||||
let mut id = String::from(c);
|
||||
id.push_str(&self.read_while(is_ident_char));
|
||||
TokenKind::Identifier(Arc::from(id))
|
||||
TokenKind::Identifier(Rc::from(id))
|
||||
}
|
||||
_ => return Err(format!("Unexpected character: {} at {}:{}", char, self.line, self.col - 1)),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user