Added back compilation

This commit is contained in:
greg 2017-08-31 19:15:32 -07:00
parent 55e1600b97
commit cb9b56f000
3 changed files with 43 additions and 14 deletions

View File

@ -29,8 +29,10 @@ 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 compile(&mut self, _input: &str) -> LLVMCodeString {
LLVMCodeString("".to_string())
pub trait CompileableLanguage : ProgrammingLanguageInterface { }
fn compile(&mut self) -> LLVMCodeString; fn can_compile(&self) -> bool {
false
}
} }

View File

@ -59,4 +59,27 @@ impl<'a> ProgrammingLanguageInterface for Maaru<'a> {
return output; return output;
} }
fn can_compile(&self) -> bool {
true
}
fn compile(&mut self, input: &str) -> LLVMCodeString {
let tokens = match tokenizer::tokenize(input) {
Ok(tokens) => tokens,
Err(err) => {
let msg = format!("Tokenization error: {:?}\n", err.msg);
panic!("{}", msg);
}
};
let ast = match parser::parse(&tokens, &[]) {
Ok(ast) => ast,
Err(err) => {
let msg = format!("Parse error: {:?}\n", err.msg);
panic!("{}", msg);
}
};
compilation::compile_ast(ast)
}
} }

View File

@ -9,12 +9,6 @@ use std::process;
use std::io::Write; use std::io::Write;
use std::default::Default; use std::default::Default;
/*
mod schala_lang;
use schala_lang::SchalaEvaluator;
use schala_lang::Schala;
*/
mod schala_lang; mod schala_lang;
mod maaru_lang; mod maaru_lang;
mod robo_lang; mod robo_lang;
@ -128,11 +122,21 @@ fn run_noninteractive<T: ProgrammingLanguageInterface>(filename: &str, language:
source_file.read_to_string(&mut buffer).unwrap(); source_file.read_to_string(&mut buffer).unwrap();
let options = EvalOptions::default(); let options = EvalOptions::default();
let interpretor_output = language.evaluate_in_repl(&buffer, options);
for line in interpretor_output { if compile {
println!("{}", line); if !language.can_compile() {
panic!("Trying to compile a non-compileable language");
} else {
let llvm_bytecode = language.compile(&buffer);
compilation_sequence(llvm_bytecode, filename);
}
} else {
let interpretor_output = language.evaluate_in_repl(&buffer, options);
for line in interpretor_output {
println!("{}", line);
}
} }
/* /*
let tokens = match T::tokenize(&buffer) { let tokens = match T::tokenize(&buffer) {
Ok(t) => t, Ok(t) => t,
Err(e) => { Err(e) => {