From a8cafa8c6442c46dc77ac02c36f52a425c4eb237 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 22 Jan 2016 02:20:12 -0800 Subject: [PATCH] Move Evaluator state into interpreter state --- src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index a7112c6..febceaf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,11 @@ fn main() { source_file.read_to_string(&mut buffer).unwrap(); panic!("Not implemented yet"); } else { - let initial_state = InterpreterState { show_tokens: false, show_parse: false }; + let initial_state = InterpreterState { + show_tokens: false, + show_parse: false, + evaluator: Evaluator::new(), + }; REPL::with_prompt_and_state(Box::new(repl_handler), ">> ", initial_state) .run(); } @@ -35,6 +39,7 @@ fn main() { struct InterpreterState { show_tokens: bool, show_parse: bool, + evaluator: Evaluator, } impl ReplState for InterpreterState { @@ -76,8 +81,7 @@ fn repl_handler(input: &str, state: &mut InterpreterState) -> String { println!("AST: {:?}", ast); } - let mut evaluator = Evaluator::new(); - let mut output: Vec = evaluator.run(ast); + let mut output: Vec = state.evaluator.run(ast); //for now only handle last output output.pop().unwrap_or("".to_string())