From 020819550b7b97db25c26c6d30230163e3c27b6b Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 6 Nov 2018 16:47:34 -0800 Subject: [PATCH] More typechecking infrastructure --- schala-lang/language/src/typechecking.rs | 33 +++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index 5efa99a..a87bb13 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -1,6 +1,6 @@ use std::rc::Rc; -use ast::AST; +use ast::*; pub type TypeName = Rc; @@ -8,12 +8,39 @@ pub struct TypeContext { } +type TypeResult = Result; + +#[derive(Debug, Clone)] +struct TypeError { } + +struct Type { + +} + impl TypeContext { pub fn new() -> TypeContext { TypeContext { } } - pub fn typecheck(&mut self, _ast: &AST) -> Result<(), String> { - Ok(()) + pub fn typecheck(&mut self, ast: &AST) -> Result<(), String> { + match self.infer_ast(ast) { + Ok(_) => Ok(()), + Err(err) => Err(format!("Type error: {:?}", err)) + } + } +} + +impl TypeContext { + fn infer_ast(&mut self, ast: &AST) -> TypeResult<()> { + unimplemented!() + } +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn basic_inference() { + } }