pub struct IntOp(/* private fields */);Expand description
An integer type plus the complete policy set: the modifier byte of every integer instruction that computes an integer.
Layout: bits 0–2 the IntTy code, bits 3–7 the Policy.
§Examples
use bytecode_lang::{IntOp, IntTy, Overflow, Policy};
let op = IntOp::new(IntTy::I64).with_policy(Policy::new().with_overflow(Overflow::Wrap));
assert_eq!(op.ty(), IntTy::I64);
assert_eq!(op.policy().overflow(), Overflow::Wrap);
assert_eq!(op.to_string(), "i64.wrap");
assert_eq!(IntOp::from_bits(op.bits()), Some(op));Implementations§
Source§impl IntOp
impl IntOp
Sourcepub const fn new(ty: IntTy) -> Self
pub const fn new(ty: IntTy) -> Self
An operation at ty with the default (all-error) policy.
§Examples
use bytecode_lang::{IntOp, IntTy};
assert_eq!(IntOp::new(IntTy::U8).to_string(), "u8");Sourcepub const fn with_policy(self, policy: Policy) -> Self
pub const fn with_policy(self, policy: Policy) -> Self
This operation with its policy replaced.
§Examples
use bytecode_lang::{IntOp, IntTy, Policy, Shift};
let op = IntOp::new(IntTy::I32).with_policy(Policy::new().with_shift(Shift::Mask));
assert_eq!(op.to_string(), "i32.mask");Sourcepub const fn ty(self) -> IntTy
pub const fn ty(self) -> IntTy
The integer type.
§Examples
use bytecode_lang::{IntOp, IntTy};
assert_eq!(IntOp::new(IntTy::U64).ty(), IntTy::U64);Sourcepub const fn policy(self) -> Policy
pub const fn policy(self) -> Policy
The policy set.
§Examples
use bytecode_lang::{IntOp, IntTy, Policy};
assert_eq!(IntOp::new(IntTy::I8).policy(), Policy::new());Sourcepub const fn bits(self) -> u8
pub const fn bits(self) -> u8
The packed byte.
§Examples
use bytecode_lang::{IntOp, IntTy};
assert_eq!(IntOp::new(IntTy::I64).bits(), 3);Sourcepub const fn from_bits(bits: u8) -> Option<Self>
pub const fn from_bits(bits: u8) -> Option<Self>
Unpacks the byte. Every byte is an integer type plus a policy, so this
returns Some for all 256 values in format version 1; the Option
leaves room for reserved bits in a later version.
§Examples
use bytecode_lang::{IntOp, IntTy, Overflow};
let op = IntOp::from_bits(0b0001_1011).unwrap(); // i64, overflow = promote
assert_eq!((op.ty(), op.policy().overflow()), (IntTy::I64, Overflow::Promote));Trait Implementations§
impl Copy for IntOp
impl Eq for IntOp
Source§impl Ord for IntOp
impl Ord for IntOp
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for IntOp
impl PartialOrd for IntOp
impl StructuralPartialEq for IntOp
Auto Trait Implementations§
impl Freeze for IntOp
impl RefUnwindSafe for IntOp
impl Send for IntOp
impl Sync for IntOp
impl Unpin for IntOp
impl UnsafeUnpin for IntOp
impl UnwindSafe for IntOp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more