Debug types
WIP
This commit is contained in:
parent
c986233a95
commit
a80db9e4c2
@ -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> {
|
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(|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)
|
Ok(input)
|
||||||
},
|
},
|
||||||
Err(msg) => {
|
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))));
|
comp.map(|comp| comp.add_artifact(TraceArtifact::new("type_check", format!("Type error: {:?}", msg))));
|
||||||
Ok(input)
|
Ok(input)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@ use std::rc::Rc;
|
|||||||
use std::collections::{HashSet, HashMap};
|
use std::collections::{HashSet, HashMap};
|
||||||
use std::collections::hash_set::Union;
|
use std::collections::hash_set::Union;
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
//use std::char;
|
use std::fmt;
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
@ -152,6 +153,14 @@ impl TypeContext {
|
|||||||
TypeContext { environment: TypeEnvironment::default() }
|
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> {
|
pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult<String> {
|
||||||
let ref block = ast.0;
|
let ref block = ast.0;
|
||||||
let output = {
|
let output = {
|
||||||
|
Loading…
Reference in New Issue
Block a user