Introduced fresh type variable method
This commit is contained in:
parent
c50626241e
commit
55e372a670
@ -4,6 +4,7 @@ use std::collections::HashMap;
|
|||||||
use schala_lang::parsing;
|
use schala_lang::parsing;
|
||||||
|
|
||||||
pub struct TypeContext {
|
pub struct TypeContext {
|
||||||
|
type_var_count: u64,
|
||||||
bindings: HashMap<Rc<String>, Type>,
|
bindings: HashMap<Rc<String>, Type>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ pub struct TypeContext {
|
|||||||
pub enum Type {
|
pub enum Type {
|
||||||
Const(TConst),
|
Const(TConst),
|
||||||
Func(Box<Type>, Box<Type>),
|
Func(Box<Type>, Box<Type>),
|
||||||
|
TVar(u64),
|
||||||
Void
|
Void
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +50,12 @@ pub type TypeResult<T> = Result<T, String>;
|
|||||||
|
|
||||||
impl TypeContext {
|
impl TypeContext {
|
||||||
pub fn new() -> 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user