From ec8ae05018d6d53a642ddf2efd682d0c692bde27 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 25 Oct 2021 19:09:05 -0700 Subject: [PATCH] Rename RuntimeValue -> MemoryValue --- .../language/src/tree_walk_eval/mod.rs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/schala-lang/language/src/tree_walk_eval/mod.rs b/schala-lang/language/src/tree_walk_eval/mod.rs index da2e5e1..d0f376a 100644 --- a/schala-lang/language/src/tree_walk_eval/mod.rs +++ b/schala-lang/language/src/tree_walk_eval/mod.rs @@ -14,7 +14,7 @@ type EvalResult = Result; #[derive(Debug)] pub struct State<'a> { - environments: ScopeStack<'a, Memory, RuntimeValue>, + environments: ScopeStack<'a, Memory, MemoryValue>, } //TODO - eh, I dunno, maybe it doesn't matter exactly how memory works in the tree-walking @@ -79,12 +79,12 @@ fn paren_wrapped(terms: impl Iterator) -> String { } #[derive(Debug)] -enum RuntimeValue { +enum MemoryValue { Function(FunctionDefinition), Primitive(Primitive), } -impl From for RuntimeValue { +impl From for MemoryValue { fn from(prim: Primitive) -> Self { Self::Primitive(prim) } @@ -118,11 +118,11 @@ impl Primitive { } } -impl RuntimeValue { +impl MemoryValue { fn to_repl(&self) -> String { match self { - RuntimeValue::Primitive(ref prim) => prim.to_repl(), - RuntimeValue::Function(..) => "".to_string(), + MemoryValue::Primitive(ref prim) => prim.to_repl(), + MemoryValue::Function(..) => "".to_string(), } } } @@ -182,7 +182,7 @@ impl<'a> State<'a> { for (def_id, function) in reduced.functions.into_iter() { let mem = (&def_id).into(); - self.environments.insert(mem, RuntimeValue::Function(function)); + self.environments.insert(mem, MemoryValue::Function(function)); } for statement in reduced.entrypoint.into_iter() { @@ -204,7 +204,7 @@ impl<'a> State<'a> { //TODO need to handle breaks, returns, etc. let mut ret = None; for stmt in statements.into_iter() { - if let Some(RuntimeValue::Primitive(prim)) = self.statement(stmt)? { + if let Some(MemoryValue::Primitive(prim)) = self.statement(stmt)? { ret = Some(prim); } } @@ -215,7 +215,7 @@ impl<'a> State<'a> { }) } - fn statement(&mut self, stmt: Statement) -> EvalResult> { + fn statement(&mut self, stmt: Statement) -> EvalResult> { match stmt { Statement::Binding { ref id, expr, constant: _ } => { println!("eval() binding id: {}", id); @@ -240,21 +240,21 @@ impl<'a> State<'a> { match self.environments.lookup(&mem) { // This just checks that the function exists in "memory" by ID, we don't // actually retrieve it until `apply_function()` - Some(RuntimeValue::Function(_)) => Primitive::Callable(Callable::UserDefined(id.clone())), + Some(MemoryValue::Function(_)) => Primitive::Callable(Callable::UserDefined(id.clone())), x => return Err(format!("Function not found for id: {} : {:?}", id, x).into()), } }, Lookup::Param(n) => { let mem = n.into(); match self.environments.lookup(&mem) { - Some(RuntimeValue::Primitive(prim)) => prim.clone(), + Some(MemoryValue::Primitive(prim)) => prim.clone(), e => return Err(format!("Param lookup error, got {:?}", e).into()), } }, Lookup::LocalVar(ref id) | Lookup::GlobalVar(ref id) => { let mem = id.into(); match self.environments.lookup(&mem) { - Some(RuntimeValue::Primitive(expr)) => expr.clone(), + Some(MemoryValue::Primitive(expr)) => expr.clone(), _ => return Err(format!("Nothing found for local/gloval variable lookup {}", id).into()), } }, @@ -262,7 +262,7 @@ impl<'a> State<'a> { Expression::Assign { ref lval, box rval } => { let mem = lval.into(); let evaluated = self.expression(rval)?; - self.environments.insert(mem, RuntimeValue::Primitive(evaluated)); + self.environments.insert(mem, MemoryValue::Primitive(evaluated)); Primitive::unit() }, Expression::Call { box f, args } => self.call_expression(f, args)?, @@ -281,7 +281,7 @@ impl<'a> State<'a> { Callable::UserDefined(def_id) => { let mem = (&def_id).into(); match self.environments.lookup(&mem) { - Some(RuntimeValue::Function(FunctionDefinition { body })) => { + Some(MemoryValue::Function(FunctionDefinition { body })) => { let body = body.clone(); //TODO ideally this clone would not happen self.apply_function(body, args) }, @@ -408,7 +408,7 @@ impl<'a> State<'a> { for (n, evaled) in evaluated_args.into_iter().enumerate() { let n = n as u8; let mem = n.into(); - frame_state.environments.insert(mem, RuntimeValue::Primitive(evaled)); + frame_state.environments.insert(mem, MemoryValue::Primitive(evaled)); } frame_state.block(body)