diff --git a/src/interpreter/interpretable.rs b/src/interpreter/interpretable.rs index 296d8d0..dd04150 100644 --- a/src/interpreter/interpretable.rs +++ b/src/interpreter/interpretable.rs @@ -7,6 +7,22 @@ use crate::{ tokens::{Token, TokenType}, }; +/// Evaluate an interpretable, returning its value. +pub fn evaluate(err_hdl: &mut ErrorHandler, ast: &dyn Interpretable) -> Option { + let env = Rc::new(RefCell::new(Environment::default())); + match ast.interprete(&env) { + Ok(v) => Some(v.result()), + Err(e) => { + e.report(err_hdl); + None + } + } +} + +/* ------- * + * HELPERS * + * ------- */ + /// Interpreter flow control, which may be either a value, a loop break or a /// loop continuation. #[derive(Debug)] @@ -53,18 +69,6 @@ pub trait Interpretable { fn interprete(&self, environment: &EnvironmentRef) -> InterpreterResult; } -/// Evaluate an interpretable, returning its value. -pub fn evaluate(err_hdl: &mut ErrorHandler, ast: &dyn Interpretable) -> Option { - let env = Rc::new(RefCell::new(Environment::default())); - match ast.interprete(&env) { - Ok(v) => Some(v.result()), - Err(e) => { - e.report(err_hdl); - None - } - } -} - /* ----------------------------- * * INTERPRETER FOR PROGRAM NODES * * ----------------------------- */