feat: add floats

This commit is contained in:
2026-04-22 22:21:26 +02:00
parent c2fc11bbeb
commit e66a4ee736
14 changed files with 471 additions and 66 deletions
+15
View File
@@ -94,6 +94,7 @@ fn evaluate_unary(op: UnaryOp, val: &ConstantValue) -> Option<ConstantValue> {
(UnaryOp::Neg, ConstantValue::Integer(v, ty)) => {
Some(ConstantValue::Integer(v.wrapping_neg(), ty.clone()))
}
(UnaryOp::Neg, ConstantValue::Float(v, ty)) => Some(ConstantValue::Float(-v, ty.clone())),
(UnaryOp::Not, ConstantValue::Boolean(b)) => Some(ConstantValue::Boolean(!b)),
_ => None,
}
@@ -165,6 +166,20 @@ fn evaluate_binary(
_ => None,
},
(ConstantValue::Float(l, ty), ConstantValue::Float(r, _)) => match op {
BinaryOp::Add => Some(ConstantValue::Float(l + r, ty.clone())),
BinaryOp::Sub => Some(ConstantValue::Float(l - r, ty.clone())),
BinaryOp::Mul => Some(ConstantValue::Float(l * r, ty.clone())),
BinaryOp::Div => Some(ConstantValue::Float(l / r, ty.clone())),
BinaryOp::Rem => Some(ConstantValue::Float(l % r, ty.clone())),
BinaryOp::Eq => Some(ConstantValue::Boolean(l == r)),
BinaryOp::Neq => Some(ConstantValue::Boolean(l != r)),
BinaryOp::Lt => Some(ConstantValue::Boolean(l < r)),
BinaryOp::Le => Some(ConstantValue::Boolean(l <= r)),
BinaryOp::Gt => Some(ConstantValue::Boolean(l > r)),
BinaryOp::Ge => Some(ConstantValue::Boolean(l >= r)),
},
_ => None,
}
}