2017-01-31 00:53:31 -08:00
|
|
|
use ::std::marker::PhantomData;
|
2017-01-23 11:27:11 -08:00
|
|
|
pub mod tokenizer;
|
|
|
|
pub mod parser;
|
|
|
|
pub mod eval;
|
|
|
|
pub mod compilation;
|
|
|
|
|
2017-01-24 20:09:14 -08:00
|
|
|
use language::{ProgrammingLanguage, EvaluationMachine, ParseError, TokenError, LLVMCodeString};
|
|
|
|
|
|
|
|
pub use self::eval::Evaluator as SchalaEvaluator;
|
2017-01-23 11:27:11 -08:00
|
|
|
|
2017-01-31 00:53:31 -08:00
|
|
|
pub struct Schala<'a> { marker: PhantomData<&'a ()> }
|
|
|
|
impl<'a> Schala<'a> {
|
|
|
|
pub fn new() -> Schala<'a> {
|
|
|
|
Schala { marker: PhantomData }
|
|
|
|
}
|
|
|
|
}
|
2017-01-23 11:27:11 -08:00
|
|
|
|
2017-01-31 00:53:31 -08:00
|
|
|
impl<'a> ProgrammingLanguage for Schala<'a> {
|
2017-01-23 11:27:11 -08:00
|
|
|
type Token = tokenizer::Token;
|
|
|
|
type AST = parser::AST;
|
2017-01-31 00:53:31 -08:00
|
|
|
type Evaluator = SchalaEvaluator<'a>;
|
2017-01-23 11:27:11 -08:00
|
|
|
|
|
|
|
fn tokenize(input: &str) -> Result<Vec<Self::Token>, TokenError> {
|
2017-01-23 19:45:26 -08:00
|
|
|
tokenizer::tokenize(input)
|
2017-01-23 11:27:11 -08:00
|
|
|
}
|
|
|
|
fn parse(input: Vec<Self::Token>) -> Result<Self::AST, ParseError> {
|
|
|
|
parser::parse(&input, &[]).map_err(|x| ParseError { msg: x.msg })
|
|
|
|
}
|
2017-01-31 00:53:31 -08:00
|
|
|
fn evaluate(ast: Self::AST, evaluator: &mut Self::Evaluator) -> Vec<String> {
|
2017-01-23 11:27:11 -08:00
|
|
|
evaluator.run(ast)
|
|
|
|
}
|
2017-01-23 19:11:50 -08:00
|
|
|
fn compile(ast: Self::AST) -> LLVMCodeString {
|
2017-01-23 11:27:11 -08:00
|
|
|
compilation::compile_ast(ast)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-24 20:09:14 -08:00
|
|
|
impl<'a> EvaluationMachine for SchalaEvaluator<'a> {
|
|
|
|
fn set_option(&mut self, option: &str, value: bool) -> bool {
|
|
|
|
if option == "trace_evaluation" {
|
|
|
|
self.trace_evaluation = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new() -> SchalaEvaluator<'a> {
|
|
|
|
SchalaEvaluator::new(None)
|
|
|
|
}
|
|
|
|
}
|