Reorder parameters in pass functions
This commit is contained in:
parent
02667b018c
commit
801c90aaa7
@ -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>(handle: &mut Schala, input: &'a str, _comp: Option<&mut UnfinishedComputation>) -> Result<&'a str, String> {
|
||||
fn load_source<'a>(input: &'a str, handle: &mut Schala, _comp: Option<&mut UnfinishedComputation>) -> Result<&'a str, String> {
|
||||
handle.source_reference.load_new_source(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);
|
||||
comp.map(|comp| {
|
||||
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;
|
||||
|
||||
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);
|
||||
match add {
|
||||
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);
|
||||
|
||||
comp.map(|comp| {
|
||||
@ -176,14 +175,14 @@ fn typechecking(handle: &mut Schala, input: ast::AST, comp: Option<&mut Unfinish
|
||||
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 output = input.reduce(symbol_table);
|
||||
comp.map(|comp| comp.add_artifact(TraceArtifact::new("ast_reducing", format!("{:?}", 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())));
|
||||
let evaluation_outputs = handle.state.evaluate(input, true);
|
||||
let text_output: Result<Vec<String>, String> = evaluation_outputs
|
||||
|
@ -67,8 +67,8 @@ fn get_attribute_identifier(attr_name: &str, attrs: &Vec<Attribute>) -> Option<p
|
||||
})
|
||||
}
|
||||
|
||||
/* a pass_chain function signature looks like:
|
||||
* fn(&mut ProgrammingLanguageInterface, A, Option<&mut DebugHandler>) -> Result<B, String>
|
||||
/* a pass_chain function signature with input A and output B looks like:
|
||||
* fn(A, &mut ProgrammingLanguageInterface, Option<&mut DebugHandler>) -> Result<B, String>
|
||||
*
|
||||
* 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
|
||||
};
|
||||
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();
|
||||
(pass_output, elapsed)
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user