From 93309c025ea38c5e01d7680e7a4426aa925c4515 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 20 May 2018 23:14:25 -0700 Subject: [PATCH] Some work --- schala-lang/src/typechecking.rs | 36 +++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index e832dfb..5e2256f 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -143,14 +143,11 @@ impl TypeContext { pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult { let ref block = ast.0; let mut infer = Infer { env: &mut self.environment }; - /* - let output = infer.infer_block(block, &env); + let output = infer.block(block); match output { Ok(s) => Ok(format!("{:?}", s)), Err(s) => Err(format!("Error: {:?}", s)) } - */ - Ok(format!("SUCKA")) } } @@ -158,8 +155,39 @@ struct Infer<'a> { env: &'a TypeEnvironment } +#[derive(Debug)] +enum InferError { + CannotUnify(MonoType, MonoType), + OccursCheckFailed(TypeName, MonoType), + UnknownIdentifier(TypeName), + Custom(String), +} +type InferResult = Result; +impl<'a> Infer<'a> { + fn block(&mut self, block: &Vec) -> InferResult { + let mut ret = MonoType::Const(TypeConst::Unit); + for s in block { + ret = match s { + parsing::Statement::ExpressionStatement(expr) => self.expression(expr)?, + parsing::Statement::Declaration(decl) => { + self.declaration(decl)?; + MonoType::Const(TypeConst::Unit) + } + } + } + Ok(ret) + } + + fn declaration(&mut self, expr: &parsing::Declaration) -> InferResult { + Ok(MonoType::Const(TypeConst::Unit)) + } + + fn expression(&mut self, expr: &parsing::Expression) -> InferResult { + Ok(MonoType::Const(TypeConst::Unit)) + } +} /* TODO this should just check the name against a map, and that map should be pre-populated with * types */