miden_assembly_syntax/ast/instruction/
advice.rs

1use core::fmt;
2
3use miden_core::sys_events::SystemEvent;
4
5// SYSTEM EVENT NODE
6// ================================================================================================
7
8/// Instructions which inject data into the advice provider.
9///
10/// These instructions can be used to perform two broad sets of operations:
11/// - Push new data onto the advice stack.
12/// - Insert new data into the advice map.
13#[derive(Clone, PartialEq, Eq, Debug)]
14pub enum SystemEventNode {
15    PushMapVal,
16    PushMapValCount,
17    PushMapValN0,
18    PushMapValN4,
19    PushMapValN8,
20    HasMapKey,
21    PushMtNode,
22    InsertMem,
23    InsertHdword,
24    InsertHdwordWithDomain,
25    InsertHqword,
26    InsertHperm,
27}
28
29impl From<&SystemEventNode> for SystemEvent {
30    fn from(value: &SystemEventNode) -> Self {
31        use SystemEventNode::*;
32        match value {
33            PushMapVal => Self::MapValueToStack,
34            PushMapValCount => Self::MapValueCountToStack,
35            PushMapValN0 => Self::MapValueToStackN0,
36            PushMapValN4 => Self::MapValueToStackN4,
37            PushMapValN8 => Self::MapValueToStackN8,
38            HasMapKey => Self::HasMapKey,
39            PushMtNode => Self::MerkleNodeToStack,
40            InsertMem => Self::MemToMap,
41            InsertHdword => Self::HdwordToMap,
42            InsertHdwordWithDomain => Self::HdwordToMapWithDomain,
43            InsertHqword => Self::HqwordToMap,
44            InsertHperm => Self::HpermToMap,
45        }
46    }
47}
48
49impl crate::prettier::PrettyPrint for SystemEventNode {
50    fn render(&self) -> crate::prettier::Document {
51        crate::prettier::display(self)
52    }
53}
54
55impl fmt::Display for SystemEventNode {
56    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57        match self {
58            Self::PushMapVal => write!(f, "push_mapval"),
59            Self::PushMapValCount => write!(f, "push_mapval_count"),
60            Self::PushMapValN0 => write!(f, "push_mapvaln.0"),
61            Self::PushMapValN4 => write!(f, "push_mapvaln.4"),
62            Self::PushMapValN8 => write!(f, "push_mapvaln.8"),
63            Self::HasMapKey => write!(f, "has_mapkey"),
64            Self::PushMtNode => write!(f, "push_mtnode"),
65            Self::InsertMem => write!(f, "insert_mem"),
66            Self::InsertHdword => write!(f, "insert_hdword"),
67            Self::InsertHdwordWithDomain => write!(f, "insert_hdword_d"),
68            Self::InsertHqword => write!(f, "insert_hqword"),
69            Self::InsertHperm => writeln!(f, "insert_hperm"),
70        }
71    }
72}