From cb9b56f000d613b6f94c0522ecfb9a6a9a44bc51 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 31 Aug 2017 19:15:32 -0700 Subject: [PATCH] Added back compilation --- src/language.rs | 10 ++++++---- src/maaru_lang/mod.rs | 23 +++++++++++++++++++++++ src/main.rs | 24 ++++++++++++++---------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/language.rs b/src/language.rs index d378da7..a8249b0 100644 --- a/src/language.rs +++ b/src/language.rs @@ -29,8 +29,10 @@ pub struct EvalOptions { pub trait ProgrammingLanguageInterface { fn evaluate_in_repl(&mut self, input: &str, eval_options: EvalOptions) -> Vec; fn get_language_name(&self) -> String; -} - -pub trait CompileableLanguage : ProgrammingLanguageInterface { - fn compile(&mut self) -> LLVMCodeString; + fn compile(&mut self, _input: &str) -> LLVMCodeString { + LLVMCodeString("".to_string()) + } + fn can_compile(&self) -> bool { + false + } } diff --git a/src/maaru_lang/mod.rs b/src/maaru_lang/mod.rs index 407745c..4399314 100644 --- a/src/maaru_lang/mod.rs +++ b/src/maaru_lang/mod.rs @@ -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) + } } diff --git a/src/main.rs b/src/main.rs index dbe2ac0..ce4cf05 100644 --- a/src/main.rs +++ b/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,11 +122,21 @@ fn run_noninteractive(filename: &str, language: source_file.read_to_string(&mut buffer).unwrap(); let options = EvalOptions::default(); - let interpretor_output = language.evaluate_in_repl(&buffer, options); - for line in interpretor_output { - println!("{}", line); + + 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, Err(e) => {