midenc_hir/ir/value/
stack.rs

1use super::*;
2
3/// This is an simple representation of a [ValueRef] on the Miden operand stack
4#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
5pub struct StackOperand {
6    /// The value this operand corresponds to
7    pub value: ValueOrAlias,
8    /// The position of this operand on the corresponding stack
9    pub pos: u8,
10}
11
12impl core::fmt::Display for StackOperand {
13    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
14        write!(f, "{}:{}", &self.pos, &self.value)
15    }
16}
17
18impl Ord for StackOperand {
19    fn cmp(&self, other: &Self) -> core::cmp::Ordering {
20        self.pos.cmp(&other.pos).then(self.value.cmp(&other.value))
21    }
22}
23
24impl PartialOrd for StackOperand {
25    fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
26        Some(self.cmp(other))
27    }
28}
29
30impl From<(usize, ValueOrAlias)> for StackOperand {
31    #[inline(always)]
32    fn from(pair: (usize, ValueOrAlias)) -> Self {
33        Self {
34            pos: pair.0 as u8,
35            value: pair.1,
36        }
37    }
38}
39
40impl PartialEq<ValueOrAlias> for StackOperand {
41    #[inline(always)]
42    fn eq(&self, other: &ValueOrAlias) -> bool {
43        self.value.eq(other)
44    }
45}