replace Rc with Arc so that Lamm may be used in an async context
This commit is contained in:
18
src/lib.rs
18
src/lib.rs
@@ -13,7 +13,7 @@ use std::fmt::Display;
|
||||
use std::io::BufRead;
|
||||
use std::fmt;
|
||||
use std::iter::Peekable;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -103,13 +103,13 @@ enum Cache {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct Object {
|
||||
locals: HashMap<String, Rc<RefCell<Object>>>,
|
||||
globals: HashMap<String, Rc<RefCell<Object>>>,
|
||||
locals: HashMap<String, Arc<RefCell<Object>>>,
|
||||
globals: HashMap<String, Arc<RefCell<Object>>>,
|
||||
value: Cache,
|
||||
}
|
||||
|
||||
impl Object {
|
||||
pub fn variable(tree: ParseTree, globals: HashMap<String, Rc<RefCell<Object>>>, locals: HashMap<String, Rc<RefCell<Object>>>) -> Self {
|
||||
pub fn variable(tree: ParseTree, globals: HashMap<String, Arc<RefCell<Object>>>, locals: HashMap<String, Arc<RefCell<Object>>>) -> Self {
|
||||
Self {
|
||||
locals,
|
||||
globals,
|
||||
@@ -117,7 +117,7 @@ impl Object {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn value(v: Value, globals: HashMap<String, Rc<RefCell<Object>>>, locals: HashMap<String, Rc<RefCell<Object>>>) -> Self {
|
||||
pub fn value(v: Value, globals: HashMap<String, Arc<RefCell<Object>>>, locals: HashMap<String, Arc<RefCell<Object>>>) -> Self {
|
||||
Self {
|
||||
locals,
|
||||
globals,
|
||||
@@ -125,7 +125,7 @@ impl Object {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn function(func: Function, globals: HashMap<String, Rc<RefCell<Object>>>, locals: HashMap<String, Rc<RefCell<Object>>>) -> Self {
|
||||
pub fn function(func: Function, globals: HashMap<String, Arc<RefCell<Object>>>, locals: HashMap<String, Arc<RefCell<Object>>>) -> Self {
|
||||
Self {
|
||||
locals,
|
||||
globals,
|
||||
@@ -152,11 +152,11 @@ impl Object {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn locals(&self) -> HashMap<String, Rc<RefCell<Object>>> {
|
||||
pub fn locals(&self) -> HashMap<String, Arc<RefCell<Object>>> {
|
||||
self.locals.clone()
|
||||
}
|
||||
|
||||
pub fn globals(&self) -> HashMap<String, Rc<RefCell<Object>>> {
|
||||
pub fn globals(&self) -> HashMap<String, Arc<RefCell<Object>>> {
|
||||
self.globals.clone()
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ impl Object {
|
||||
pub struct Runtime<'a, R: BufRead> {
|
||||
tokenizer: Peekable<Tokenizer<R>>,
|
||||
global_types: HashMap<String, Type>,
|
||||
globals: HashMap<String, Rc<RefCell<Object>>>,
|
||||
globals: HashMap<String, Arc<RefCell<Object>>>,
|
||||
parser: Option<Parser<'a, Tokenizer<R>>>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user