Convert type-checking function type
This commit is contained in:
parent
3a97401f61
commit
e412fb9a89
@ -5,7 +5,7 @@ mod parsing;
|
|||||||
mod type_check;
|
mod type_check;
|
||||||
mod eval;
|
mod eval;
|
||||||
|
|
||||||
use self::type_check::{TypeContext, TypeCheckResult};
|
use self::type_check::{TypeContext};
|
||||||
|
|
||||||
pub struct Schala {
|
pub struct Schala {
|
||||||
state: eval::ReplState,
|
state: eval::ReplState,
|
||||||
@ -63,9 +63,9 @@ impl ProgrammingLanguageInterface for Schala {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match self.type_context.type_check(&ast) {
|
match self.type_context.type_check(&ast) {
|
||||||
TypeCheckResult::OK => (),
|
Ok(t) => (),
|
||||||
TypeCheckResult::Error(s) => {
|
Err(msg) => {
|
||||||
output.add_artifact(TraceArtifact::new("type_check", s));
|
output.add_artifact(TraceArtifact::new("type_check", msg));
|
||||||
output.add_output(format!("Type error"));
|
output.add_output(format!("Type error"));
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -22,16 +22,11 @@ impl TypeContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum TypeCheckResult {
|
pub struct SchalaType {
|
||||||
OK,
|
|
||||||
Error(String)
|
|
||||||
}
|
|
||||||
impl TypeCheckResult {
|
|
||||||
fn new(msg: &str) -> TypeCheckResult {
|
|
||||||
TypeCheckResult::Error(msg.to_string())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TypeCheckResult = Result<SchalaType, String>;
|
||||||
|
|
||||||
// from Niko's talk
|
// from Niko's talk
|
||||||
/* fn type_check(expression, expected_ty) -> Ty {
|
/* fn type_check(expression, expected_ty) -> Ty {
|
||||||
let ty = bare_type_check(expression, expected_type);
|
let ty = bare_type_check(expression, expected_type);
|
||||||
@ -53,14 +48,14 @@ impl TypeContext {
|
|||||||
for statement in ast.0.iter() {
|
for statement in ast.0.iter() {
|
||||||
match statement {
|
match statement {
|
||||||
&Statement::Declaration(ref _decl) => {
|
&Statement::Declaration(ref _decl) => {
|
||||||
return TypeCheckResult::new("Declarations not supported");
|
return Err(format!("Declarations not supported"));
|
||||||
},
|
},
|
||||||
&Statement::ExpressionStatement(ref expr) => {
|
&Statement::ExpressionStatement(ref expr) => {
|
||||||
match (&expr.0, &expr.1) {
|
match (&expr.0, &expr.1) {
|
||||||
(&IntLiteral(_), &Some(ref t)) => {
|
(&IntLiteral(_), &Some(ref t)) => {
|
||||||
match t {
|
match t {
|
||||||
&TypeAnno::Singleton { ref name, ref params } if **name == "Int" && params.len() == 0 => (),
|
&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 { })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user