More type infrastructure
From here on out, I can start playing with concrete code that attempts to actually typecheck limited syntactic constructs, and see what I end up with.
This commit is contained in:
parent
7d3ae36058
commit
06e9452718
@ -142,24 +142,35 @@ impl<'a> TypeContext<'a> {
|
||||
}
|
||||
|
||||
pub fn typecheck(&mut self, ast: &AST) -> Result<String, String> {
|
||||
let mut returned_type = Type::Const(TypeConst::Unit);
|
||||
for statement in ast.0.iter() {
|
||||
self.typecheck_statement(statement.node()).map_err(|err| { err.msg })?
|
||||
returned_type = self.typecheck_statement(statement.node()).map_err(|err| { err.msg })?
|
||||
}
|
||||
Ok("unknown type".to_string())
|
||||
Ok(format!("{:?}", returned_type))
|
||||
}
|
||||
|
||||
fn typecheck_statement(&mut self, statement: &Statement) -> InferResult<()> {
|
||||
fn typecheck_statement(&mut self, statement: &Statement) -> InferResult<Type> {
|
||||
match statement {
|
||||
Statement::ExpressionStatement(e) => self.typecheck_expr(e.node()),
|
||||
Statement::Declaration(decl) => self.typecheck_decl(decl),
|
||||
}
|
||||
}
|
||||
|
||||
fn typecheck_decl(&mut self, decl: &Declaration) -> InferResult<()> {
|
||||
Ok(())
|
||||
fn typecheck_decl(&mut self, decl: &Declaration) -> InferResult<Type> {
|
||||
Ok(Type::Const(TypeConst::Unit))
|
||||
}
|
||||
|
||||
fn typecheck_expr(&mut self, expr: &Expression) -> InferResult<()> {
|
||||
Ok(())
|
||||
fn typecheck_expr(&mut self, expr: &Expression) -> InferResult<Type> {
|
||||
match expr {
|
||||
Expression(expr_type, Some(_anno)) => {
|
||||
//TODO here
|
||||
self.typecheck_expr_type(expr_type)
|
||||
},
|
||||
Expression(expr_type, None) => self.typecheck_expr_type(expr_type)
|
||||
}
|
||||
}
|
||||
|
||||
fn typecheck_expr_type(&mut self, expr: &ExpressionType) -> InferResult<Type> {
|
||||
Ok(Type::Const(TypeConst::Unit))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user