Added back compilation
This commit is contained in:
parent
55e1600b97
commit
cb9b56f000
@ -29,8 +29,10 @@ pub struct EvalOptions {
|
||||
pub trait ProgrammingLanguageInterface {
|
||||
fn evaluate_in_repl(&mut self, input: &str, eval_options: EvalOptions) -> Vec<String>;
|
||||
fn get_language_name(&self) -> String;
|
||||
fn compile(&mut self, _input: &str) -> LLVMCodeString {
|
||||
LLVMCodeString("".to_string())
|
||||
}
|
||||
fn can_compile(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub trait CompileableLanguage : ProgrammingLanguageInterface {
|
||||
fn compile(&mut self) -> LLVMCodeString;
|
||||
}
|
||||
|
@ -59,4 +59,27 @@ impl<'a> ProgrammingLanguageInterface for Maaru<'a> {
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
16
src/main.rs
16
src/main.rs
@ -9,12 +9,6 @@ use std::process;
|
||||
use std::io::Write;
|
||||
use std::default::Default;
|
||||
|
||||
/*
|
||||
mod schala_lang;
|
||||
use schala_lang::SchalaEvaluator;
|
||||
use schala_lang::Schala;
|
||||
*/
|
||||
|
||||
mod schala_lang;
|
||||
mod maaru_lang;
|
||||
mod robo_lang;
|
||||
@ -128,10 +122,20 @@ fn run_noninteractive<T: ProgrammingLanguageInterface>(filename: &str, language:
|
||||
source_file.read_to_string(&mut buffer).unwrap();
|
||||
|
||||
let options = EvalOptions::default();
|
||||
|
||||
if compile {
|
||||
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) {
|
||||
Ok(t) => t,
|
||||
|
Loading…
Reference in New Issue
Block a user