Interpreter - Function re-ordering
This commit is contained in:
parent
b1d0db5ea4
commit
3b5778ff47
1 changed files with 16 additions and 12 deletions
|
@ -7,6 +7,22 @@ use crate::{
|
||||||
tokens::{Token, TokenType},
|
tokens::{Token, TokenType},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Evaluate an interpretable, returning its value.
|
||||||
|
pub fn evaluate(err_hdl: &mut ErrorHandler, ast: &dyn Interpretable) -> Option<Value> {
|
||||||
|
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
|
/// Interpreter flow control, which may be either a value, a loop break or a
|
||||||
/// loop continuation.
|
/// loop continuation.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -53,18 +69,6 @@ pub trait Interpretable {
|
||||||
fn interprete(&self, environment: &EnvironmentRef) -> InterpreterResult;
|
fn interprete(&self, environment: &EnvironmentRef) -> InterpreterResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate an interpretable, returning its value.
|
|
||||||
pub fn evaluate(err_hdl: &mut ErrorHandler, ast: &dyn Interpretable) -> Option<Value> {
|
|
||||||
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 *
|
* INTERPRETER FOR PROGRAM NODES *
|
||||||
* ----------------------------- */
|
* ----------------------------- */
|
||||||
|
|
Loading…
Reference in a new issue