Change around some stuff

This commit is contained in:
greg 2017-10-10 21:23:24 -07:00
parent ff3dbbcbc6
commit b4208b696d
1 changed files with 26 additions and 9 deletions

View File

@ -201,19 +201,36 @@ impl TypeContext {
use self::TypeConst::*; use self::TypeConst::*;
Ok(match (&expr.0, &expr.1) { Ok(match (&expr.0, &expr.1) {
(ref _t, &Some(ref anno)) => { (&IntLiteral(_), anno) => {
self.from_anno(anno)// TODO make this better, match *anno {
None => TConst(Integer),
Some(ref t) => self.from_anno(t)
}
}
(&FloatLiteral(_), anno) => {
match *anno {
None => TConst(Float),
Some(ref t) => self.from_anno(t),
}
}, },
(&IntLiteral(_), _) => TConst(Integer), (&StringLiteral(_), anno) => {
(&FloatLiteral(_), _) => TConst(Float), match *anno {
(&StringLiteral(_), _) => TConst(StringT), None => TConst(StringT),
(&BoolLiteral(_), _) => TConst(Boolean), Some(ref t) => self.from_anno(t),
(&Value(ref name), _) => { }
},
(&BoolLiteral(_), anno) => {
match *anno {
None => TConst(Boolean),
Some(ref t) => self.from_anno(t),
}
},
(&Value(ref name), ref _anno) => {
self.lookup(name) self.lookup(name)
.map(|entry| entry.type_var) .map(|entry| entry.type_var)
.ok_or(format!("Couldn't find {}", name))? .ok_or(format!("Couldn't find {}", name))?
}, },
(&BinExp(ref op, box ref lhs, box ref rhs), _) => { (&BinExp(ref op, box ref lhs, box ref rhs), ref _anno) => {
let op_type = self.infer_op(op)?; let op_type = self.infer_op(op)?;
let lhs_type = self.infer(&lhs)?; let lhs_type = self.infer(&lhs)?;
@ -232,7 +249,7 @@ impl TypeContext {
_ => return Err(format!("Bad type for operator")), _ => return Err(format!("Bad type for operator")),
} }
}, },
(&Call { ref f, ref arguments }, _) => { (&Call { ref f, ref arguments }, ref _anno) => {
let f_type = self.infer(&*f)?; let f_type = self.infer(&*f)?;
let arg_type = self.infer(arguments.get(0).unwrap())?; // TODO fix later let arg_type = self.infer(arguments.get(0).unwrap())?; // TODO fix later
match f_type { match f_type {