Reorder parameters in pass functions

This commit is contained in:
greg 2019-01-07 02:43:31 -08:00
parent 02667b018c
commit 801c90aaa7
2 changed files with 10 additions and 11 deletions

View File

@ -89,13 +89,12 @@ impl Schala {
} }
} }
//TODO rejigger the signature of these methods so you don't awkwardly have the input in the middle fn load_source<'a>(input: &'a str, handle: &mut Schala, _comp: Option<&mut UnfinishedComputation>) -> Result<&'a str, String> {
fn load_source<'a>(handle: &mut Schala, input: &'a str, _comp: Option<&mut UnfinishedComputation>) -> Result<&'a str, String> {
handle.source_reference.load_new_source(input); handle.source_reference.load_new_source(input);
Ok(input) Ok(input)
} }
fn tokenizing(_handle: &mut Schala, input: &str, comp: Option<&mut UnfinishedComputation>) -> Result<Vec<tokenizing::Token>, String> { fn tokenizing(input: &str, _handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result<Vec<tokenizing::Token>, String> {
let tokens = tokenizing::tokenize(input); let tokens = tokenizing::tokenize(input);
comp.map(|comp| { comp.map(|comp| {
let token_string = tokens.iter().map(|t| format!("{:?}<L:{},C:{}>", t.kind, t.offset.0, t.offset.1)).join(", "); let token_string = tokens.iter().map(|t| format!("{:?}<L:{},C:{}>", t.kind, t.offset.0, t.offset.1)).join(", ");
@ -110,7 +109,7 @@ fn tokenizing(_handle: &mut Schala, input: &str, comp: Option<&mut UnfinishedCom
} }
} }
fn parsing(handle: &mut Schala, input: Vec<tokenizing::Token>, comp: Option<&mut UnfinishedComputation>) -> Result<ast::AST, String> { fn parsing(input: Vec<tokenizing::Token>, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result<ast::AST, String> {
use parsing::Parser; use parsing::Parser;
let mut parser = match handle.active_parser.take() { let mut parser = match handle.active_parser.take() {
@ -153,7 +152,7 @@ fn format_parse_error(error: parsing::ParseError, handle: &mut Schala) -> String
} }
} }
fn symbol_table(handle: &mut Schala, input: ast::AST, comp: Option<&mut UnfinishedComputation>) -> Result<ast::AST, String> { fn symbol_table(input: ast::AST, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result<ast::AST, String> {
let add = handle.symbol_table.borrow_mut().add_top_level_symbols(&input); let add = handle.symbol_table.borrow_mut().add_top_level_symbols(&input);
match add { match add {
Ok(()) => { Ok(()) => {
@ -165,7 +164,7 @@ fn symbol_table(handle: &mut Schala, input: ast::AST, comp: Option<&mut Unfinish
} }
} }
fn typechecking(handle: &mut Schala, input: ast::AST, comp: Option<&mut UnfinishedComputation>) -> Result<ast::AST, String> { fn typechecking(input: ast::AST, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result<ast::AST, String> {
let result = handle.type_context.typecheck(&input); let result = handle.type_context.typecheck(&input);
comp.map(|comp| { comp.map(|comp| {
@ -176,14 +175,14 @@ fn typechecking(handle: &mut Schala, input: ast::AST, comp: Option<&mut Unfinish
Ok(input) Ok(input)
} }
fn ast_reducing(handle: &mut Schala, input: ast::AST, comp: Option<&mut UnfinishedComputation>) -> Result<reduced_ast::ReducedAST, String> { fn ast_reducing(input: ast::AST, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result<reduced_ast::ReducedAST, String> {
let ref symbol_table = handle.symbol_table.borrow(); let ref symbol_table = handle.symbol_table.borrow();
let output = input.reduce(symbol_table); let output = input.reduce(symbol_table);
comp.map(|comp| comp.add_artifact(TraceArtifact::new("ast_reducing", format!("{:?}", output)))); comp.map(|comp| comp.add_artifact(TraceArtifact::new("ast_reducing", format!("{:?}", output))));
Ok(output) Ok(output)
} }
fn eval(handle: &mut Schala, input: reduced_ast::ReducedAST, comp: Option<&mut UnfinishedComputation>) -> Result<String, String> { fn eval(input: reduced_ast::ReducedAST, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result<String, String> {
comp.map(|comp| comp.add_artifact(TraceArtifact::new("value_state", handle.state.debug_print()))); comp.map(|comp| comp.add_artifact(TraceArtifact::new("value_state", handle.state.debug_print())));
let evaluation_outputs = handle.state.evaluate(input, true); let evaluation_outputs = handle.state.evaluate(input, true);
let text_output: Result<Vec<String>, String> = evaluation_outputs let text_output: Result<Vec<String>, String> = evaluation_outputs

View File

@ -67,8 +67,8 @@ fn get_attribute_identifier(attr_name: &str, attrs: &Vec<Attribute>) -> Option<p
}) })
} }
/* a pass_chain function signature looks like: /* a pass_chain function signature with input A and output B looks like:
* fn(&mut ProgrammingLanguageInterface, A, Option<&mut DebugHandler>) -> Result<B, String> * fn(A, &mut ProgrammingLanguageInterface, Option<&mut DebugHandler>) -> Result<B, String>
* *
* TODO use some kind of failure-handling library to make this better * TODO use some kind of failure-handling library to make this better
*/ */
@ -97,7 +97,7 @@ fn generate_pass_chain(idents: Vec<Ident>) -> proc_macro2::TokenStream {
_ => None _ => None
}; };
let start = time::Instant::now(); let start = time::Instant::now();
let pass_output = #pass_name(self, input_to_next_stage, debug_handle); let pass_output = #pass_name(input_to_next_stage, self, debug_handle);
let elapsed = start.elapsed(); let elapsed = start.elapsed();
(pass_output, elapsed) (pass_output, elapsed)
}; };