From 801c90aaa78898fe3c2840c2e358b1e1fe6b207d Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 7 Jan 2019 02:43:31 -0800 Subject: [PATCH] Reorder parameters in pass functions --- schala-lang/language/src/lib.rs | 15 +++++++-------- schala-repl-codegen/src/lib.rs | 6 +++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index 2992b6e..8d0bdd6 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -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, String> { +fn tokenizing(input: &str, _handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result, String> { let tokens = tokenizing::tokenize(input); comp.map(|comp| { let token_string = tokens.iter().map(|t| format!("{:?}", 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, comp: Option<&mut UnfinishedComputation>) -> Result { +fn parsing(input: Vec, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result { 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 { +fn symbol_table(input: ast::AST, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result { 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 { +fn typechecking(input: ast::AST, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result { 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 { +fn ast_reducing(input: ast::AST, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result { 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 { +fn eval(input: reduced_ast::ReducedAST, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result { 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, String> = evaluation_outputs diff --git a/schala-repl-codegen/src/lib.rs b/schala-repl-codegen/src/lib.rs index 6016783..8112f91 100644 --- a/schala-repl-codegen/src/lib.rs +++ b/schala-repl-codegen/src/lib.rs @@ -67,8 +67,8 @@ fn get_attribute_identifier(attr_name: &str, attrs: &Vec) -> Option

) -> Result +/* a pass_chain function signature with input A and output B looks like: + * fn(A, &mut ProgrammingLanguageInterface, Option<&mut DebugHandler>) -> Result * * TODO use some kind of failure-handling library to make this better */ @@ -97,7 +97,7 @@ fn generate_pass_chain(idents: Vec) -> 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) };