/ cab / runtime / operation.rs
operation.rs
 1  use crate::{
 2     ByteIndex,
 3     ValueIndex,
 4  };
 5  
 6  #[derive(Debug, Clone, Copy, PartialEq, Eq, num_enum::TryFromPrimitive)]
 7  #[repr(u8)]
 8  pub enum Operation {
 9     Push,
10     Pop,
11  
12     Swap,
13  
14     Jump,
15     JumpIf,
16     JumpIfError,
17  
18     Force,
19  
20     ScopeStart,
21     ScopeEnd,
22     ScopePush,
23     ScopeSwap,
24  
25     Interpolate,
26  
27     Resolve,
28  
29     AssertBoolean,
30  
31     Construct,
32  
33     Call,
34  
35     Equal,
36  
37     All,
38     Any,
39  }
40  
41  #[derive(Debug, Clone, Copy, PartialEq, Eq)]
42  pub enum Argument {
43     U16(u16),
44     U64(u64),
45     ValueIndex(ValueIndex),
46     ByteIndex(ByteIndex),
47  }
48  
49  impl Argument {
50     #[must_use]
51     pub fn as_u16(&self) -> Option<u16> {
52        if let &Self::U16(u16) = self {
53           Some(u16)
54        } else {
55           None
56        }
57     }
58  
59     #[must_use]
60     pub fn as_u64(&self) -> Option<u64> {
61        if let &Self::U64(u64) = self {
62           Some(u64)
63        } else {
64           None
65        }
66     }
67  
68     #[must_use]
69     pub fn as_value_index(&self) -> Option<ValueIndex> {
70        if let &Self::ValueIndex(index) = self {
71           Some(index)
72        } else {
73           None
74        }
75     }
76  
77     #[must_use]
78     pub fn as_byte_index(&self) -> Option<ByteIndex> {
79        if let &Self::ByteIndex(index) = self {
80           Some(index)
81        } else {
82           None
83        }
84     }
85  }