From 902c85ccd744f2f221a1d453fc5e5d02cfeb927c Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 1 Feb 2017 19:04:52 -0800 Subject: [PATCH] Fully implemented state If I make the LanguageInterface trait over a pair of language and evaluator, then it works :) --- src/language.rs | 6 +++--- src/main.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/language.rs b/src/language.rs index 930529b..b07c107 100644 --- a/src/language.rs +++ b/src/language.rs @@ -46,7 +46,7 @@ pub trait LanguageInterface { fn evaluate_in_repl(&mut self, input: &str, options: LanguageInterfaceOptions) -> String; } -impl LanguageInterface for PL where PL: ProgrammingLanguage, T: Debug, A: Debug, E: EvaluationMachine { +impl LanguageInterface for (PL, PL::Evaluator) where PL: ProgrammingLanguage, T: Debug, A: Debug, E: EvaluationMachine { fn evaluate_in_repl(&mut self, input: &str, options: LanguageInterfaceOptions) -> String { let mut output = String::new(); @@ -79,8 +79,8 @@ impl LanguageInterface for PL where PL: ProgrammingLanguage = PL::evaluate(ast, &mut evaluator); + let ref mut evaluator = self.1; + let mut full_output: Vec = PL::evaluate(ast, evaluator); output.push_str(&full_output.pop().unwrap_or("".to_string())); } output diff --git a/src/main.rs b/src/main.rs index 9c4badf..dc34928 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,7 +116,7 @@ impl<'a> Repl<'a> { show_tokens: false, show_parse: false, show_llvm_ir: show_llvm, - languages: vec![Box::new(Schala::new())], + languages: vec![Box::new((Schala::new(), SchalaEvaluator::new(None)))], evaluator: evaluator, interpreter_directive_sigil: '.', reader: reader,