datex_core/instruction/instruction_codes.rs
1use binrw::{BinRead, BinWrite};
2use num_enum::TryFromPrimitive;
3use strum::Display;
4use strum_macros::EnumIter;
5
6#[allow(non_camel_case_types)]
7#[derive(
8 EnumIter,
9 Debug,
10 Eq,
11 PartialEq,
12 TryFromPrimitive,
13 Copy,
14 Clone,
15 Display,
16 BinRead,
17 BinWrite,
18 num_enum::IntoPrimitive,
19)]
20#[brw(repr = u8)]
21#[repr(u8)]
22pub enum InstructionCode {
23 UNINITIALIZED, // placeholder for an uninitialized value
24
25 // flow instructions 0x00 - 0x0f
26 STATEMENTS, // statements block
27 SHORT_STATEMENTS, // optimized statements block with up to 255 instructions
28 UNBOUNDED_STATEMENTS,
29 UNBOUNDED_STATEMENTS_END, // end of statements block (only needed for unbounded blocks)
30
31 JUMP, // unconditional jump (relative byte offset)
32 JUMP_IF_FALSE, // conditional jump, jumps if false. example of usage is: "var a = 5; if(false) (a=3) else (a=2)" -> here it will jump to "(a=2)" block if "if(false)" is false and will not read the hole "if" block
33 JUMP_WITH_VALUE,
34
35 APPLY_ZERO,
36 APPLY_SINGLE,
37 APPLY,
38 CALL_METHOD,
39
40 GET_ENTRY_DYNAMIC, // get property with arbitrary key value
41 GET_ENTRY_INDEX, // get property with integer index
42 GET_ENTRY_TEXT, // get property with text key
43
44 TAKE_ENTRY_DYNAMIC, // take property with arbitrary key value
45 TAKE_ENTRY_INDEX, // take property with integer index
46 TAKE_ENTRY_TEXT, // take property with text key
47
48 SET_ENTRY_DYNAMIC, // set property with arbitrary key value
49 SET_ENTRY_INDEX, // set property with integer index
50 SET_ENTRY_TEXT, // set property with text key
51
52 SENDER,
53 RECEIVER,
54
55 MATCHES, // matches
56
57 STRUCTURAL_EQUAL, // ==
58 NOT_STRUCTURAL_EQUAL, // !=
59 EQUAL, // ===
60 NOT_EQUAL, // !==
61 IS, // is
62
63 ADD, // +
64 SUBTRACT, // -
65 MULTIPLY, // *
66 DIVIDE, // /
67 MODULO, // %
68 POWER, // ^
69
70 AND,
71 OR,
72 NOT,
73
74 UNARY_PLUS,
75 UNARY_MINUS,
76 BITWISE_NOT, // ~
77
78 INCREMENT,
79 DECREMENT,
80
81 APPEND_ENTRY,
82 CLEAR,
83 SPLICE,
84 SPLICE_DYNAMIC,
85
86 // pointers & variables 0xa0 - 0xbf
87
88 // stack value
89 // TODO #669: refactor with stack variable system?
90 CLONE_STACK_VALUE, // clone #stack[i] 0x0000-0x00ff = variables passed on between scopes, 0x0100-0xfdff = normal variables, 0xfe00-0xffff = it variables (#it.0, #it.1, ...) for function arguments
91 BORROW_STACK_VALUE, // &#stack[i]
92 GET_STACK_VALUE_SHARED_REF, // '#stack[i]
93 GET_STACK_VALUE_SHARED_REF_MUT, // 'mut #stack[i]
94 SET_STACK_VALUE, // #stack[i] = ...
95 PUSH_TO_STACK, // #stack += ...
96 PUSH_LIST_TO_STACK, // #stack ...+= [x]
97 TAKE_STACK_VALUE, // #stack[i]
98
99 GET_ROOT_PROPERTY, // e.g. $.endpoint
100
101 CALLABLE, // for functions/procedures
102 CALLABLE_DECLARATION, // for inline DATEX script function/procedure declarations
103
104 ENTITY_TYPE_DEFINITION,
105
106 // Note: fix to sync with PointerAddress
107 REQUEST_REMOTE_SHARED_REF, // '$x
108 REQUEST_REMOTE_SHARED_REF_MUT, // 'mut $x
109
110 GET_CORE_LIB_VALUE, // e.g. integer, print
111 GET_LOCAL_SHARED_REF, // '$x, containing only the id, origin id is inferred from sender
112
113 SHARED_REF, // '/'mut $1234
114 SHARED_REF_WITH_VALUE, // '/'mut $1234 mut [value]
115
116 MOVE_WITH_VALUE,
117
118 DERIVE_SHARED_REF, // dynamic 'x
119 DERIVE_SHARED_REF_MUT, // dynamic 'mut x
120
121 CREATE_SHARED, // shared x
122 CREATE_SHARED_MUT, // shared mut x
123
124 SET_SHARED_CONTAINER_VALUE, // *x = 10;
125
126 UNBOX, // *x
127
128 /// value with entity classification
129 ENTITY_VALUE,
130 TYPE_EXPRESSION, // type()
131
132 // ...
133
134 // values 0xc0 - 0xdf
135 TEXT,
136 INT_8, // byte
137 INT_16,
138 INT_32,
139 INT_64,
140 INT_128,
141 INT_BIG,
142 INT, // default integer (unsized)
143
144 RANGE,
145
146 UINT_8, // u8
147 UINT_16,
148 UINT_32,
149 UINT_64,
150 UINT_128,
151
152 DECIMAL_F32,
153 DECIMAL_F64,
154 DECIMAL_BIG,
155 DECIMAL_AS_INT_32,
156 DECIMAL_AS_INT_16,
157
158 DECIMAL, // default decimal (unsized)
159
160 TRUE,
161 FALSE,
162 NULL,
163
164 SHORT_TEXT, // string with max. 255 characters
165
166 ENDPOINT,
167
168 BOXED_VALUE, // boxed value (for Option<T> and other types that require boxing)
169 TAGGED_VALUE, // e.g. #Example or #Example {example: 42}
170 INSTANT, // ISO 8601 datetime stored as i128 milliseconds since epoch
171
172 // lists and maps 0xe0 - 0xef
173 LIST, // (1,2,3)
174 SHORT_LIST, // (1,2,3) - optimized short list with up to 255 elements
175 COMPACT_LIST, // optimized representation for a list containing core values of the same type (e.g. List<integer/u8>)
176 MAP, // (a:1, b:2)
177 SHORT_MAP, // {a:1, b:2} - optimized short map with up to 255 elements
178
179 KEY_VALUE_SHORT_TEXT,
180 KEY_VALUE_DYNAMIC, // for object elements with dynamic key
181
182 REMOTE_EXECUTION, // ::
183
184 CLASSIFIED_VALUE,
185}
186impl InstructionCode {
187 pub const fn as_u8(&self) -> u8 {
188 *self as u8
189 }
190}
191
192#[cfg(test)]
193mod tests {
194 use super::*;
195 use log::info;
196 use strum::IntoEnumIterator;
197
198 #[ignore]
199 #[test]
200 fn instruction_code_values() {
201 flexi_logger::init();
202 // print a list of all instruction codes and their values for debugging purposes
203 for code in InstructionCode::iter() {
204 info!("{:?} = {:2X}", code, code as u8);
205 }
206 }
207}