From 55e372a670974a28d459f4557269ca232428f191 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 28 Feb 2018 05:45:20 -0800 Subject: [PATCH] Introduced fresh type variable method --- src/schala_lang/typechecking.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/schala_lang/typechecking.rs b/src/schala_lang/typechecking.rs index c89f61d..203a2c9 100644 --- a/src/schala_lang/typechecking.rs +++ b/src/schala_lang/typechecking.rs @@ -4,6 +4,7 @@ use std::collections::HashMap; use schala_lang::parsing; pub struct TypeContext { + type_var_count: u64, bindings: HashMap, Type>, } @@ -11,6 +12,7 @@ pub struct TypeContext { pub enum Type { Const(TConst), Func(Box, Box), + TVar(u64), Void } @@ -48,7 +50,12 @@ pub type TypeResult = Result; impl TypeContext { pub fn new() -> TypeContext { - TypeContext { bindings: HashMap::new() } + TypeContext { bindings: HashMap::new(), type_var_count: 0 } + } + pub fn fresh(&mut self) -> Type { + let ret = self.type_var_count; + self.type_var_count += 1; + Type::TVar(ret) } }