From 217ee73fc90a817956f2e8b5d36b8ef0e27aa3d9 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 20 May 2018 23:44:12 -0700 Subject: [PATCH] Literals --- schala-lang/src/typechecking.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index 5e2256f..8e92e92 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -170,7 +170,7 @@ impl<'a> Infer<'a> { let mut ret = MonoType::Const(TypeConst::Unit); for s in block { ret = match s { - parsing::Statement::ExpressionStatement(expr) => self.expression(expr)?, + parsing::Statement::ExpressionStatement(expr) => self.anno_expression(expr)?, parsing::Statement::Declaration(decl) => { self.declaration(decl)?; MonoType::Const(TypeConst::Unit) @@ -184,8 +184,32 @@ impl<'a> Infer<'a> { Ok(MonoType::Const(TypeConst::Unit)) } - fn expression(&mut self, expr: &parsing::Expression) -> InferResult { - Ok(MonoType::Const(TypeConst::Unit)) + fn anno_expression(&mut self, expr: &parsing::Expression) -> InferResult { + match expr { + parsing::Expression(e, Some(anno)) => { + return Err(InferError::Custom(format!("Annotations not done yet"))) + /* + let anno_ty = anno.to_type()?; + let ty = self.infer_exprtype(&e)?; + self.unify(ty, anno_ty) + */ + }, + parsing::Expression(e, None) => self.expression(e) + } + } + + fn expression(&mut self, expr: &parsing::ExpressionType) -> InferResult { + use self::parsing::ExpressionType::*; + Ok(match expr { + NatLiteral(_) => MonoType::Const(TypeConst::Nat), + FloatLiteral(_) => MonoType::Const(TypeConst::Float), + StringLiteral(_) => MonoType::Const(TypeConst::StringT), + BoolLiteral(_) => MonoType::Const(TypeConst::Bool), + Value(v) => { + unimplemented!() + }, + _ => return Err(InferError::Custom(format!("this expression type not done yet"))) + }) } }