From e39356c0e5ef36e77b8111f769960506dcc5ab24 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 9 Nov 2018 00:21:34 -0800 Subject: [PATCH] Even more type work --- schala-lang/language/src/typechecking.rs | 35 ++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index 394f937..5c5e314 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -24,7 +24,8 @@ impl TypeError { enum MonoType { Var(Rc), Const(TConst), - Arrow(Box, Box) + Arrow(Box, Box), + ExistentialVar(u32) } impl TypeIdentifier { @@ -87,14 +88,18 @@ impl<'a> TypeContext<'a> { fn infer_ast(&mut self, ast: &AST) -> InferResult { 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 { + 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 { 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 { + 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 { unimplemented!() } + + fn allocate_existential(&mut self) -> MonoType { + MonoType::ExistentialVar(0) + } } #[cfg(test)]