Add binop_hint
This commit is contained in:
parent
c4f78471cd
commit
8954d1a6d0
@ -107,6 +107,16 @@ impl TypeKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn binop_hint(&self, op: &BinaryOperator) -> Option<TypeKind> {
|
||||||
|
match op {
|
||||||
|
BinaryOperator::Add | BinaryOperator::Minus | BinaryOperator::Mult => {
|
||||||
|
Some(self.clone())
|
||||||
|
}
|
||||||
|
BinaryOperator::And => None,
|
||||||
|
BinaryOperator::Cmp(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn signed(&self) -> bool {
|
pub fn signed(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
TypeKind::Bool => false,
|
TypeKind::Bool => false,
|
||||||
|
@ -408,7 +408,11 @@ impl Expression {
|
|||||||
ExprKind::BinOp(op, lhs, rhs) => {
|
ExprKind::BinOp(op, lhs, rhs) => {
|
||||||
// TODO make sure lhs and rhs can actually do this binary
|
// TODO make sure lhs and rhs can actually do this binary
|
||||||
// operation once relevant
|
// operation once relevant
|
||||||
let lhs_res = lhs.typecheck(state, &typerefs, hint_t);
|
let lhs_res = lhs.typecheck(
|
||||||
|
state,
|
||||||
|
&typerefs,
|
||||||
|
hint_t.and_then(|t| t.binop_hint(op)).as_ref(),
|
||||||
|
);
|
||||||
let lhs_type = state.or_else(lhs_res, TypeKind::Vague(Vague::Unknown), lhs.1);
|
let lhs_type = state.or_else(lhs_res, TypeKind::Vague(Vague::Unknown), lhs.1);
|
||||||
let rhs_res = rhs.typecheck(state, &typerefs, Some(&lhs_type));
|
let rhs_res = rhs.typecheck(state, &typerefs, Some(&lhs_type));
|
||||||
let rhs_type = state.or_else(rhs_res, TypeKind::Vague(Vague::Unknown), rhs.1);
|
let rhs_type = state.or_else(rhs_res, TypeKind::Vague(Vague::Unknown), rhs.1);
|
||||||
|
@ -5,5 +5,5 @@ pub fn OneHalf(var1: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() -> bool {
|
pub fn main() -> bool {
|
||||||
return 7.5 > 5.5;
|
return (7.5 > 5.5);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user