From fab3fb8ec2cc1e1ca9e8bb6d185dd3f5341c57c9 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 7 Nov 2018 16:39:32 -0800 Subject: [PATCH] More basic types + test --- schala-lang/language/src/typechecking.rs | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index 5f287f3..bf6a56a 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -25,7 +25,9 @@ enum TConst { User(Rc), Unit, Nat, - Int + Int, + Float, + StringT, } impl TConst { @@ -80,6 +82,8 @@ impl TypeContext { use self::ExpressionType::*; match expr_type { NatLiteral(_) => Ok(MonoType::Const(TConst::Nat)), + FloatLiteral(_) => Ok(MonoType::Const(TConst::Float)), + StringLiteral(_) => Ok(MonoType::Const(TConst::StringT)), _ => Ok(MonoType::Const(TConst::user("unimplemented"))) } } @@ -88,6 +92,26 @@ impl TypeContext { #[cfg(test)] mod tests { use super::*; + + fn parse(input: &str) -> AST { + let tokens: Vec<::tokenizing::Token> = ::tokenizing::tokenize(input); + let mut parser = ::parsing::Parser::new(tokens); + parser.parse().unwrap() + } + + macro_rules! type_test { + ($input:expr, $correct:expr) => { + { + let mut tc = TypeContext::new(); + let ast = parse($input); + tc.add_symbols(&ast); + assert_eq!($correct, tc.type_check(&ast).unwrap()) + } + } + } + + + #[test] fn basic_inference() {