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    PushMapValN,
17    HasMapKey,
18    PushMtNode,
19    InsertMem,
20    InsertHdword,
21    InsertHdwordWithDomain,
22    InsertHqword,
23    InsertHperm,
24}
25
26impl From<&SystemEventNode> for SystemEvent {
27    fn from(value: &SystemEventNode) -> Self {
28        use SystemEventNode::*;
29        match value {
30            PushMapVal => Self::MapValueToStack,
31            PushMapValN => Self::MapValueToStackN,
32            HasMapKey => Self::HasMapKey,
33            PushMtNode => Self::MerkleNodeToStack,
34            InsertMem => Self::MemToMap,
35            InsertHdword => Self::HdwordToMap,
36            InsertHdwordWithDomain => Self::HdwordToMapWithDomain,
37            InsertHqword => Self::HqwordToMap,
38            InsertHperm => Self::HpermToMap,
39        }
40    }
41}
42
43impl crate::prettier::PrettyPrint for SystemEventNode {
44    fn render(&self) -> crate::prettier::Document {
45        crate::prettier::display(self)
46    }
47}
48
49impl fmt::Display for SystemEventNode {
50    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51        match self {
52            Self::PushMapVal => write!(f, "push_mapval"),
53            Self::PushMapValN => write!(f, "push_mapvaln"),
54            Self::HasMapKey => write!(f, "has_mapkey"),
55            Self::PushMtNode => write!(f, "push_mtnode"),
56            Self::InsertMem => write!(f, "insert_mem"),
57            Self::InsertHdword => write!(f, "insert_hdword"),
58            Self::InsertHdwordWithDomain => write!(f, "insert_hdword_d"),
59            Self::InsertHqword => write!(f, "insert_hqword"),
60            Self::InsertHperm => writeln!(f, "insert_hperm"),
61        }
62    }
63}