More work on new trait structure
This commit is contained in:
parent
626b17cbd2
commit
3abe299361
@ -97,22 +97,20 @@ 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, PartialEq)]
|
|
||||||
pub struct EvalStage {
|
|
||||||
index: u8,
|
|
||||||
name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct EvalOptions {
|
pub struct EvalOptions {
|
||||||
debug_stages: Vec<EvalStage>,
|
pub debug_tokens: bool,
|
||||||
|
pub debug_parse: bool,
|
||||||
|
pub debug_type: bool,
|
||||||
|
pub debug_eval: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ProgrammingLanguageInterface {
|
pub trait ProgrammingLanguageInterface {
|
||||||
fn evaluate_in_repl(&mut self, input: &str, eval_options: EvalOptions);
|
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 get_stages(&self) -> Vec<u8>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CompileableLanguage : ProgrammingLanguageInterface {
|
pub trait CompileableLanguage : ProgrammingLanguageInterface {
|
||||||
fn compile(&mut self);
|
fn compile(&mut self) -> LLVMCodeString;
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,64 @@ pub mod parser;
|
|||||||
pub mod eval;
|
pub mod eval;
|
||||||
pub mod compilation;
|
pub mod compilation;
|
||||||
|
|
||||||
use language::{ProgrammingLanguage, EvaluationMachine, ParseError, TokenError, LLVMCodeString};
|
use language::{ProgrammingLanguageInterface, EvalOptions, ProgrammingLanguage, EvaluationMachine, ParseError, TokenError, LLVMCodeString};
|
||||||
|
|
||||||
pub use self::eval::Evaluator as MaaruEvaluator;
|
pub use self::eval::Evaluator as MaaruEvaluator;
|
||||||
|
|
||||||
|
pub struct NewMaaru<'a> {
|
||||||
|
evaluator: MaaruEvaluator<'a>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> NewMaaru<'a> {
|
||||||
|
fn new() -> NewMaaru<'a> {
|
||||||
|
NewMaaru {
|
||||||
|
evaluator: MaaruEvaluator::new(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> ProgrammingLanguageInterface for NewMaaru<'a> {
|
||||||
|
fn get_language_name(&self) -> String {
|
||||||
|
"Maaru".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn evaluate_in_repl(&mut self, input: &str, options: EvalOptions) -> Vec<String> {
|
||||||
|
let mut output = vec![];
|
||||||
|
let tokens = match tokenizer::tokenize(input) {
|
||||||
|
Ok(tokens) => {
|
||||||
|
if options.debug_tokens {
|
||||||
|
output.push(format!("{:?}", tokens));
|
||||||
|
}
|
||||||
|
tokens
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
let msg = format!("Tokenization error: {:?}\n", err.msg);
|
||||||
|
output.push(msg);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let ast = match parser::parse(&tokens, &[]) {
|
||||||
|
Ok(ast) => {
|
||||||
|
if options.debug_parse {
|
||||||
|
output.push(format!("{:?}", ast));
|
||||||
|
}
|
||||||
|
ast
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
let msg = format!("Parse error: {:?}\n", err.msg);
|
||||||
|
output.push(msg);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let evaluation_output = self.evaluator.run(ast);
|
||||||
|
output.extend(evaluation_output);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Maaru<'a> { marker: PhantomData<&'a ()> }
|
pub struct Maaru<'a> { marker: PhantomData<&'a ()> }
|
||||||
impl<'a> Maaru<'a> {
|
impl<'a> Maaru<'a> {
|
||||||
pub fn new() -> Maaru <'a> {
|
pub fn new() -> Maaru <'a> {
|
||||||
|
Loading…
Reference in New Issue
Block a user