From bb3f85dd166c5092b672b962c6654f077c973af2 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 30 Aug 2017 23:36:13 -0700 Subject: [PATCH] Getting rid of old code for maaru --- src/maaru_lang/mod.rs | 38 -------------------------------------- src/main.rs | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 46 deletions(-) diff --git a/src/maaru_lang/mod.rs b/src/maaru_lang/mod.rs index 8ebaffc..1d2286a 100644 --- a/src/maaru_lang/mod.rs +++ b/src/maaru_lang/mod.rs @@ -68,41 +68,3 @@ impl<'a> Maaru<'a> { Maaru { marker: PhantomData } } } - -impl<'a> ProgrammingLanguage for Maaru<'a> { - type Token = tokenizer::Token; - type AST = parser::AST; - type Evaluator = MaaruEvaluator<'a>; - - fn name() -> String { - "Maaru".to_string() - } - - fn tokenize(input: &str) -> Result, TokenError> { - tokenizer::tokenize(input) - } - fn parse(input: Vec) -> Result { - parser::parse(&input, &[]).map_err(|x| ParseError { msg: x.msg }) - } - fn evaluate(ast: Self::AST, evaluator: &mut Self::Evaluator) -> Vec { - evaluator.run(ast) - } - fn compile(ast: Self::AST) -> LLVMCodeString { - compilation::compile_ast(ast) - } -} - -impl<'a> EvaluationMachine for MaaruEvaluator<'a> { - fn set_option(&mut self, option: &str, value: bool) -> bool { - if option == "trace_evaluation" { - self.trace_evaluation = value; - return true; - } - - false - } - - fn new() -> MaaruEvaluator<'a> { - MaaruEvaluator::new(None) - } -} diff --git a/src/main.rs b/src/main.rs index fb76370..f47899a 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, ProgrammingLanguageInterface, LLVMCodeString, EvaluationMachine}; +use language::{ProgrammingLanguage, LanguageInterface, ProgrammingLanguageInterface, EvalOptions, LLVMCodeString, EvaluationMachine}; mod llvm_wrap; @@ -87,8 +87,8 @@ fn main() { repl.run(); } [_, ref filename, _..] => { - let language = maaru_lang::Maaru::new(); - run_noninteractive(filename, &language, trace_evaluation, compile); + let mut language = maaru_lang::NewMaaru::new(); + run_noninteractive(filename, &mut language, trace_evaluation, compile); } }; } @@ -123,12 +123,17 @@ fn program_options() -> getopts::Options { options } +fn run_noninteractive(filename: &str, language: &mut T, trace_evaluation: bool, compile: bool) { + let mut source_file = File::open(&Path::new(filename)).unwrap(); + let mut buffer = String::new(); + source_file.read_to_string(&mut buffer).unwrap(); -fn run_noninteractive<'a, T: ProgrammingLanguage>(filename: &str, _language: &T, trace_evaluation: bool, compile: bool) { - let mut source_file = File::open(&Path::new(filename)).unwrap(); - let mut buffer = String::new(); - source_file.read_to_string(&mut buffer).unwrap(); - + let options = EvalOptions::default(); + let interpretor_output = language.evaluate_in_repl(&buffer, options); + for line in interpretor_output { + println!("{}", line); + } + /* let tokens = match T::tokenize(&buffer) { Ok(t) => t, Err(e) => { @@ -158,6 +163,7 @@ fn run_noninteractive<'a, T: ProgrammingLanguage>(filename: &str, _language: &T, println!("{}", r); } } + */ } type LineReader = linefeed::Reader;