rustfmt schala.rs
This commit is contained in:
parent
d65233240a
commit
0f40a7de5d
@ -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::{
|
||||
ComputationRequest, ComputationResponse, GlobalOutputStats, LangMetaRequest, LangMetaResponse,
|
||||
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.
|
||||
pub struct Schala<'a> {
|
||||
@ -22,7 +23,6 @@ pub struct Schala<'a> {
|
||||
|
||||
/// Execution state for AST-walking interpreter
|
||||
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))?;
|
||||
|
||||
//Perform all symbol table work
|
||||
self.symbol_table
|
||||
.process_ast(&ast)
|
||||
.map_err(SchalaError::from_symbol_table)?;
|
||||
self.symbol_table.process_ast(&ast).map_err(SchalaError::from_symbol_table)?;
|
||||
|
||||
// Typechecking
|
||||
// TODO typechecking not working
|
||||
let _overall_type = self
|
||||
.type_context
|
||||
.typecheck(&ast)
|
||||
.map_err(SchalaError::from_type_error);
|
||||
let _overall_type = self.type_context.typecheck(&ast).map_err(SchalaError::from_type_error);
|
||||
|
||||
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 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())?;
|
||||
|
||||
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> {
|
||||
vec![
|
||||
"tokenizing",
|
||||
"parsing",
|
||||
"symbol-table",
|
||||
"typechecking",
|
||||
"ast-reduction",
|
||||
"ast-walking-evaluation",
|
||||
]
|
||||
vec!["tokenizing", "parsing", "symbol-table", "typechecking", "ast-reduction", "ast-walking-evaluation"]
|
||||
}
|
||||
|
||||
impl<'a> ProgrammingLanguageInterface for Schala<'a> {
|
||||
@ -186,43 +155,23 @@ impl<'a> ProgrammingLanguageInterface for Schala<'a> {
|
||||
"schala".to_owned()
|
||||
}
|
||||
|
||||
fn run_computation(
|
||||
&mut self,
|
||||
request: ComputationRequest<Self::Config>,
|
||||
) -> ComputationResponse {
|
||||
let ComputationRequest {
|
||||
source,
|
||||
debug_requests: _,
|
||||
config: _,
|
||||
} = request;
|
||||
fn run_computation(&mut self, request: ComputationRequest<Self::Config>) -> ComputationResponse {
|
||||
let ComputationRequest { source, debug_requests: _, config: _ } = request;
|
||||
self.source_reference.load_new_source(source);
|
||||
let sw = Stopwatch::start_new();
|
||||
|
||||
let main_output = self
|
||||
.run_pipeline(source)
|
||||
.map_err(|schala_err| schala_err.display());
|
||||
let main_output = self.run_pipeline(source).map_err(|schala_err| schala_err.display());
|
||||
|
||||
let global_output_stats = GlobalOutputStats {
|
||||
total_duration: sw.elapsed(),
|
||||
stage_durations: vec![],
|
||||
};
|
||||
let global_output_stats = GlobalOutputStats { total_duration: sw.elapsed(), stage_durations: vec![] };
|
||||
|
||||
ComputationResponse {
|
||||
main_output,
|
||||
global_output_stats,
|
||||
debug_responses: vec![],
|
||||
}
|
||||
ComputationResponse { main_output, global_output_stats, debug_responses: vec![] }
|
||||
}
|
||||
|
||||
fn request_meta(&mut self, request: LangMetaRequest) -> LangMetaResponse {
|
||||
match request {
|
||||
LangMetaRequest::StageNames => {
|
||||
LangMetaResponse::StageNames(stage_names().iter().map(|s| s.to_string()).collect())
|
||||
}
|
||||
_ => LangMetaResponse::Custom {
|
||||
kind: "not-implemented".to_string(),
|
||||
value: "".to_string(),
|
||||
},
|
||||
LangMetaRequest::StageNames =>
|
||||
LangMetaResponse::StageNames(stage_names().iter().map(|s| s.to_string()).collect()),
|
||||
_ => LangMetaResponse::Custom { kind: "not-implemented".to_string(), value: "".to_string() },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user