pub struct IntOp(/* private fields */);Expand description
An integer type plus the policies integer arithmetic consults: the modifier byte of every typed integer instruction that computes an integer.
Layout: bits 0–2 the IntTy code, bits 3–4 Overflow, bit 5
DivZero, bits 6–7 Shift (the value 3 is reserved). The
float_to_int policy is not here: no integer arithmetic converts a float,
and the conversions that do carry a FloatConv. Eight types times
4 × 2 × 3 policies is 192 valid bytes; the other 64 are refused.
§Examples
use bytecode_lang::{IntOp, IntTy, Overflow, Policy, Shift};
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));
let php = IntOp::new(IntTy::I64).with_policy(Policy::new().with_shift(Shift::Saturate));
assert_eq!(php.to_string(), "i64.shsat");
assert_eq!(IntOp::from_bits(0b1100_0011), None); // shift code 3 is reservedImplementations§
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 by policy’s overflow,
div_zero, and shift (its float_to_int, which no integer
arithmetic consults, is not carried).
§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: overflow, div_zero, and shift as carried, and
float_to_int at its default (error).
§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, or None if its shift field holds the reserved
code 3.
§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));
assert!(IntOp::from_bits(0b1100_0000).is_none());