Typecheck values
This commit is contained in:
parent
4a27af2136
commit
33c22c8bbc
@ -14,14 +14,14 @@ use util::StateStack;
|
|||||||
pub type TypeName = Rc<String>;
|
pub type TypeName = Rc<String>;
|
||||||
type TypeResult<T> = Result<T, String>;
|
type TypeResult<T> = Result<T, String>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
enum Type {
|
enum Type {
|
||||||
Const(TConst),
|
Const(TConst),
|
||||||
Var(TypeName),
|
Var(TypeName),
|
||||||
Func(Vec<Type>),
|
Func(Vec<Type>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
enum TConst {
|
enum TConst {
|
||||||
Unit,
|
Unit,
|
||||||
Nat,
|
Nat,
|
||||||
@ -94,6 +94,12 @@ impl<'a> TypeContext<'a> {
|
|||||||
|
|
||||||
return Err(format!("NOTDONE"))
|
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)
|
_ => Type::Const(Unit)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user