mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add binop impls for TyBool
This commit is contained in:
parent
7862e2ea1c
commit
ab00acfb55
25
mini_core.rs
25
mini_core.rs
@ -8,6 +8,7 @@ pub trait Sized {}
|
||||
#[lang="copy"]
|
||||
pub unsafe trait Copy {}
|
||||
|
||||
unsafe impl Copy for bool {}
|
||||
unsafe impl Copy for u8 {}
|
||||
unsafe impl Copy for u16 {}
|
||||
unsafe impl Copy for u32 {}
|
||||
@ -40,6 +41,30 @@ impl Mul for u8 {
|
||||
}
|
||||
}
|
||||
|
||||
#[lang="bitor"]
|
||||
pub trait BitOr<RHS = Self> {
|
||||
type Output;
|
||||
|
||||
#[must_use]
|
||||
fn bitor(self, rhs: RHS) -> Self::Output;
|
||||
}
|
||||
|
||||
impl BitOr for bool {
|
||||
type Output = bool;
|
||||
|
||||
fn bitor(self, rhs: bool) -> bool {
|
||||
self | rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> BitOr<bool> for &'a bool {
|
||||
type Output = bool;
|
||||
|
||||
fn bitor(self, rhs: bool) -> bool {
|
||||
*self | rhs
|
||||
}
|
||||
}
|
||||
|
||||
#[lang = "eq"]
|
||||
pub trait PartialEq<Rhs: ?Sized = Self> {
|
||||
fn eq(&self, other: &Rhs) -> bool;
|
||||
|
30
src/base.rs
30
src/base.rs
@ -242,6 +242,9 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, cur_ebb: Ebb, stmt: &
|
||||
let rhs = trans_operand(fx, rhs).load_value(fx);
|
||||
|
||||
let res = match ty.sty {
|
||||
TypeVariants::TyBool => {
|
||||
trans_bool_binop(fx, *bin_op, lhs, rhs, lval.layout().ty)
|
||||
}
|
||||
TypeVariants::TyUint(_) => {
|
||||
trans_int_binop(fx, *bin_op, lhs, rhs, lval.layout().ty, false, false)
|
||||
}
|
||||
@ -426,6 +429,33 @@ macro_rules! binop_match {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trans_bool_binop<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, bin_op: BinOp, lhs: Value, rhs: Value, ty: Ty<'tcx>) -> CValue<'tcx> {
|
||||
let res = binop_match! {
|
||||
fx, bin_op, false, lhs, rhs, "bool";
|
||||
Add (_) bug;
|
||||
Sub (_) bug;
|
||||
Mul (_) bug;
|
||||
Div (_) bug;
|
||||
Rem (_) bug;
|
||||
BitXor (_) bxor;
|
||||
BitAnd (_) band;
|
||||
BitOr (_) bor;
|
||||
Shl (_) bug;
|
||||
Shr (_) bug;
|
||||
|
||||
Eq (_) icmp(Equal);
|
||||
Lt (_) icmp(UnsignedLessThan);
|
||||
Le (_) icmp(UnsignedLessThanOrEqual);
|
||||
Ne (_) icmp(NotEqual);
|
||||
Ge (_) icmp(UnsignedGreaterThanOrEqual);
|
||||
Gt (_) icmp(UnsignedGreaterThan);
|
||||
|
||||
Offset (_) bug;
|
||||
};
|
||||
|
||||
CValue::ByVal(res, fx.layout_of(ty))
|
||||
}
|
||||
|
||||
pub fn trans_int_binop<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, bin_op: BinOp, lhs: Value, rhs: Value, ty: Ty<'tcx>, signed: bool, _checked: bool) -> CValue<'tcx> {
|
||||
let res = binop_match! {
|
||||
fx, bin_op, signed, lhs, rhs, "int/uint";
|
||||
|
Loading…
Reference in New Issue
Block a user