This commit is contained in:
greg 2018-05-15 21:53:50 -07:00
parent 276662d98a
commit b0e38f7f5b

View File

@ -45,7 +45,6 @@ pub enum Type {
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct TVar(String); pub struct TVar(String);
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub enum TConst { pub enum TConst {
Unit, Unit,
@ -186,17 +185,23 @@ impl TypeContext {
} }
output output
} }
pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult<Type> {
let ref block = ast.0;
Ok(self.type_check_block(block)?)
}
} }
impl TypeContext { impl TypeContext {
pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult<Type> {
use self::Type::*; use self::TConst::*; fn type_check_block(&mut self, statements: &Vec<parsing::Statement>) -> TypeResult<Type> {
let mut ret_type = Const(Unit); let mut ret_type = Type::Const(TConst::Unit);
for statement in ast.0.iter() { for statement in statements {
ret_type = self.type_check_statement(statement)?; ret_type = self.type_check_statement(statement)?;
} }
Ok(ret_type) Ok(ret_type)
} }
fn type_check_statement(&mut self, statement: &parsing::Statement) -> TypeResult<Type> { fn type_check_statement(&mut self, statement: &parsing::Statement) -> TypeResult<Type> {
use self::parsing::Statement::*; use self::parsing::Statement::*;
match statement { match statement {