datex_core/global/instruction_codes.rs
1use num_enum::TryFromPrimitive;
2use strum::Display;
3use strum_macros::EnumIter;
4
5#[allow(non_camel_case_types)]
6#[derive(
7 EnumIter,
8 Debug,
9 Eq,
10 PartialEq,
11 TryFromPrimitive,
12 Copy,
13 Clone,
14 Display,
15 num_enum::IntoPrimitive,
16)]
17#[repr(u8)]
18pub enum InstructionCode {
19 // flow instructions 0x00 - 0x0f
20 EXIT = 0x00,
21 STATEMENTS, // statements block
22 SHORT_STATEMENTS, // optimized statements block with up to 255 instructions
23 UNBOUNDED_STATEMENTS,
24 UNBOUNDED_STATEMENTS_END, // end of statements block (only needed for unbounded blocks)
25 CACHE_POINT, // cache dxb from this point on
26 CACHE_RESET, // reset dxb scope cache
27
28 // internal variables and other shorthands 0x30 - 0x4f
29 VAR_RESULT,
30 SET_VAR_RESULT,
31 SET_VAR_RESULT_REFERENCE,
32 VAR_RESULT_ACTION,
33
34 VAR_SUB_RESULT,
35 SET_VAR_SUB_RESULT,
36 SET_VAR_SUB_RESULT_REFERENCE,
37 VAR_SUB_RESULT_ACTION,
38
39 VAR_VOID,
40 SET_VAR_VOID,
41 SET_VAR_VOID_REFERENCE,
42 VAR_VOID_ACTION,
43
44 _VAR_ORIGIN,
45 _SET_VAR_ORIGIN,
46 _SET_VAR_ORIGIN_REFERENCE,
47 _VAR_ORIGIN_ACTION,
48
49 VAR_IT,
50 SET_VAR_IT,
51 SET_VAR_IT_REFERENCE,
52 VAR_IT_ACTION,
53
54 VAR_REMOTE,
55
56 VAR_REMOTE_ACTION,
57 VAR_ORIGIN,
58 VAR_ENDPOINT,
59 VAR_ENTRYPOINT,
60 VAR_STD,
61 // VAR_TIMESTAMP ,
62 VAR_META,
63 VAR_PUBLIC,
64 VAR_THIS,
65 VAR_LOCATION,
66 VAR_ENV,
67
68 APPLY_ZERO,
69 APPLY_SINGLE,
70 APPLY,
71
72 GET_PROPERTY_DYNAMIC, // get property with arbitrary key value
73 GET_PROPERTY_INDEX, // get property with integer index
74 GET_PROPERTY_TEXT, // get property with text key
75
76 SET_PROPERTY_DYNAMIC, // set property with arbitrary key value
77 SET_PROPERTY_INDEX, // set property with integer index
78 SET_PROPERTY_TEXT, // set property with text key
79
80 // runtime commands 0x50 - 0x7f
81 RETURN, // return
82 TEMPLATE, // template
83 EXTENDS, // extends
84 IMPLEMENTS, // implements
85 MATCHES, // matches
86 DEBUGGER, // debugger
87 JMP, // jmp labelname
88 JTR, // jtr labelname
89 JFA, // jfa labelname (TODO replace with 0xa)
90 COUNT, // count x
91 ABOUT, // about x
92 NEW, // new <x> ()
93 DELETE_POINTER, // delete $aa
94 COPY, // copy $aa
95 CLONE, // clone $aa
96 ORIGIN, // origin $aa
97 SUBSCRIBERS, // subscribers $aa
98 PLAIN_SCOPE, // scope xy;
99 // don't use 0x64 (magic number)
100
101 // comparators 0x80 - 0x8f
102 STRUCTURAL_EQUAL, // ==
103 NOT_STRUCTURAL_EQUAL, // !=
104 EQUAL, // ===
105 NOT_EQUAL, // !==
106 GREATER, // >
107 LESS, // <
108 GREATER_EQUAL, // >=
109 LESS_EQUAL, // <=
110 IS, // is
111
112 // logical + algebraic operators 0x90 - 0x9f
113 AND, // &
114 OR, // |
115 ADD, // +
116 SUBTRACT, // -
117 MULTIPLY, // *
118 DIVIDE, // /
119 NOT, // !
120 MODULO, // %
121 POWER, // ^
122 INCREMENT, // ++
123 DECREMENT, // --
124
125 UNARY_PLUS,
126 UNARY_MINUS,
127 BITWISE_NOT, // ~
128
129 UNION, // | // TODO #428: maybe create a union collection of multiple values, instead of using this as a binary operator?
130
131 // assignment operators
132 ASSIGN, // =
133 ADD_ASSIGN, // +=
134 SUBTRACT_ASSIGN, // -=
135 MULTIPLY_ASSIGN, // *=
136 DIVIDE_ASSIGN, // /=
137 MODULO_ASSIGN, // %=
138 POWER_ASSIGN, // ^=
139
140 // pointers & variables 0xa0 - 0xbf
141
142 // slots
143 // TODO #669: refactor with stack variable system?
144 GET_SLOT, // #xyz 0x0000-0x00ff = variables passed on between scopes, 0x0100-0xfdff = normal variables, 0xfe00-0xffff = it variables (#it.0, #it.1, ...) for function arguments
145 SET_SLOT, // #aa = ...
146 ALLOCATE_SLOT, // #aa = ...
147 SLOT_ACTION, // #x += ...
148 DROP_SLOT, // drop #aa
149
150 GET_INTERNAL_SLOT, // e.g. #endpoint
151
152 LABEL, // $x
153 SET_LABEL, // $x = ...,
154 INIT_LABEL, // $x := ...
155 LABEL_ACTION, // $x += ...
156
157 // Note: fix to sync with RawPointerAddress
158 GET_REMOTE_SHARED_REF = 120u8, // '$x
159 GET_INTERNAL_SHARED_REF = 121u8, // '$y, containing globally unique internal id
160 GET_LOCAL_SHARED_REF = 122u8, // '$x, containing only the id, origin id is inferred from sender
161
162 GET_REMOTE_SHARED_REF_MUT, // 'mut $x
163
164 GET_OR_INIT_REF, // $aa := ...
165 POINTER_ACTION, // $aa += ...
166 CREATE_SHARED_REF, // ' / 'mut
167 SET_REF, // &aa = ...
168
169 CREATE_SHARED, // shared x
170 CREATE_SHARED_MUT, // shared mut x
171
172 SET_REFERENCE_VALUE, // *x = 10;
173
174 UNBOX, // *x
175
176 CHILD_GET, // .y
177 CHILD_SET, // .y = a
178 CHILD_SET_REFERENCE, // .y $= a
179 CHILD_ACTION, // .y += a, ...
180 CHILD_GET_REF, // ->y
181
182 WILDCARD, // *
183
184 /// type byte codes --> switch to Type Space
185 TYPED_VALUE,
186 TYPE_EXPRESSION, // type()
187
188 // ...
189
190 // values 0xc0 - 0xdf
191 TEXT,
192 INT_8, // byte
193 INT_16,
194 INT_32,
195 INT_64,
196 INT_128,
197 INT_BIG,
198 INT, // default integer (unsized)
199
200 UINT_8, // u8
201 UINT_16,
202 UINT_32,
203 UINT_64,
204 UINT_128,
205
206 DECIMAL_F32,
207 DECIMAL_F64,
208 DECIMAL_BIG,
209 DECIMAL_AS_INT_32,
210 DECIMAL_AS_INT_16,
211
212 DECIMAL, // default decimal (unsized)
213
214 TRUE,
215 FALSE,
216 NULL,
217 VOID,
218 BUFFER,
219 QUANTITY,
220
221 SHORT_TEXT, // string with max. 255 characters
222
223 PERSON_ALIAS,
224 PERSON_ALIAS_WILDCARD,
225 INSTITUTION_ALIAS,
226 INSTITUTION_ALIAS_WILDCARD,
227 BOT,
228 BOT_WILDCARD,
229
230 ENDPOINT,
231 ENDPOINT_WILDCARD,
232
233 URL, //file://... , https://...
234
235 TIME, // ~2022-10-10~
236
237 // lists and maps 0xe0 - 0xef
238 LIST, // (1,2,3)
239 SHORT_LIST, // (1,2,3) - optimized short list with up to 255 elements
240 MAP, // (a:1, b:2)
241 SHORT_MAP, // {a:1, b:2} - optimized short map with up to 255 elements
242
243 KEY_VALUE_SHORT_TEXT,
244 KEY_VALUE_DYNAMIC, // for object elements with dynamic key
245 KEY_PERMISSION, // for object elements with permission prefix
246 INTERNAL_OBJECT_SLOT, // for object internal slots
247
248 // special instructions 0xf0 - 0xff
249 SYNC, // <==
250 STOP_SYNC, // </=
251
252 STREAM, // << stream
253 STOP_STREAM, // </ stream
254
255 REMOTE_EXECUTION, // ::
256
257 TRANSFORM, // transform x <Int>
258 OBSERVE, // observe x ()=>()
259 RUN, // run xy;
260 AWAIT, // await xy;
261 DEFER, // maybe xy;
262 FUNCTION, // function ()
263 ASSERT, // assert
264 ITERATOR, // iterator ()
265 NEXT, // next it
266 FREEZE, // freeze
267 SEAL, // seal
268 HAS, // x has y
269 KEYS, // keys x
270 GET_TYPE, // type $aa
271 GET, // get file://..., get @user::34
272 RANGE, // ..
273 RESOLVE_RELATIVE_PATH, // ./abc
274 DO, // do xy;
275 DEFAULT, // x default y
276 COLLAPSE, // collapse x
277 RESPONSE, // response x
278 CLONE_COLLAPSE, // collapse
279}
280
281#[cfg(test)]
282mod tests {
283 use super::*;
284 use log::info;
285 use strum::IntoEnumIterator;
286
287 #[ignore]
288 #[test]
289 fn test_instruction_code_values() {
290 // print a list of all instruction codes and their values for debugging purposes
291 for code in InstructionCode::iter() {
292 info!("{:?} = {:2X}", code, code as u8);
293 }
294 }
295}