diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index 389c7ad..e6a5c2d 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -91,10 +91,12 @@ fn symbol_table(handle: &mut Schala, input: parsing::AST, comp: Option<&mut Unfi fn typechecking(handle: &mut Schala, input: parsing::AST, comp: Option<&mut UnfinishedComputation>) -> Result { match handle.type_context.type_check_ast(&input) { Ok(ty) => { - comp.map(|comp| comp.add_artifact(TraceArtifact::new("type_check", format!("{:?}", ty)))); + comp.map(|c| c.add_artifact(TraceArtifact::new("type_table", format!("{}", handle.type_context.debug_types())))); + comp.map(|c| c.add_artifact(TraceArtifact::new("type_check", format!("{:?}", ty)))); Ok(input) }, Err(msg) => { + comp.map(|comp| comp.add_artifact(TraceArtifact::new("type_table", format!("{}", handle.type_context.debug_types())))); comp.map(|comp| comp.add_artifact(TraceArtifact::new("type_check", format!("Type error: {:?}", msg)))); Ok(input) } diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index cff850d..af85756 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -2,7 +2,8 @@ use std::rc::Rc; use std::collections::{HashSet, HashMap}; use std::collections::hash_set::Union; use std::iter::Iterator; -//use std::char; +use std::fmt; +use std::fmt::Write; use itertools::Itertools; @@ -151,6 +152,14 @@ impl TypeContext { pub fn new() -> TypeContext { TypeContext { environment: TypeEnvironment::default() } } + + pub fn debug_types(&self) -> String { + let mut output = format!("Type context\n"); + for (sym, ty) in &self.environment.map { + write!(output, "{} -> {:?}\n", sym, ty).unwrap(); + } + output + } pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult { let ref block = ast.0;