replace Rc with Arc so that Lamm may be used in an async context

This commit is contained in:
2024-10-22 13:26:48 -04:00
parent 0a40cca6ff
commit d9a576897b
3 changed files with 26 additions and 26 deletions

View File

@@ -5,7 +5,7 @@ use crate::{Type, Object, Value};
use std::collections::HashMap;
use std::fmt::{self, Display};
use std::rc::Rc;
use std::sync::Arc;
#[derive(Clone, Debug, PartialEq)]
pub struct FunctionType(pub Box<Type>, pub Vec<Type>);
@@ -52,8 +52,8 @@ impl Function {
}
pub(crate) fn call(&mut self,
mut globals: HashMap<String, Rc<RefCell<Object>>>,
locals: HashMap<String, Rc<RefCell<Object>>>,
mut globals: HashMap<String, Arc<RefCell<Object>>>,
locals: HashMap<String, Arc<RefCell<Object>>>,
args: Vec<Object>) -> Result<Value, RuntimeError>
{
let mut tree = vec![Ok(*self.body.clone())].into_iter();
@@ -63,11 +63,11 @@ impl Function {
.locals(locals.clone());
for (obj, name) in std::iter::zip(args.into_iter(), self.arg_names.clone().into_iter()) {
exec = exec.add_local(name.clone(), Rc::new(RefCell::new(obj)));
exec = exec.add_local(name.clone(), Arc::new(RefCell::new(obj)));
}
if let Some(name) = self.name().map(|x| x.to_string()) {
exec = exec.add_local(name, Rc::new(RefCell::new(Object::function(self.clone(), g, locals))));
exec = exec.add_local(name, Arc::new(RefCell::new(Object::function(self.clone(), g, locals))));
}
exec.next().unwrap()