From 3d960d5697eb9e8699ceaebf6df18b7670f2574e Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 29 Apr 2018 03:45:31 -0700 Subject: [PATCH] Implement most of pipeline --- schala-lang/src/lib.rs | 45 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index b63207f..7c690c5 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -40,14 +40,47 @@ impl Schala { } } -fn tokenizing_stage(handle: &mut Schala, input: &str) -> Result, ()> { +fn tokenizing_stage(_handle: &mut Schala, input: &str) -> Result, ()> { Ok(tokenizing::tokenize(input)) } -fn parsing_stage(handle: &mut Schala, input: Vec) -> Result { +fn parsing_stage(_handle: &mut Schala, input: Vec) -> Result { parsing::parse(input).0 } +fn symbol_table_stage(handle: &mut Schala, input: parsing::AST) -> Result { + match handle.type_context.add_top_level_types(&input) { + Ok(()) => Ok(input), + Err(msg) => Err(msg) + } +} + +fn typechecking_stage(handle: &mut Schala, input: parsing::AST) -> Result { + match handle.type_context.type_check_ast(&input) { + Ok(ty) => { + println!("FINAL TYPE: {:?}", ty); + /* + if options.debug.type_checking { + evaluation.add_artifact(TraceArtifact::new("type_check", format!("{:?}", ty))); + } + */ + Ok(input) + }, + Err(msg) => Err(msg) + } +} + +fn eval_stage(handle: &mut Schala, input: parsing::AST) -> Result { + let evaluation_outputs = handle.state.evaluate(input); + let text_output: Result, String> = evaluation_outputs + .into_iter() + .collect(); + + let eval_output: Result = text_output + .map(|v| { v.into_iter().intersperse(format!("\n")).collect() }); + eval_output +} + impl ProgrammingLanguageInterface for Schala { fn get_language_name(&self) -> String { "Schala".to_string() @@ -59,7 +92,13 @@ impl ProgrammingLanguageInterface for Schala { fn execute_pipeline(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation { //let chain = pass_chain![tokenizing::tokenize, parsing::parse]; - let mut chain = pass_chain![self, tokenizing_stage, parsing_stage]; + let mut chain = pass_chain![self, + tokenizing_stage, + parsing_stage, + symbol_table_stage, + typechecking_stage, + eval_stage + ]; chain(input) }