From 7d3ae360588ac67cdbf7e02091c8aec015ea8408 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 10 Feb 2019 04:42:30 -0800 Subject: [PATCH] AST-walking infrastructure --- schala-lang/language/src/typechecking.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index fd5787a..7396605 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -142,6 +142,24 @@ impl<'a> TypeContext<'a> { } pub fn typecheck(&mut self, ast: &AST) -> Result { - Ok(format!("UNIT")) + for statement in ast.0.iter() { + self.typecheck_statement(statement.node()).map_err(|err| { err.msg })? + } + Ok("unknown type".to_string()) + } + + fn typecheck_statement(&mut self, statement: &Statement) -> InferResult<()> { + 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_expr(&mut self, expr: &Expression) -> InferResult<()> { + Ok(()) } }