From 12f55fa84492a15e09c029a3f021109e50cbebd7 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 21 Feb 2018 18:12:46 -0800 Subject: [PATCH] More static type work --- src/schala_lang/typechecking.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/schala_lang/typechecking.rs b/src/schala_lang/typechecking.rs index 6027c2e..98c122a 100644 --- a/src/schala_lang/typechecking.rs +++ b/src/schala_lang/typechecking.rs @@ -71,8 +71,21 @@ impl TypeContext { } } fn type_from_anno(&mut self, anno: &parsing::TypeName) -> TypeResult { + use self::parsing::{TypeName, TypeSingletonName}; + use self::parsing::TypeName::*; use self::Type::*; use self::TConst::*; - Ok(Unit) + Ok(match anno { + &Tuple(_) => return Err(format!("Tuples not yet implemented")), + &Singleton(ref name) => match name { + &TypeSingletonName { ref name, .. } => match **name { + ref n if n == "Int" => Const(Int), + ref n if n == "Float" => Const(Float), + ref n if n == "Bool" => Const(Bool), + ref n if n == "String" => Const(StringT), + ref n => Const(Custom((format!("{}", n)))) + } + } + }) } fn unify(&mut self, t1: Type, t2: Type) -> TypeResult { use self::Type::*; use self::TConst::*;