Rename passes

This commit is contained in:
greg 2018-05-05 02:06:08 -07:00
parent fb168da8bd
commit 8ad5dd9056

View File

@ -5,7 +5,6 @@ extern crate itertools;
extern crate lazy_static; extern crate lazy_static;
#[macro_use] #[macro_use]
extern crate maplit; extern crate maplit;
#[macro_use] #[macro_use]
extern crate schala_repl; extern crate schala_repl;
#[macro_use] #[macro_use]
@ -19,33 +18,30 @@ macro_rules! bx {
} }
mod builtin; mod builtin;
mod tokenizing; mod tokenizing;
mod parsing; mod parsing;
mod typechecking; mod typechecking;
mod eval; mod eval;
use self::typechecking::{TypeContext};
#[derive(ProgrammingLanguageInterface)] #[derive(ProgrammingLanguageInterface)]
#[LanguageName = "Schala"] #[LanguageName = "Schala"]
#[SourceFileExtension = "schala"] #[SourceFileExtension = "schala"]
#[PipelineSteps(tokenizing_stage, parsing_stage, symbol_table_stage, typechecking_stage, eval_stage)] #[PipelineSteps(tokenizing, parsing, symbol_table, typechecking, eval)]
pub struct Schala { pub struct Schala {
state: eval::State<'static>, state: eval::State<'static>,
type_context: TypeContext type_context: typechecking::TypeContext
} }
impl Schala { impl Schala {
pub fn new() -> Schala { pub fn new() -> Schala {
Schala { Schala {
state: eval::State::new(), state: eval::State::new(),
type_context: TypeContext::new(), type_context: typechecking::TypeContext::new(),
} }
} }
} }
fn tokenizing_stage(_handle: &mut Schala, input: &str, comp: Option<&mut UnfinishedComputation>) -> Result<Vec<tokenizing::Token>, String> { fn tokenizing(_handle: &mut Schala, input: &str, 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.token_type, t.offset.0, t.offset.1)).join(", "); let token_string = tokens.iter().map(|t| format!("{:?}<L:{},C:{}>", t.token_type, t.offset.0, t.offset.1)).join(", ");
@ -60,7 +56,7 @@ fn tokenizing_stage(_handle: &mut Schala, input: &str, comp: Option<&mut Unfinis
} }
} }
fn parsing_stage(_handle: &mut Schala, input: Vec<tokenizing::Token>, comp: Option<&mut UnfinishedComputation>) -> Result<parsing::AST, parsing::ParseError> { fn parsing(_handle: &mut Schala, input: Vec<tokenizing::Token>, comp: Option<&mut UnfinishedComputation>) -> Result<parsing::AST, parsing::ParseError> {
let (ast, trace) = parsing::parse(input); let (ast, trace) = parsing::parse(input);
comp.map(|comp| { comp.map(|comp| {
@ -71,7 +67,7 @@ fn parsing_stage(_handle: &mut Schala, input: Vec<tokenizing::Token>, comp: Opti
ast ast
} }
fn symbol_table_stage(handle: &mut Schala, input: parsing::AST, comp: Option<&mut UnfinishedComputation>) -> Result<parsing::AST, String> { fn symbol_table(handle: &mut Schala, input: parsing::AST, comp: Option<&mut UnfinishedComputation>) -> Result<parsing::AST, String> {
match handle.type_context.add_top_level_types(&input) { match handle.type_context.add_top_level_types(&input) {
Ok(()) => { Ok(()) => {
let text = handle.type_context.debug_symbol_table(); let text = handle.type_context.debug_symbol_table();
@ -82,7 +78,7 @@ fn symbol_table_stage(handle: &mut Schala, input: parsing::AST, comp: Option<&mu
} }
} }
fn typechecking_stage(handle: &mut Schala, input: parsing::AST, comp: Option<&mut UnfinishedComputation>) -> Result<parsing::AST, String> { fn typechecking(handle: &mut Schala, input: parsing::AST, comp: Option<&mut UnfinishedComputation>) -> Result<parsing::AST, String> {
match handle.type_context.type_check_ast(&input) { match handle.type_context.type_check_ast(&input) {
Ok(ty) => { Ok(ty) => {
comp.map(|comp| comp.add_artifact(TraceArtifact::new("type_check", format!("{:?}", ty)))); comp.map(|comp| comp.add_artifact(TraceArtifact::new("type_check", format!("{:?}", ty))));
@ -92,7 +88,7 @@ fn typechecking_stage(handle: &mut Schala, input: parsing::AST, comp: Option<&mu
} }
} }
fn eval_stage(handle: &mut Schala, input: parsing::AST, _comp: Option<&mut UnfinishedComputation>) -> Result<String, String> { fn eval(handle: &mut Schala, input: parsing::AST, _comp: Option<&mut UnfinishedComputation>) -> Result<String, String> {
let evaluation_outputs = handle.state.evaluate(input); let evaluation_outputs = handle.state.evaluate(input);
let text_output: Result<Vec<String>, String> = evaluation_outputs let text_output: Result<Vec<String>, String> = evaluation_outputs
.into_iter() .into_iter()