From 06e9452718e75427949dac2e34eedd8c88ffb7f9 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 10 Feb 2019 05:15:57 -0800 Subject: [PATCH] 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. --- schala-lang/language/src/typechecking.rs | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index 7396605..e974ca6 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -142,24 +142,35 @@ impl<'a> TypeContext<'a> { } pub fn typecheck(&mut self, ast: &AST) -> Result { + 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 { 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 { + Ok(Type::Const(TypeConst::Unit)) } - fn typecheck_expr(&mut self, expr: &Expression) -> InferResult<()> { - Ok(()) + fn typecheck_expr(&mut self, expr: &Expression) -> InferResult { + 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 { + Ok(Type::Const(TypeConst::Unit)) } }