From 33c22c8bbc7b9ccb50dc6092ab65819a3795f530 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 29 May 2018 00:57:27 -0700 Subject: [PATCH] Typecheck values --- schala-lang/src/typechecking.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index 9996d8a..dac6ca4 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -14,14 +14,14 @@ use util::StateStack; pub type TypeName = Rc; type TypeResult = Result; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] enum Type { Const(TConst), Var(TypeName), Func(Vec), } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] enum TConst { Unit, Nat, @@ -94,6 +94,12 @@ impl<'a> TypeContext<'a> { return Err(format!("NOTDONE")) }, + Value(name) => { + match self.values.lookup(name) { + Some(ty) => ty.clone(), + None => return Err(format!("Unknown variable: {}", name)) + } + }, _ => Type::Const(Unit) }) }