Converted over Maaru to new schema

-partially...
This commit is contained in:
greg 2017-08-30 22:58:57 -07:00
parent 3abe299361
commit 3e66568ddd
3 changed files with 26 additions and 12 deletions

View File

@ -98,7 +98,7 @@ impl<PL, T, A, E> LanguageInterface for (PL, PL::Evaluator) where PL: Programmin
/* below here is new versions of everything */ /* below here is new versions of everything */
#[derive(Debug)] #[derive(Debug, Default)]
pub struct EvalOptions { pub struct EvalOptions {
pub debug_tokens: bool, pub debug_tokens: bool,
pub debug_parse: bool, pub debug_parse: bool,
@ -109,6 +109,9 @@ pub struct EvalOptions {
pub trait ProgrammingLanguageInterface { pub trait ProgrammingLanguageInterface {
fn evaluate_in_repl(&mut self, input: &str, eval_options: EvalOptions) -> Vec<String>; fn evaluate_in_repl(&mut self, input: &str, eval_options: EvalOptions) -> Vec<String>;
fn get_language_name(&self) -> String; fn get_language_name(&self) -> String;
fn set_option(&mut self, option: &str, value: bool) -> bool {
false
}
} }
pub trait CompileableLanguage : ProgrammingLanguageInterface { pub trait CompileableLanguage : ProgrammingLanguageInterface {

View File

@ -13,7 +13,7 @@ pub struct NewMaaru<'a> {
} }
impl<'a> NewMaaru<'a> { impl<'a> NewMaaru<'a> {
fn new() -> NewMaaru<'a> { pub fn new() -> NewMaaru<'a> {
NewMaaru { NewMaaru {
evaluator: MaaruEvaluator::new(None), evaluator: MaaruEvaluator::new(None),
} }

View File

@ -20,7 +20,7 @@ mod maaru_lang;
mod robo_lang; mod robo_lang;
mod language; mod language;
use language::{ProgrammingLanguage, LanguageInterface, LLVMCodeString, EvaluationMachine}; use language::{ProgrammingLanguage, LanguageInterface, ProgrammingLanguageInterface, LLVMCodeString, EvaluationMachine};
mod llvm_wrap; mod llvm_wrap;
@ -28,11 +28,14 @@ mod virtual_machine;
use virtual_machine::{run_vm, run_assembler}; use virtual_machine::{run_vm, run_assembler};
fn main() { fn main() {
let languages: Vec<Box<LanguageInterface>> = let languages: Vec<Box<ProgrammingLanguageInterface>> =
vec![ vec![
Box::new(maaru_lang::NewMaaru::new()),
/*
Box::new((schala_lang::Schala::new(), schala_lang::SchalaEvaluator::new())), Box::new((schala_lang::Schala::new(), schala_lang::SchalaEvaluator::new())),
Box::new((maaru_lang::Maaru::new(), maaru_lang::MaaruEvaluator::new(None))), Box::new((maaru_lang::Maaru::new(), maaru_lang::MaaruEvaluator::new(None))),
Box::new((robo_lang::Robo::new(), robo_lang::RoboEvaluator::new())), Box::new((robo_lang::Robo::new(), robo_lang::RoboEvaluator::new())),
*/
]; ];
let option_matches = let option_matches =
@ -162,14 +165,14 @@ struct Repl {
pub show_tokens: bool, pub show_tokens: bool,
pub show_parse: bool, pub show_parse: bool,
pub show_llvm_ir: bool, pub show_llvm_ir: bool,
languages: Vec<Box<LanguageInterface>>, languages: Vec<Box<ProgrammingLanguageInterface>>,
current_language_index: usize, current_language_index: usize,
interpreter_directive_sigil: char, interpreter_directive_sigil: char,
reader: LineReader, reader: LineReader,
} }
impl Repl { impl Repl {
fn new(languages: Vec<Box<LanguageInterface>>, initial_index: usize) -> Repl { fn new(languages: Vec<Box<ProgrammingLanguageInterface>>, initial_index: usize) -> Repl {
let mut reader: linefeed::Reader<_> = linefeed::Reader::new("Metainterpreter").unwrap(); let mut reader: linefeed::Reader<_> = linefeed::Reader::new("Metainterpreter").unwrap();
reader.set_prompt(">> "); reader.set_prompt(">> ");
let i = if initial_index < languages.len() { initial_index } else { 0 }; 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 { 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(); let mut options = language::EvalOptions::default();
options.show_tokens = self.show_tokens; /*
options.show_parse = self.show_parse; options.show_tokens = self.show_tokens;
options.show_llvm_ir = self.show_llvm_ir; 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 { fn handle_interpreter_directive(&mut self, input: &str) -> bool {