From 3e66568ddd178ffe0cd4494a5d6486f0b71accc3 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 30 Aug 2017 22:58:57 -0700 Subject: [PATCH] Converted over Maaru to new schema -partially... --- src/language.rs | 5 ++++- src/maaru_lang/mod.rs | 2 +- src/main.rs | 31 +++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/language.rs b/src/language.rs index c76062a..8bae75e 100644 --- a/src/language.rs +++ b/src/language.rs @@ -98,7 +98,7 @@ impl LanguageInterface for (PL, PL::Evaluator) where PL: Programmin /* below here is new versions of everything */ -#[derive(Debug)] +#[derive(Debug, Default)] pub struct EvalOptions { pub debug_tokens: bool, pub debug_parse: bool, @@ -109,6 +109,9 @@ pub struct EvalOptions { pub trait ProgrammingLanguageInterface { fn evaluate_in_repl(&mut self, input: &str, eval_options: EvalOptions) -> Vec; fn get_language_name(&self) -> String; + fn set_option(&mut self, option: &str, value: bool) -> bool { + false + } } pub trait CompileableLanguage : ProgrammingLanguageInterface { diff --git a/src/maaru_lang/mod.rs b/src/maaru_lang/mod.rs index e29beaa..8ebaffc 100644 --- a/src/maaru_lang/mod.rs +++ b/src/maaru_lang/mod.rs @@ -13,7 +13,7 @@ pub struct NewMaaru<'a> { } impl<'a> NewMaaru<'a> { - fn new() -> NewMaaru<'a> { + pub fn new() -> NewMaaru<'a> { NewMaaru { evaluator: MaaruEvaluator::new(None), } diff --git a/src/main.rs b/src/main.rs index 7bda796..fb76370 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ mod maaru_lang; mod robo_lang; mod language; -use language::{ProgrammingLanguage, LanguageInterface, LLVMCodeString, EvaluationMachine}; +use language::{ProgrammingLanguage, LanguageInterface, ProgrammingLanguageInterface, LLVMCodeString, EvaluationMachine}; mod llvm_wrap; @@ -28,11 +28,14 @@ mod virtual_machine; use virtual_machine::{run_vm, run_assembler}; fn main() { - let languages: Vec> = + let languages: Vec> = vec![ + Box::new(maaru_lang::NewMaaru::new()), + /* Box::new((schala_lang::Schala::new(), schala_lang::SchalaEvaluator::new())), Box::new((maaru_lang::Maaru::new(), maaru_lang::MaaruEvaluator::new(None))), Box::new((robo_lang::Robo::new(), robo_lang::RoboEvaluator::new())), + */ ]; let option_matches = @@ -162,14 +165,14 @@ struct Repl { pub show_tokens: bool, pub show_parse: bool, pub show_llvm_ir: bool, - languages: Vec>, + languages: Vec>, current_language_index: usize, interpreter_directive_sigil: char, reader: LineReader, } impl Repl { - fn new(languages: Vec>, initial_index: usize) -> Repl { + fn new(languages: Vec>, initial_index: usize) -> Repl { let mut reader: linefeed::Reader<_> = linefeed::Reader::new("Metainterpreter").unwrap(); reader.set_prompt(">> "); let i = if initial_index < languages.len() { initial_index } else { 0 }; @@ -210,14 +213,22 @@ impl Repl { } fn input_handler(&mut self, input: &str) -> String { - let ref mut language = self.languages[self.current_language_index]; + let ref mut language = self.languages[self.current_language_index]; - let mut options = language::LanguageInterfaceOptions::default(); - options.show_tokens = self.show_tokens; - options.show_parse = self.show_parse; - options.show_llvm_ir = self.show_llvm_ir; + let mut options = language::EvalOptions::default(); + /* + options.show_tokens = self.show_tokens; + options.show_parse = self.show_parse; + options.show_llvm_ir = self.show_llvm_ir; + */ - language.evaluate_in_repl(input, options) + + let interpretor_output = language.evaluate_in_repl(input, options); + let mut acc = String::new(); + for i in interpretor_output { + acc.push_str(&i) + } + acc } fn handle_interpreter_directive(&mut self, input: &str) -> bool {