Kill old trait infrastructure

This commit is contained in:
greg 2018-04-30 14:34:15 -07:00
parent 491face68b
commit 83fe71f721
5 changed files with 18 additions and 31 deletions

View File

@ -7,7 +7,7 @@ mod parser;
mod eval; mod eval;
mod compilation; mod compilation;
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, LanguageOutput, TraceArtifact}; use schala_repl::{ProgrammingLanguageInterface, EvalOptions, UnfinishedComputation, FinishedComputation, TraceArtifact};
#[derive(Debug)] #[derive(Debug)]
pub struct TokenError { pub struct TokenError {
@ -42,8 +42,8 @@ impl<'a> ProgrammingLanguageInterface for Maaru<'a> {
format!("maaru") format!("maaru")
} }
fn evaluate_in_repl(&mut self, input: &str, options: &EvalOptions) -> LanguageOutput { fn execute_pipeline(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation {
let mut output = LanguageOutput::default(); let mut output = UnfinishedComputation::default();
let tokens = match tokenizer::tokenize(input) { let tokens = match tokenizer::tokenize(input) {
Ok(tokens) => { Ok(tokens) => {
@ -53,8 +53,7 @@ impl<'a> ProgrammingLanguageInterface for Maaru<'a> {
tokens tokens
}, },
Err(err) => { Err(err) => {
output.add_output(format!("Tokenization error: {:?}\n", err.msg)); return output.finish(Err(format!("Tokenization error: {:?}\n", err.msg)))
return output;
} }
}; };
@ -66,16 +65,14 @@ impl<'a> ProgrammingLanguageInterface for Maaru<'a> {
ast ast
}, },
Err(err) => { Err(err) => {
output.add_output(format!("Parse error: {:?}\n", err.msg)); return output.finish(Err(format!("Parse error: {:?}\n", err.msg)))
return output;
} }
}; };
let mut evaluation_output = String::new(); let mut evaluation_output = String::new();
for s in self.evaluator.run(ast).iter() { for s in self.evaluator.run(ast).iter() {
evaluation_output.push_str(s); evaluation_output.push_str(s);
} }
output.add_output(evaluation_output); output.finish(Ok(evaluation_output))
return output;
} }
/* TODO make this work with new framework */ /* TODO make this work with new framework */

View File

@ -4,7 +4,7 @@ extern crate itertools;
extern crate schala_repl; extern crate schala_repl;
use itertools::Itertools; use itertools::Itertools;
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, LanguageOutput}; use schala_repl::{ProgrammingLanguageInterface, EvalOptions, FinishedComputation, UnfinishedComputation};
pub struct Robo { pub struct Robo {
} }
@ -155,18 +155,16 @@ impl ProgrammingLanguageInterface for Robo {
format!("robo") format!("robo")
} }
fn evaluate_in_repl(&mut self, input: &str, _eval_options: &EvalOptions) -> LanguageOutput { fn execute_pipeline(&mut self, input: &str, _eval_options: &EvalOptions) -> FinishedComputation {
let mut output = LanguageOutput::default(); let output = UnfinishedComputation::default();
let tokens = match tokenize(input) { let tokens = match tokenize(input) {
Ok(tokens) => tokens, Ok(tokens) => tokens,
Err(e) => { Err(e) => {
output.add_output(format!("Tokenize error: {:?}", e)); return output.finish(Err(format!("Tokenize error: {:?}", e)));
return output;
} }
}; };
output.add_output(format!("{:?}", tokens)); output.finish(Ok(format!("{:?}", tokens)))
output
} }
} }

View File

@ -4,7 +4,7 @@ extern crate itertools;
extern crate schala_repl; extern crate schala_repl;
use itertools::Itertools; use itertools::Itertools;
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, LanguageOutput}; use schala_repl::{ProgrammingLanguageInterface, EvalOptions, UnfinishedComputation, FinishedComputation};
use std::iter::Peekable; use std::iter::Peekable;
use std::vec::IntoIter; use std::vec::IntoIter;
use std::str::Chars; use std::str::Chars;
@ -73,12 +73,11 @@ impl ProgrammingLanguageInterface for Rukka {
format!("rukka") format!("rukka")
} }
fn evaluate_in_repl(&mut self, input: &str, _eval_options: &EvalOptions) -> LanguageOutput { fn execute_pipeline(&mut self, input: &str, _eval_options: &EvalOptions) -> FinishedComputation {
let mut output = LanguageOutput::default(); let mut output = UnfinishedComputation::default();
let sexps = match read(input) { let sexps = match read(input) {
Err(err) => { Err(err) => {
output.add_output(format!("Error: {}", err)); return output.finish(Err(format!("Error: {}", err)));
return output;
}, },
Ok(sexps) => sexps Ok(sexps) => sexps
}; };
@ -89,8 +88,7 @@ impl ProgrammingLanguageInterface for Rukka {
Err(err) => format!("{} Error: {}", i, err), Err(err) => format!("{} Error: {}", i, err),
} }
}).intersperse(format!("\n")).collect(); }).intersperse(format!("\n")).collect();
output.add_output(output_str); output.finish(Ok(output_str))
output
} }
} }

View File

@ -163,12 +163,6 @@ impl TraceArtifact {
} }
pub trait ProgrammingLanguageInterface { pub trait ProgrammingLanguageInterface {
/* old */
fn evaluate_in_repl(&mut self, _: &str, _: &EvalOptions) -> LanguageOutput {
LanguageOutput { output: format!("Defunct"), artifacts: vec![], failed: false }
}
/* old */
fn execute_pipeline(&mut self, _input: &str, _eval_options: &EvalOptions) -> FinishedComputation { fn execute_pipeline(&mut self, _input: &str, _eval_options: &EvalOptions) -> FinishedComputation {
FinishedComputation { artifacts: HashMap::new(), text_output: Err(format!("Execution pipeline not done")) } FinishedComputation { artifacts: HashMap::new(), text_output: Err(format!("Execution pipeline not done")) }
} }

View File

@ -35,8 +35,8 @@ struct Output {
fn interpreter_input(input: Json<Input>, generators: State<Vec<PLIGenerator>>) -> Json<Output> { fn interpreter_input(input: Json<Input>, generators: State<Vec<PLIGenerator>>) -> Json<Output> {
let schala_gen = generators.get(0).unwrap(); let schala_gen = generators.get(0).unwrap();
let mut schala: Box<ProgrammingLanguageInterface> = schala_gen(); let mut schala: Box<ProgrammingLanguageInterface> = schala_gen();
let code_output = schala.evaluate_in_repl(&input.source, &EvalOptions::default()); let code_output = schala.execute_pipeline(&input.source, &EvalOptions::default());
Json(Output { text: code_output.to_string() }) Json(Output { text: code_output.to_repl() })
} }
pub fn web_main(language_generators: Vec<PLIGenerator>) { pub fn web_main(language_generators: Vec<PLIGenerator>) {