2017-09-08 03:47:04 -07:00
|
|
|
extern crate colored;
|
|
|
|
|
|
|
|
use self::colored::*;
|
|
|
|
|
2017-01-23 19:11:50 -08:00
|
|
|
pub struct LLVMCodeString(pub String);
|
|
|
|
|
2017-09-17 18:57:47 -07:00
|
|
|
#[derive(Debug, Default, Serialize, Deserialize)]
|
2017-08-30 19:09:22 -07:00
|
|
|
pub struct EvalOptions {
|
2017-08-30 19:15:04 -07:00
|
|
|
pub debug_tokens: bool,
|
|
|
|
pub debug_parse: bool,
|
|
|
|
pub debug_type: bool,
|
2017-10-08 13:57:43 -07:00
|
|
|
pub debug_symbol_table: bool,
|
2017-09-01 02:08:26 -07:00
|
|
|
pub show_llvm_ir: bool,
|
2017-08-31 16:26:55 -07:00
|
|
|
pub trace_evaluation: bool,
|
2017-10-02 22:58:03 -07:00
|
|
|
pub compile: bool,
|
2017-08-30 19:09:22 -07:00
|
|
|
}
|
|
|
|
|
2017-08-31 20:59:43 -07:00
|
|
|
#[derive(Debug, Default)]
|
2018-03-07 22:07:13 -08:00
|
|
|
pub struct LanguageOutput {
|
2017-08-31 20:59:43 -07:00
|
|
|
output: String,
|
2018-03-09 00:50:06 -08:00
|
|
|
artifacts: Vec<TraceArtifact>,
|
2018-03-11 12:56:51 -07:00
|
|
|
pub failed: bool,
|
2017-08-31 20:59:43 -07:00
|
|
|
}
|
|
|
|
|
2018-03-07 22:07:13 -08:00
|
|
|
impl LanguageOutput {
|
2017-08-31 20:59:43 -07:00
|
|
|
pub fn add_artifact(&mut self, artifact: TraceArtifact) {
|
|
|
|
self.artifacts.push(artifact);
|
|
|
|
}
|
|
|
|
pub fn add_output(&mut self, output: String) {
|
|
|
|
self.output = output;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn to_string(&self) -> String {
|
|
|
|
let mut acc = String::new();
|
|
|
|
for line in self.artifacts.iter() {
|
2017-09-08 03:47:04 -07:00
|
|
|
acc.push_str(&line.debug_output.color(line.text_color).to_string());
|
|
|
|
acc.push_str(&"\n");
|
2017-08-31 20:59:43 -07:00
|
|
|
}
|
|
|
|
acc.push_str(&self.output);
|
|
|
|
acc
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print_to_screen(&self) {
|
|
|
|
for line in self.artifacts.iter() {
|
2017-10-12 10:43:54 -07:00
|
|
|
let color = line.text_color;
|
|
|
|
let stage = line.stage_name.color(color).to_string();
|
|
|
|
let output = line.debug_output.color(color).to_string();
|
|
|
|
println!("{}: {}", stage, output);
|
2017-08-31 20:59:43 -07:00
|
|
|
}
|
|
|
|
println!("{}", self.output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
//TODO I'll probably wanna implement this later
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct CompilationOutput {
|
|
|
|
output: LLVMCodeString,
|
|
|
|
artifacts: Vec<TraceArtifact>,
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct TraceArtifact {
|
|
|
|
stage_name: String,
|
|
|
|
debug_output: String,
|
2017-09-08 03:47:04 -07:00
|
|
|
text_color: &'static str,
|
2017-08-31 20:59:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TraceArtifact {
|
|
|
|
pub fn new(stage: &str, debug: String) -> TraceArtifact {
|
2017-09-16 14:29:22 -07:00
|
|
|
let color = match stage {
|
2017-10-08 22:17:29 -07:00
|
|
|
"parse_trace" | "ast" => "red",
|
2017-09-16 14:29:22 -07:00
|
|
|
"tokens" => "green",
|
2017-10-01 00:48:08 -07:00
|
|
|
"type_check" => "magenta",
|
2017-09-16 14:29:22 -07:00
|
|
|
_ => "blue",
|
|
|
|
};
|
|
|
|
TraceArtifact { stage_name: stage.to_string(), debug_output: debug, text_color: color}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_parse_trace(trace: Vec<String>) -> TraceArtifact {
|
2017-09-16 15:05:11 -07:00
|
|
|
let mut output = String::new();
|
|
|
|
|
|
|
|
for t in trace {
|
|
|
|
output.push_str(&t);
|
|
|
|
output.push_str("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
TraceArtifact { stage_name: "parse_trace".to_string(), debug_output: output, text_color: "red"}
|
2017-08-31 20:59:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 19:09:22 -07:00
|
|
|
pub trait ProgrammingLanguageInterface {
|
2018-03-07 22:07:13 -08:00
|
|
|
fn evaluate_in_repl(&mut self, input: &str, eval_options: &EvalOptions) -> LanguageOutput;
|
2018-03-09 00:50:06 -08:00
|
|
|
fn evaluate_noninteractive(&mut self, input: &str, eval_options: &EvalOptions) -> LanguageOutput {
|
|
|
|
self.evaluate_in_repl(input, eval_options)
|
|
|
|
}
|
2017-08-30 19:09:22 -07:00
|
|
|
fn get_language_name(&self) -> String;
|
2017-10-02 23:07:05 -07:00
|
|
|
fn get_source_file_suffix(&self) -> String;
|
2017-08-31 19:15:32 -07:00
|
|
|
fn compile(&mut self, _input: &str) -> LLVMCodeString {
|
|
|
|
LLVMCodeString("".to_string())
|
|
|
|
}
|
|
|
|
fn can_compile(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
2017-08-30 19:09:22 -07:00
|
|
|
}
|