From 0bcd7e6f41d83a283bf4c68a438daa2365efc759 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 27 Feb 2019 02:15:19 -0800 Subject: [PATCH] Add new_env method This is basically the same as the one on the evaluator and makes use of the ScopeStack - maybe need to generalize this more? --- schala-lang/language/src/typechecking.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index 09e3a24..2dcc082 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -24,7 +24,6 @@ pub type TypeName = Rc; pub struct TypeContext<'a> { variable_map: ScopeStack<'a, Rc, Type>, unification_table: InPlaceUnificationTable, - type_var_count: usize, } /// `InferResult` is the monad in which type inference takes place. @@ -232,10 +231,20 @@ impl<'a> TypeContext<'a> { TypeContext { variable_map: ScopeStack::new(None), unification_table: UnificationTable::new(), - type_var_count: 0, } } + fn new_env(&'a self, new_var: Rc, ty: Type) -> TypeContext<'a> { + let mut new_context = TypeContext { + variable_map: self.variable_map.new_scope(None), + unification_table: UnificationTable::new(), //???? not sure if i want this + }; + + new_context.variable_map.insert(new_var, ty); + new_context + } + + fn get_type_from_name(&self, name: &TypeIdentifier) -> InferResult { use self::TypeIdentifier::*; Ok(match name { @@ -247,7 +256,6 @@ impl<'a> TypeContext<'a> { }, Tuple(_) => return TypeError::new("tuples aren't ready yet"), }) - } /// `typecheck` is the entry into the type-inference system, accepting an AST as an argument