Adjust types in TreeWalkEvaluator

This commit is contained in:
Greg Shuflin 2021-11-01 01:21:03 -07:00
parent cd1bb91555
commit 7289504ab7
2 changed files with 3 additions and 12 deletions

View File

@ -40,14 +40,14 @@ impl<'a, 'b> Evaluator<'a, 'b> {
//TODO need to handle breaks, returns, etc.
let mut ret = None;
for stmt in statements.into_iter() {
if let Some(MemoryValue::Primitive(prim)) = self.statement(stmt)? {
if let Some(prim) = self.statement(stmt)? {
ret = Some(prim);
}
}
Ok(if let Some(ret) = ret { ret } else { self.expression(Expression::unit())? })
}
fn statement(&mut self, stmt: Statement) -> EvalResult<Option<MemoryValue>> {
fn statement(&mut self, stmt: Statement) -> EvalResult<Option<Primitive>> {
match stmt {
Statement::Binding { ref id, expr, constant: _ } => {
let evaluated = self.expression(expr)?;
@ -56,7 +56,7 @@ impl<'a, 'b> Evaluator<'a, 'b> {
}
Statement::Expression(expr) => {
let evaluated = self.expression(expr)?;
Ok(Some(evaluated.into()))
Ok(Some(evaluated))
}
Statement::Return(expr) => unimplemented!(),
Statement::Break => unimplemented!(),

View File

@ -88,15 +88,6 @@ impl From<Primitive> for MemoryValue {
}
}
impl MemoryValue {
fn to_repl(&self, type_context: &TypeContext) -> String {
match self {
MemoryValue::Primitive(ref prim) => prim.to_repl(type_context),
MemoryValue::Function(..) => "<function>".to_string(),
}
}
}
#[derive(Debug)]
enum RuntimeValue {
Expression(Expression),