Convert type-checking function type

This commit is contained in:
greg 2017-10-07 22:08:48 -07:00
parent 3a97401f61
commit e412fb9a89
2 changed files with 10 additions and 15 deletions

View File

@ -5,7 +5,7 @@ mod parsing;
mod type_check;
mod eval;
use self::type_check::{TypeContext, TypeCheckResult};
use self::type_check::{TypeContext};
pub struct Schala {
state: eval::ReplState,
@ -63,9 +63,9 @@ impl ProgrammingLanguageInterface for Schala {
};
match self.type_context.type_check(&ast) {
TypeCheckResult::OK => (),
TypeCheckResult::Error(s) => {
output.add_artifact(TraceArtifact::new("type_check", s));
Ok(t) => (),
Err(msg) => {
output.add_artifact(TraceArtifact::new("type_check", msg));
output.add_output(format!("Type error"));
return output;
}

View File

@ -22,16 +22,11 @@ impl TypeContext {
}
}
pub enum TypeCheckResult {
OK,
Error(String)
}
impl TypeCheckResult {
fn new(msg: &str) -> TypeCheckResult {
TypeCheckResult::Error(msg.to_string())
}
pub struct SchalaType {
}
type TypeCheckResult = Result<SchalaType, String>;
// from Niko's talk
/* fn type_check(expression, expected_ty) -> Ty {
let ty = bare_type_check(expression, expected_type);
@ -53,14 +48,14 @@ impl TypeContext {
for statement in ast.0.iter() {
match statement {
&Statement::Declaration(ref _decl) => {
return TypeCheckResult::new("Declarations not supported");
return Err(format!("Declarations not supported"));
},
&Statement::ExpressionStatement(ref expr) => {
match (&expr.0, &expr.1) {
(&IntLiteral(_), &Some(ref t)) => {
match t {
&TypeAnno::Singleton { ref name, ref params } if **name == "Int" && params.len() == 0 => (),
t => return TypeCheckResult::new(&format!("Bad type {:?} for int literal", t)),
t => return Err(format!("Bad type {:?} for int literal", t)),
}
},
_ => (),
@ -68,6 +63,6 @@ impl TypeContext {
}
}
}
TypeCheckResult::OK
Ok(SchalaType { })
}
}