From 5bfd79669edd3b0d80da5134ecbf3baa584ccf0f Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sat, 11 Dec 2021 04:14:26 -0800 Subject: [PATCH] Rename environment -> memory --- schala-lang/src/tree_walk_eval/evaluator.rs | 26 ++++++++++----------- schala-lang/src/tree_walk_eval/mod.rs | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/schala-lang/src/tree_walk_eval/evaluator.rs b/schala-lang/src/tree_walk_eval/evaluator.rs index 91a4442..7ddb59b 100644 --- a/schala-lang/src/tree_walk_eval/evaluator.rs +++ b/schala-lang/src/tree_walk_eval/evaluator.rs @@ -38,7 +38,7 @@ impl<'a, 'b> Evaluator<'a, 'b> { let mut acc = vec![]; for (def_id, function) in reduced.functions.into_iter() { let mem = (&def_id).into(); - self.state.environments.insert(mem, MemoryValue::Function(function)); + self.state.memory.insert(mem, MemoryValue::Function(function)); } for statement in reduced.entrypoint.into_iter() { @@ -78,7 +78,7 @@ impl<'a, 'b> Evaluator<'a, 'b> { match stmt { Statement::Binding { ref id, expr, constant: _ } => { let evaluated = self.expression(expr)?; - self.state.environments.insert(id.into(), evaluated.into()); + self.state.memory.insert(id.into(), evaluated.into()); Ok(StatementOutput::Nothing) } Statement::Expression(expr) => { @@ -119,7 +119,7 @@ impl<'a, 'b> Evaluator<'a, 'b> { Expression::Lookup(kind) => match kind { Lookup::Function(ref id) => { let mem = id.into(); - match self.state.environments.lookup(&mem) { + match self.state.memory.lookup(&mem) { // This just checks that the function exists in "memory" by ID, we don't // actually retrieve it until `apply_function()` Some(MemoryValue::Function(_)) => Primitive::Callable(Callable::UserDefined(*id)), @@ -128,21 +128,21 @@ impl<'a, 'b> Evaluator<'a, 'b> { } Lookup::Param(n) => { let mem = n.into(); - match self.state.environments.lookup(&mem) { + match self.state.memory.lookup(&mem) { Some(MemoryValue::Primitive(prim)) => prim.clone(), e => return Err(format!("Param lookup error, got {:?}", e).into()), } } Lookup::SelfParam => { let mem = Memory::self_param(); - match self.state.environments.lookup(&mem) { + match self.state.memory.lookup(&mem) { Some(MemoryValue::Primitive(prim)) => prim.clone(), e => return Err(format!("SelfParam lookup error, got {:?}", e).into()), } } Lookup::LocalVar(ref id) | Lookup::GlobalVar(ref id) => { let mem = id.into(); - match self.state.environments.lookup(&mem) { + match self.state.memory.lookup(&mem) { Some(MemoryValue::Primitive(expr)) => expr.clone(), _ => return Err( @@ -155,7 +155,7 @@ impl<'a, 'b> Evaluator<'a, 'b> { let mem = lval.into(); let evaluated = self.expression(rval)?; println!("Inserting {:?} into {:?}", evaluated, mem); - self.state.environments.insert(mem, MemoryValue::Primitive(evaluated)); + self.state.memory.insert(mem, MemoryValue::Primitive(evaluated)); Primitive::unit() } Expression::Call { box f, args } => self.call_expression(f, args, None)?, @@ -311,9 +311,9 @@ impl<'a, 'b> Evaluator<'a, 'b> { let cond = self.expression(cond)?; for alt in alternatives.into_iter() { - let mut new_scope = self.state.environments.new_scope(None); + let mut new_scope = self.state.memory.new_scope(None); if matches(&cond, &alt.pattern, &mut new_scope) { - let mut new_state = State { environments: new_scope }; + let mut new_state = State { memory: new_scope }; let mut evaluator = Evaluator::new(&mut new_state, self.type_context); let output = evaluator.block(alt.item); self.early_returning = evaluator.early_returning; @@ -338,7 +338,7 @@ impl<'a, 'b> Evaluator<'a, 'b> { Callable::Builtin(builtin) => self.apply_builtin(builtin, args), Callable::UserDefined(def_id) => { let mem = (&def_id).into(); - match self.state.environments.lookup(&mem) { + match self.state.memory.lookup(&mem) { Some(MemoryValue::Function(FunctionDefinition { body })) => { let body = body.clone(); //TODO ideally this clone would not happen self.apply_function(body, args, self_expr) @@ -496,17 +496,17 @@ impl<'a, 'b> Evaluator<'a, 'b> { evaluated_args.push(self.expression(arg)?); } - let mut frame_state = State { environments: self.state.environments.new_scope(None) }; + let mut frame_state = State { memory: self.state.memory.new_scope(None) }; let mut evaluator = Evaluator::new(&mut frame_state, self.type_context); if let Some(evaled) = self_expr { let mem = Memory::self_param(); - evaluator.state.environments.insert(mem, MemoryValue::Primitive(evaled)); + evaluator.state.memory.insert(mem, MemoryValue::Primitive(evaled)); } for (n, evaled) in evaluated_args.into_iter().enumerate() { let n = n as u8; let mem = n.into(); - evaluator.state.environments.insert(mem, MemoryValue::Primitive(evaled)); + evaluator.state.memory.insert(mem, MemoryValue::Primitive(evaled)); } evaluator.block(body) } diff --git a/schala-lang/src/tree_walk_eval/mod.rs b/schala-lang/src/tree_walk_eval/mod.rs index c575d51..0a4ca22 100644 --- a/schala-lang/src/tree_walk_eval/mod.rs +++ b/schala-lang/src/tree_walk_eval/mod.rs @@ -14,7 +14,7 @@ type EvalResult = Result; #[derive(Debug)] pub struct State<'a> { - environments: ScopeStack<'a, Memory, MemoryValue>, + memory: ScopeStack<'a, Memory, MemoryValue>, } //TODO - eh, I dunno, maybe it doesn't matter exactly how memory works in the tree-walking @@ -158,7 +158,7 @@ impl From for Primitive { impl<'a> State<'a> { pub fn new() -> Self { - Self { environments: ScopeStack::new(Some("global".to_string())) } + Self { memory: ScopeStack::new(Some("global".to_string())) } } pub fn evaluate(