From 55e1600b97ed6a12fbfc1b8bf9b6b159635b5039 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 31 Aug 2017 18:05:10 -0700 Subject: [PATCH] Kill old trait --- src/language.rs | 83 -------------------------------------------- src/main.rs | 20 +++++------ src/robo_lang/mod.rs | 4 +-- 3 files changed, 10 insertions(+), 97 deletions(-) diff --git a/src/language.rs b/src/language.rs index 90ff0b4..d378da7 100644 --- a/src/language.rs +++ b/src/language.rs @@ -18,86 +18,6 @@ pub struct ParseError { pub struct LLVMCodeString(pub String); -pub trait ProgrammingLanguage { - type Token: Debug; - type AST: Debug; - type Evaluator: EvaluationMachine; - - fn name() -> String; - fn tokenize(input: &str) -> Result, TokenError>; - fn parse(input: Vec) -> Result; - fn evaluate(ast: Self::AST, evaluator: &mut Self::Evaluator) -> Vec; - fn compile(ast: Self::AST) -> LLVMCodeString; -} - -pub trait EvaluationMachine { - fn set_option(&mut self, option: &str, value: bool) -> bool; - fn new() -> Self; -} - -#[derive(Default)] -pub struct LanguageInterfaceOptions { - pub show_parse: bool, - pub show_tokens: bool, - pub show_llvm_ir: bool, -} - -pub trait LanguageInterface { - fn evaluate_in_repl(&mut self, input: &str, options: LanguageInterfaceOptions) -> String; - fn get_language_name(&self) -> String; - fn set_option(&mut self, option: &str, value: bool) -> bool; -} - -impl LanguageInterface for (PL, PL::Evaluator) where PL: ProgrammingLanguage, T: Debug, A: Debug, E: EvaluationMachine { - fn set_option(&mut self, option: &str, value: bool) -> bool { - self.1.set_option(option, value) - } - fn get_language_name(&self) -> String { - PL::name() - } - fn evaluate_in_repl(&mut self, input: &str, options: LanguageInterfaceOptions) -> String { - let mut output = String::new(); - - let tokens = match PL::tokenize(input) { - Ok(tokens) => tokens, - Err(err) => { - output.push_str(&format!("Tokenization error: {}\n", err.msg)); - return output; - } - }; - - if options.show_tokens { - output.push_str(&format!("Tokens: {:?}\n", tokens)); - } - - let ast = match PL::parse(tokens) { - Ok(ast) => ast, - Err(err) => { - output.push_str(&format!("Parse error: {:?}\n", err.msg)); - return output; - } - }; - - if options.show_parse { - output.push_str(&format!("AST: {:?}\n", ast)); - } - - if options.show_llvm_ir { - let LLVMCodeString(s) = PL::compile(ast); - output.push_str(&s); - } else { - // for now only handle last output - 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 - } -} - -/* below here is new versions of everything */ - - #[derive(Debug, Default)] pub struct EvalOptions { pub debug_tokens: bool, @@ -109,9 +29,6 @@ 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/main.rs b/src/main.rs index 021c770..dbe2ac0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,15 +29,11 @@ use virtual_machine::{run_vm, run_assembler}; fn main() { let languages: Vec> = - vec![ - Box::new(schala_lang::Schala::new()), - Box::new(maaru_lang::Maaru::new()), - Box::new(robo_lang::Robo::new()), - /* - Box::new((schala_lang::Schala::new(), schala_lang::SchalaEvaluator::new())), - Box::new((maaru_lang::Maaru::new(), maaru_lang::MaaruEvaluator::new(None))), - */ - ]; + vec![ + Box::new(schala_lang::Schala::new()), + Box::new(maaru_lang::Maaru::new()), + Box::new(robo_lang::Robo::new()), + ]; let option_matches = match program_options().parse(std::env::args()) { @@ -126,7 +122,7 @@ fn program_options() -> getopts::Options { options } -fn run_noninteractive(filename: &str, language: &mut T, options: EvalOptions, compile: bool) { +fn run_noninteractive(filename: &str, language: &mut T, _options: EvalOptions, 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(); @@ -306,8 +302,8 @@ impl Repl { Some(&"tokens") => self.show_tokens = show, Some(&"parse") => self.show_parse = show, Some(&"eval") => { - let ref mut language = self.languages[self.current_language_index]; - language.set_option("trace_evaluation", show); + //let ref mut language = self.languages[self.current_language_index]; + //language.set_option("trace_evaluation", show); }, Some(&"llvm") => self.show_llvm_ir = show, Some(e) => { diff --git a/src/robo_lang/mod.rs b/src/robo_lang/mod.rs index 2fa9a0d..14a9c7a 100644 --- a/src/robo_lang/mod.rs +++ b/src/robo_lang/mod.rs @@ -1,7 +1,7 @@ extern crate itertools; use self::itertools::Itertools; -use language::{ProgrammingLanguageInterface, EvalOptions, ProgrammingLanguage, ParseError, TokenError, LLVMCodeString}; +use language::{ProgrammingLanguageInterface, EvalOptions, ParseError, TokenError, LLVMCodeString}; pub struct Robo { } @@ -137,7 +137,7 @@ impl ProgrammingLanguageInterface for Robo { "Robo".to_string() } - fn evaluate_in_repl(&mut self, input: &str, eval_options: EvalOptions) -> Vec { + fn evaluate_in_repl(&mut self, input: &str, _eval_options: EvalOptions) -> Vec { let mut output = vec!(); let tokens = match tokenize(input) { Ok(tokens) => tokens,