Debug types

WIP
This commit is contained in:
greg 2018-05-21 03:09:38 -07:00
parent c986233a95
commit a80db9e4c2
2 changed files with 13 additions and 2 deletions

View File

@ -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<parsing::AST, String> {
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)
}

View File

@ -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<String> {
let ref block = ast.0;