Even more type work
This commit is contained in:
parent
d44bb02d61
commit
e39356c0e5
@ -24,7 +24,8 @@ impl TypeError {
|
|||||||
enum MonoType {
|
enum MonoType {
|
||||||
Var(Rc<String>),
|
Var(Rc<String>),
|
||||||
Const(TConst),
|
Const(TConst),
|
||||||
Arrow(Box<MonoType>, Box<MonoType>)
|
Arrow(Box<MonoType>, Box<MonoType>),
|
||||||
|
ExistentialVar(u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypeIdentifier {
|
impl TypeIdentifier {
|
||||||
@ -87,14 +88,18 @@ impl<'a> TypeContext<'a> {
|
|||||||
fn infer_ast(&mut self, ast: &AST) -> InferResult<MonoType> {
|
fn infer_ast(&mut self, ast: &AST) -> InferResult<MonoType> {
|
||||||
let mut output = MonoType::Const(TConst::Unit);
|
let mut output = MonoType::Const(TConst::Unit);
|
||||||
for statement in ast.0.iter() {
|
for statement in ast.0.iter() {
|
||||||
output = match statement {
|
output = self.infer_statement(statement)?;
|
||||||
Statement::ExpressionStatement(ref expr) => self.infer_expr(expr)?,
|
|
||||||
Statement::Declaration(ref decl) => self.infer_decl(decl)?,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
Ok(output)
|
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> {
|
fn infer_expr(&mut self, expr: &Expression) -> InferResult<MonoType> {
|
||||||
match expr {
|
match expr {
|
||||||
Expression(expr_type, Some(type_anno)) => {
|
Expression(expr_type, Some(type_anno)) => {
|
||||||
@ -137,6 +142,14 @@ impl<'a> TypeContext<'a> {
|
|||||||
_ => return TypeError::new("not a function")
|
_ => 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"))
|
_ => MonoType::Const(TConst::user("unimplemented"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -155,9 +168,21 @@ impl<'a> TypeContext<'a> {
|
|||||||
unimplemented!()
|
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> {
|
fn unify(&mut self, t1: &MonoType, t2: &MonoType) -> InferResult<MonoType> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn allocate_existential(&mut self) -> MonoType {
|
||||||
|
MonoType::ExistentialVar(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user