diff --git a/lykiadb-server/src/engine/error.rs b/lykiadb-server/src/engine/error.rs index 909e9b2..c61fc7e 100644 --- a/lykiadb-server/src/engine/error.rs +++ b/lykiadb-server/src/engine/error.rs @@ -169,7 +169,6 @@ pub fn report_error( } #[cfg(test)] mod tests { - use super::*; use lykiadb_lang::{ diff --git a/lykiadb-server/src/engine/interpreter.rs b/lykiadb-server/src/engine/interpreter.rs index 95fe8c5..625a26d 100644 --- a/lykiadb-server/src/engine/interpreter.rs +++ b/lykiadb-server/src/engine/interpreter.rs @@ -259,10 +259,7 @@ impl Interpreter { &self.interner.get_or_intern(name), ) } else { - self.root_env.read( - name, - &self.interner.get_or_intern(name), - ) + self.root_env.read(name, &self.interner.get_or_intern(name)) } } @@ -370,7 +367,11 @@ impl VisitorMut for Interpreter { evaluated.clone(), ) } else { - self.root_env.assign( &dst.name, self.interner.get_or_intern(&dst.name), evaluated.clone(),) + self.root_env.assign( + &dst.name, + self.interner.get_or_intern(&dst.name), + evaluated.clone(), + ) }; if result.is_err() { return Err(result.err().unwrap()); @@ -587,13 +588,14 @@ impl VisitorMut for Interpreter { } Stmt::Declaration { dst, expr, .. } => { let evaluated = self.visit_expr(expr)?; - self.env.define( - self.interner.get_or_intern(&dst.name), - evaluated.clone(), - ); + self.env + .define(self.interner.get_or_intern(&dst.name), evaluated.clone()); } Stmt::Block { body: stmts, .. } => { - return self.execute_block(stmts, Arc::new(EnvironmentFrame::new(Some(Arc::clone(&self.env))))); + return self.execute_block( + stmts, + Arc::new(EnvironmentFrame::new(Some(Arc::clone(&self.env)))), + ); } Stmt::If { condition, diff --git a/lykiadb-server/src/value/callable.rs b/lykiadb-server/src/value/callable.rs index da9cee5..f2c8e61 100644 --- a/lykiadb-server/src/value/callable.rs +++ b/lykiadb-server/src/value/callable.rs @@ -67,7 +67,7 @@ impl Function { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { Function::Stateful(_) | Function::Lambda { .. } => write!(f, ""), - Function::UserDefined { .. } => write!(f, ""), + Function::UserDefined { .. } => write!(f, ""), } } } diff --git a/lykiadb-server/src/value/environment.rs b/lykiadb-server/src/value/environment.rs index 5472314..0460a21 100644 --- a/lykiadb-server/src/value/environment.rs +++ b/lykiadb-server/src/value/environment.rs @@ -11,7 +11,6 @@ pub struct EnvironmentFrame { pub parent: Option>, } - #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] pub enum EnvironmentError { /*AssignmentToUndefined { @@ -33,7 +32,6 @@ macro_rules! env_ancestor { }}; } - impl From for ExecutionError { fn from(err: EnvironmentError) -> Self { ExecutionError::Environment(err) @@ -42,19 +40,17 @@ impl From for ExecutionError { impl EnvironmentFrame { pub fn new(parent: Option>) -> EnvironmentFrame { - EnvironmentFrame { parent, map: RwLock::new(FxHashMap::default()) } + EnvironmentFrame { + parent, + map: RwLock::new(FxHashMap::default()), + } } pub fn define(&self, name: SymbolU32, value: RV) { self.map.write().unwrap().insert(name, value); } - pub fn assign( - &self, - key: &str, - key_sym: SymbolU32, - value: RV, - ) -> Result { + pub fn assign(&self, key: &str, key_sym: SymbolU32, value: RV) -> Result { if self.map.read().unwrap().contains_key(&key_sym) { self.map.write().unwrap().insert(key_sym, value); return Ok(true); @@ -67,7 +63,7 @@ impl EnvironmentFrame { } .into(), )), - |parent| parent.as_ref().assign(key, key_sym, value) + |parent| parent.as_ref().assign(key, key_sym, value), ) } @@ -94,7 +90,7 @@ impl EnvironmentFrame { .into(), )), |parent| parent.read(key, key_sym), - ) + ); } pub fn read_at( @@ -105,13 +101,18 @@ impl EnvironmentFrame { ) -> Result { env_ancestor!(env, distance) .map - .read().unwrap() - .get(&key_sym).map_or(Err(HaltReason::Error( - EnvironmentError::Other { - message: format!("Variable '{}' was not found", key), - } - .into(), - )), |v| Ok(v.clone())) + .read() + .unwrap() + .get(&key_sym) + .map_or( + Err(HaltReason::Error( + EnvironmentError::Other { + message: format!("Variable '{}' was not found", key), + } + .into(), + )), + |v| Ok(v.clone()), + ) } } @@ -147,9 +148,7 @@ mod test { root.define(interner.get_or_intern("five"), RV::Num(5.0)); let child = super::EnvironmentFrame::new(Some(Arc::new(root))); assert_eq!( - child - .read("five", &interner.get_or_intern("five")) - .unwrap(), + child.read("five", &interner.get_or_intern("five")).unwrap(), RV::Num(5.0) ); } @@ -158,23 +157,22 @@ mod test { fn test_write_to_parent() { let root = Arc::new(super::EnvironmentFrame::new(None)); let mut interner = get_interner(); - + root.define(interner.get_or_intern("five"), RV::Num(5.0)); - + let child = super::EnvironmentFrame::new(Some(root.clone())); - - child.assign("five", interner.get_or_intern("five"), RV::Num(5.1)) + + child + .assign("five", interner.get_or_intern("five"), RV::Num(5.1)) .unwrap(); assert_eq!( - root.read("five", &interner.get_or_intern("five")) - .unwrap(), + root.read("five", &interner.get_or_intern("five")).unwrap(), RV::Num(5.1) ); assert_eq!( - child.read("five", &interner.get_or_intern("five")) - .unwrap(), + child.read("five", &interner.get_or_intern("five")).unwrap(), RV::Num(5.1) ); } @@ -183,9 +181,7 @@ mod test { fn test_read_undefined_variable() { let env = super::EnvironmentFrame::new(None); let mut interner = get_interner(); - assert!(env - .read("five", &interner.get_or_intern("five")) - .is_err()); + assert!(env.read("five", &interner.get_or_intern("five")).is_err()); } #[test]