Even more type work

This commit is contained in:
greg 2018-11-09 00:21:34 -08:00
parent d44bb02d61
commit e39356c0e5
1 changed files with 30 additions and 5 deletions

View File

@ -24,7 +24,8 @@ impl TypeError {
enum MonoType {
Var(Rc<String>),
Const(TConst),
Arrow(Box<MonoType>, Box<MonoType>)
Arrow(Box<MonoType>, Box<MonoType>),
ExistentialVar(u32)
}
impl TypeIdentifier {
@ -87,14 +88,18 @@ impl<'a> TypeContext<'a> {
fn infer_ast(&mut self, ast: &AST) -> InferResult<MonoType> {
let mut output = MonoType::Const(TConst::Unit);
for statement in ast.0.iter() {
output = match statement {
Statement::ExpressionStatement(ref expr) => self.infer_expr(expr)?,
Statement::Declaration(ref decl) => self.infer_decl(decl)?,
};
output = self.infer_statement(statement)?;
}
Ok(output)
}
fn infer_statement(&mut self, stmt: &Statement) -> InferResult<MonoType> {
match stmt {
Statement::ExpressionStatement(ref expr) => self.infer_expr(expr),
Statement::Declaration(ref decl) => self.infer_decl(decl),
}
}
fn infer_expr(&mut self, expr: &Expression) -> InferResult<MonoType> {
match expr {
Expression(expr_type, Some(type_anno)) => {
@ -137,6 +142,14 @@ impl<'a> TypeContext<'a> {
_ => return TypeError::new("not a function")
}
},
Lambda { params, type_anno, body } => {
let arg_type = unimplemented!();
let result_type = unimplemented!();
MonoType::Arrow(Box::new(arg_type), Box::new(result_type))
}
_ => MonoType::Const(TConst::user("unimplemented"))
})
}
@ -155,9 +168,21 @@ impl<'a> TypeContext<'a> {
unimplemented!()
}
fn infer_block(&mut self, block: &Block) -> InferResult<MonoType> {
let mut output = MonoType::Const(TConst::Unit);
for statement in block.iter() {
output = self.infer_statement(statement)?;
}
Ok(output)
}
fn unify(&mut self, t1: &MonoType, t2: &MonoType) -> InferResult<MonoType> {
unimplemented!()
}
fn allocate_existential(&mut self) -> MonoType {
MonoType::ExistentialVar(0)
}
}
#[cfg(test)]