rustfmt schala.rs

This commit is contained in:
Greg Shuflin 2021-10-27 00:39:08 -07:00
parent d65233240a
commit 0f40a7de5d

View File

@ -1,11 +1,12 @@
use stopwatch::Stopwatch;
use crate::error::SchalaError;
use crate::{/*eval, */parsing, reduced_ir, tree_walk_eval, symbol_table, tokenizing, typechecking};
use schala_repl::{ use schala_repl::{
ComputationRequest, ComputationResponse, GlobalOutputStats, LangMetaRequest, LangMetaResponse, ComputationRequest, ComputationResponse, GlobalOutputStats, LangMetaRequest, LangMetaResponse,
ProgrammingLanguageInterface, ProgrammingLanguageInterface,
}; };
use stopwatch::Stopwatch;
use crate::{
error::SchalaError, parsing, reduced_ir, symbol_table, tokenizing, tree_walk_eval, typechecking,
};
/// All the state necessary to parse and execute a Schala program are stored in this struct. /// All the state necessary to parse and execute a Schala program are stored in this struct.
pub struct Schala<'a> { pub struct Schala<'a> {
@ -22,7 +23,6 @@ pub struct Schala<'a> {
/// Execution state for AST-walking interpreter /// Execution state for AST-walking interpreter
eval_state: tree_walk_eval::State<'a>, eval_state: tree_walk_eval::State<'a>,
} }
/* /*
@ -84,19 +84,13 @@ impl<'a> Schala<'a> {
.map_err(|err| SchalaError::from_parse_error(err, &self.source_reference))?; .map_err(|err| SchalaError::from_parse_error(err, &self.source_reference))?;
//Perform all symbol table work //Perform all symbol table work
self.symbol_table self.symbol_table.process_ast(&ast).map_err(SchalaError::from_symbol_table)?;
.process_ast(&ast)
.map_err(SchalaError::from_symbol_table)?;
// Typechecking // Typechecking
// TODO typechecking not working // TODO typechecking not working
let _overall_type = self let _overall_type = self.type_context.typecheck(&ast).map_err(SchalaError::from_type_error);
.type_context
.typecheck(&ast)
.map_err(SchalaError::from_type_error);
let reduced_ir = reduced_ir::reduce(&ast, &self.symbol_table); let reduced_ir = reduced_ir::reduce(&ast, &self.symbol_table);
println!("Reduced IR: {:?}", reduced_ir);
let evaluation_outputs = self.eval_state.evaluate(reduced_ir, true); let evaluation_outputs = self.eval_state.evaluate(reduced_ir, true);
let text_output: Result<Vec<String>, String> = evaluation_outputs.into_iter().collect(); let text_output: Result<Vec<String>, String> = evaluation_outputs.into_iter().collect();
@ -108,24 +102,6 @@ impl<'a> Schala<'a> {
text_output.map(|v| Iterator::intersperse(v.into_iter(), "\n".to_owned()).collect())?; text_output.map(|v| Iterator::intersperse(v.into_iter(), "\n".to_owned()).collect())?;
Ok(eval_output) Ok(eval_output)
/*
// Reduce AST - TODO this doesn't produce an error yet, but probably should
let reduced_ast = reduced_ast::reduce(&ast, &self.symbol_table);
// Tree-walking evaluator. TODO fix this
let evaluation_outputs = self.state.evaluate(reduced_ast, true);
let text_output: Result<Vec<String>, String> = evaluation_outputs.into_iter().collect();
let text_output: Result<Vec<String>, SchalaError> =
text_output.map_err(|err| SchalaError::from_string(err, Stage::Evaluation));
let eval_output: String =
text_output.map(|v| Iterator::intersperse(v.into_iter(), "\n".to_owned()).collect())?;
Ok(eval_output)
*/
} }
} }
@ -165,14 +141,7 @@ pub(crate) enum Stage {
} }
fn stage_names() -> Vec<&'static str> { fn stage_names() -> Vec<&'static str> {
vec![ vec!["tokenizing", "parsing", "symbol-table", "typechecking", "ast-reduction", "ast-walking-evaluation"]
"tokenizing",
"parsing",
"symbol-table",
"typechecking",
"ast-reduction",
"ast-walking-evaluation",
]
} }
impl<'a> ProgrammingLanguageInterface for Schala<'a> { impl<'a> ProgrammingLanguageInterface for Schala<'a> {
@ -186,43 +155,23 @@ impl<'a> ProgrammingLanguageInterface for Schala<'a> {
"schala".to_owned() "schala".to_owned()
} }
fn run_computation( fn run_computation(&mut self, request: ComputationRequest<Self::Config>) -> ComputationResponse {
&mut self, let ComputationRequest { source, debug_requests: _, config: _ } = request;
request: ComputationRequest<Self::Config>,
) -> ComputationResponse {
let ComputationRequest {
source,
debug_requests: _,
config: _,
} = request;
self.source_reference.load_new_source(source); self.source_reference.load_new_source(source);
let sw = Stopwatch::start_new(); let sw = Stopwatch::start_new();
let main_output = self let main_output = self.run_pipeline(source).map_err(|schala_err| schala_err.display());
.run_pipeline(source)
.map_err(|schala_err| schala_err.display());
let global_output_stats = GlobalOutputStats { let global_output_stats = GlobalOutputStats { total_duration: sw.elapsed(), stage_durations: vec![] };
total_duration: sw.elapsed(),
stage_durations: vec![],
};
ComputationResponse { ComputationResponse { main_output, global_output_stats, debug_responses: vec![] }
main_output,
global_output_stats,
debug_responses: vec![],
}
} }
fn request_meta(&mut self, request: LangMetaRequest) -> LangMetaResponse { fn request_meta(&mut self, request: LangMetaRequest) -> LangMetaResponse {
match request { match request {
LangMetaRequest::StageNames => { LangMetaRequest::StageNames =>
LangMetaResponse::StageNames(stage_names().iter().map(|s| s.to_string()).collect()) LangMetaResponse::StageNames(stage_names().iter().map(|s| s.to_string()).collect()),
} _ => LangMetaResponse::Custom { kind: "not-implemented".to_string(), value: "".to_string() },
_ => LangMetaResponse::Custom {
kind: "not-implemented".to_string(),
value: "".to_string(),
},
} }
} }
} }