Skip to main content

BinaryOperator

Enum BinaryOperator 

Source
pub enum BinaryOperator {
Show 36 variants Mul, Div, SignedDiv, Mod, SignedMod, FloatDiv, FloatMul, Add, Sub, FloatAdd, FloatSub, LeftShift, RightShift, SignedRightShift, SignedLessThan, SignedGreaterThan, SignedLessEqual, SignedGreaterEqual, LessEqual, GreaterEqual, LessThan, GreaterThan, FloatLessEqual, FloatGreaterEqual, FloatLessThan, FloatGreaterThan, Equal, NotEqual, FloatEqual, FloatNotEqual, LogicalXor, LogicalAnd, LogicalOr, BitwiseXor, BitwiseOr, BitwiseAnd,
}
Expand description

An infix operator in a p-code expression.

Unless a variant says otherwise, both operands and the result are the same width, and arithmetic wraps rather than trapping. The comparisons are the exception: they yield one byte holding 0 or 1, whatever their operands’ width. Self::is_comparison and its siblings classify a variant without having to match all thirty-six.

Variants§

§

Mul

* — multiplication. The low half of the product, so the same for signed and unsigned operands.

§

Div

/ — unsigned division.

§

SignedDiv

s/ — signed division, truncating towards zero.

§

Mod

% — unsigned remainder.

§

SignedMod

s% — signed remainder, taking its sign from the dividend.

§

FloatDiv

f/ — floating-point division.

§

FloatMul

f* — floating-point multiplication.

§

Add

+ — addition. Two’s-complement, so the same for signed and unsigned operands; a carry or overflow flag is computed separately, with Builtin::Carry or Builtin::Sborrow.

§

Sub

- — subtraction, likewise sign-agnostic.

§

FloatAdd

f+ — floating-point addition.

§

FloatSub

f- — floating-point subtraction.

§

LeftShift

<< — left shift. Bits shifted off the top are discarded.

§

RightShift

>> — logical right shift, shifting in zeroes.

§

SignedRightShift

s>> — arithmetic right shift, shifting in copies of the sign bit.

§

SignedLessThan

s< — signed less-than.

§

SignedGreaterThan

s> — signed greater-than.

§

SignedLessEqual

s<= — signed less-than-or-equal.

§

SignedGreaterEqual

s>= — signed greater-than-or-equal.

§

LessEqual

<= — unsigned less-than-or-equal.

§

GreaterEqual

>= — unsigned greater-than-or-equal.

§

LessThan

< — unsigned less-than.

§

GreaterThan

> — unsigned greater-than.

§

FloatLessEqual

f<= — floating-point less-than-or-equal.

§

FloatGreaterEqual

f>= — floating-point greater-than-or-equal.

§

FloatLessThan

f< — floating-point less-than.

§

FloatGreaterThan

f> — floating-point greater-than.

§

Equal

== — bitwise equality. Sign-agnostic, since two’s-complement equality is bit equality.

§

NotEqual

!= — bitwise inequality.

§

FloatEqual

f== — floating-point equality, which is not bit equality: NaN compares unequal to itself, and the two zeroes compare equal.

§

FloatNotEqual

f!= — floating-point inequality.

§

LogicalXor

^^ — boolean exclusive-or. Operands are read as false when zero and true otherwise; the result is one byte.

§

LogicalAnd

&& — boolean and. One byte, and not short-circuiting: p-code has no control flow inside an expression, so both operands are evaluated.

§

LogicalOr

|| — boolean or, likewise one byte and not short-circuiting.

§

BitwiseXor

^ — bitwise exclusive-or, in the width of the operands.

§

BitwiseOr

| — bitwise or.

§

BitwiseAnd

& — bitwise and.

Implementations§

Source§

impl BinaryOperator

Source

pub fn is_comparison(self) -> bool

Does this operator yield a one-byte boolean rather than a value in the width of its operands?

Source

pub fn is_shift(self) -> bool

Is this a shift, whose right operand is a distance rather than a value of the same width?

Source

pub fn is_signed_comparison(self) -> bool

Is this one of the four comparisons that read their operands as two’s-complement signed integers?

Source

pub fn is_float_comparison(self) -> bool

Is this one of the six comparisons that read their operands as floating-point?

Source

pub fn is_float(self) -> bool

Does this operator read its operands as floating-point, whether it compares them or computes with them?

Source

pub fn is_logical(self) -> bool

Is this a boolean connective (&&, ||, ^^) rather than a bitwise one? Both operands and the result are truth values, one byte wide.

Source

pub fn is_signed_integer(self) -> bool

Does this operator read its operands as two’s-complement signed integers? Covers the signed comparisons plus s/, s% and s>>.

Source

pub fn pretty_print(self) -> &'static str

Trait Implementations§

Source§

impl Clone for BinaryOperator

Source§

fn clone(&self) -> BinaryOperator

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BinaryOperator

Source§

impl Debug for BinaryOperator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for BinaryOperator

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for BinaryOperator

Source§

impl Hash for BinaryOperator

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for BinaryOperator

Source§

fn eq(&self, other: &BinaryOperator) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for BinaryOperator

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for BinaryOperator

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.