Starting work on values

This commit is contained in:
greg 2019-02-12 21:14:13 -08:00
parent 35da1748f0
commit d969d573fa

View File

@ -207,7 +207,6 @@ impl<'a> TypeContext<'a> {
fn typecheck_expr(&mut self, expr: &Expression) -> InferResult<Type> {
match expr {
Expression(expr_type, Some(anno)) => {
//TODO here
let t1 = self.typecheck_expr_type(expr_type)?;
let t2 = self.get_type_from_name(anno)?;
self.unify(t2, t1)
@ -225,6 +224,7 @@ impl<'a> TypeContext<'a> {
StringLiteral(_) => Type::Const(TypeConst::StringT),
PrefixExp(op, expr) => self.typecheck_prefix(op, expr.node())?,
IfExpression { discriminator, body } => self.typecheck_if_expr(discriminator, body)?,
Value(val) => self.handle_value(val)?,
_ => Type::Const(TypeConst::Unit)
})
}
@ -250,6 +250,13 @@ impl<'a> TypeContext<'a> {
Ok(Type::Const(TypeConst::Unit))
}
fn handle_value(&mut self, val: &Rc<String>) -> InferResult<Type> {
match self.variable_map.lookup(val) {
Some(ty) => Ok(ty.clone()),
None => TypeError::new(&format!("Couldn't find variable: {}", val))
}
}
fn unify(&mut self, t1: Type, t2: Type) -> InferResult<Type> {
use self::Type::*; use self::TypeConst::*;
Ok(match (t1, t2) {