snarkvm_synthesizer_program/logic/instruction/operand/
mod.rs1mod bytes;
17mod parse;
18
19use console::{
20 network::prelude::*,
21 program::{Literal, ProgramID, Register},
22 types::Group,
23};
24
25#[derive(Clone, PartialEq, Eq, Hash)]
28pub enum Operand<N: Network> {
29 Literal(Literal<N>),
31 Register(Register<N>),
33 ProgramID(ProgramID<N>),
35 Signer,
38 Caller,
41 BlockHeight,
44 NetworkID,
47}
48
49impl<N: Network> From<Literal<N>> for Operand<N> {
50 #[inline]
52 fn from(literal: Literal<N>) -> Self {
53 Operand::Literal(literal)
54 }
55}
56
57impl<N: Network> From<&Literal<N>> for Operand<N> {
58 #[inline]
60 fn from(literal: &Literal<N>) -> Self {
61 Operand::Literal(literal.clone())
62 }
63}
64
65impl<N: Network> From<Register<N>> for Operand<N> {
66 #[inline]
68 fn from(register: Register<N>) -> Self {
69 Operand::Register(register)
70 }
71}
72
73impl<N: Network> From<&Register<N>> for Operand<N> {
74 #[inline]
76 fn from(register: &Register<N>) -> Self {
77 Operand::Register(register.clone())
78 }
79}
80
81#[cfg(test)]
82mod tests {
83 use super::*;
84 use console::network::MainnetV0;
85
86 type CurrentNetwork = MainnetV0;
87
88 #[test]
89 fn test_operand_from_literal() -> Result<()> {
90 let literal = Literal::from_str("1field")?;
91 let expected = Operand::<CurrentNetwork>::Literal(literal.clone());
92
93 let operand = Operand::<CurrentNetwork>::from(literal);
94 assert_eq!(expected, operand);
95 Ok(())
96 }
97
98 #[test]
99 fn test_operand_from_register() -> Result<()> {
100 let register = Register::from_str("r0")?;
101 let expected = Operand::<CurrentNetwork>::Register(register.clone());
102
103 let operand = Operand::<CurrentNetwork>::from(register);
104 assert_eq!(expected, operand);
105 Ok(())
106 }
107
108 #[test]
109 fn test_operand_from_register_member() -> Result<()> {
110 let register = Register::from_str("r0.owner")?;
111 let expected = Operand::<CurrentNetwork>::Register(register.clone());
112
113 let operand = Operand::<CurrentNetwork>::from(register);
114 assert_eq!(expected, operand);
115 Ok(())
116 }
117}