Starting work on values
This commit is contained in:
parent
35da1748f0
commit
d969d573fa
@ -207,7 +207,6 @@ impl<'a> TypeContext<'a> {
|
|||||||
fn typecheck_expr(&mut self, expr: &Expression) -> InferResult<Type> {
|
fn typecheck_expr(&mut self, expr: &Expression) -> InferResult<Type> {
|
||||||
match expr {
|
match expr {
|
||||||
Expression(expr_type, Some(anno)) => {
|
Expression(expr_type, Some(anno)) => {
|
||||||
//TODO here
|
|
||||||
let t1 = self.typecheck_expr_type(expr_type)?;
|
let t1 = self.typecheck_expr_type(expr_type)?;
|
||||||
let t2 = self.get_type_from_name(anno)?;
|
let t2 = self.get_type_from_name(anno)?;
|
||||||
self.unify(t2, t1)
|
self.unify(t2, t1)
|
||||||
@ -225,6 +224,7 @@ impl<'a> TypeContext<'a> {
|
|||||||
StringLiteral(_) => Type::Const(TypeConst::StringT),
|
StringLiteral(_) => Type::Const(TypeConst::StringT),
|
||||||
PrefixExp(op, expr) => self.typecheck_prefix(op, expr.node())?,
|
PrefixExp(op, expr) => self.typecheck_prefix(op, expr.node())?,
|
||||||
IfExpression { discriminator, body } => self.typecheck_if_expr(discriminator, body)?,
|
IfExpression { discriminator, body } => self.typecheck_if_expr(discriminator, body)?,
|
||||||
|
Value(val) => self.handle_value(val)?,
|
||||||
_ => Type::Const(TypeConst::Unit)
|
_ => Type::Const(TypeConst::Unit)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -250,6 +250,13 @@ impl<'a> TypeContext<'a> {
|
|||||||
Ok(Type::Const(TypeConst::Unit))
|
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> {
|
fn unify(&mut self, t1: Type, t2: Type) -> InferResult<Type> {
|
||||||
use self::Type::*; use self::TypeConst::*;
|
use self::Type::*; use self::TypeConst::*;
|
||||||
Ok(match (t1, t2) {
|
Ok(match (t1, t2) {
|
||||||
|
Loading…
Reference in New Issue
Block a user