From 2a0737fd45484c1feee8692d1abe8614698349dd Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 12 Aug 2024 10:29:06 -0400 Subject: [PATCH] Add test; Clean up context --- dust-lang/src/context.rs | 13 ------------- dust-lang/src/vm.rs | 7 +++++++ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/dust-lang/src/context.rs b/dust-lang/src/context.rs index 13368fa..3a5b41c 100644 --- a/dust-lang/src/context.rs +++ b/dust-lang/src/context.rs @@ -10,23 +10,18 @@ use crate::{Identifier, Span, Type, Value}; #[derive(Debug, Clone)] pub struct Context { variables: Arc>>, - is_garbage_collected_to: Arc>, } impl Context { pub fn new() -> Self { Self { variables: Arc::new(RwLock::new(HashMap::new())), - is_garbage_collected_to: Arc::new(RwLock::new(0)), } } pub fn with_variables_from(other: &Self) -> Self { Self { variables: Arc::new(RwLock::new(other.variables.read().unwrap().clone())), - is_garbage_collected_to: Arc::new(RwLock::new( - *other.is_garbage_collected_to.read().unwrap(), - )), } } @@ -88,12 +83,6 @@ impl Context { pub fn collect_garbage(&self, current_position: usize) { log::trace!("Collecting garbage up to {current_position}"); - let mut is_garbage_collected_to = self.is_garbage_collected_to.write().unwrap(); - - if current_position < *is_garbage_collected_to { - return; - } - let mut variables = self.variables.write().unwrap(); variables.retain(|identifier, (_, last_used)| { @@ -106,8 +95,6 @@ impl Context { !should_drop }); variables.shrink_to_fit(); - - *is_garbage_collected_to = current_position; } pub fn update_last_position(&self, identifier: &Identifier, position: Span) -> bool { diff --git a/dust-lang/src/vm.rs b/dust-lang/src/vm.rs index 52c7acd..df690ac 100644 --- a/dust-lang/src/vm.rs +++ b/dust-lang/src/vm.rs @@ -693,6 +693,13 @@ impl Display for VmError { mod tests { use super::*; + #[test] + fn range() { + let input = "1..5"; + + assert_eq!(run(input), Ok(Some(Value::range(1..5)))); + } + #[test] fn negate_expression() { let input = "x = -42; -x";