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?
This commit is contained in:
greg 2019-02-27 02:15:19 -08:00
parent d515b1658a
commit 0bcd7e6f41

View File

@ -24,7 +24,6 @@ pub type TypeName = Rc<String>;
pub struct TypeContext<'a> {
variable_map: ScopeStack<'a, Rc<String>, Type>,
unification_table: InPlaceUnificationTable<TypeVar>,
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<String>, 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<Type> {
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