Rename RuntimeValue -> MemoryValue
This commit is contained in:
parent
e4af5beb1c
commit
ec8ae05018
@ -14,7 +14,7 @@ type EvalResult<T> = Result<T, RuntimeError>;
|
||||
|
||||
#[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<Item=String>) -> String {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum RuntimeValue {
|
||||
enum MemoryValue {
|
||||
Function(FunctionDefinition),
|
||||
Primitive(Primitive),
|
||||
}
|
||||
|
||||
impl From<Primitive> for RuntimeValue {
|
||||
impl From<Primitive> 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(..) => "<function>".to_string(),
|
||||
MemoryValue::Primitive(ref prim) => prim.to_repl(),
|
||||
MemoryValue::Function(..) => "<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<Option<RuntimeValue>> {
|
||||
fn statement(&mut self, stmt: Statement) -> EvalResult<Option<MemoryValue>> {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user