datex_core/global/instruction_codes.rs
1use num_enum::TryFromPrimitive;
2use strum::Display;
3
4#[allow(non_camel_case_types)]
5#[derive(
6 Debug,
7 Eq,
8 PartialEq,
9 TryFromPrimitive,
10 Copy,
11 Clone,
12 Display,
13 num_enum::IntoPrimitive,
14)]
15#[repr(u8)]
16pub enum InstructionCode {
17 // flow instructions 0x00 - 0x0f
18 EXIT = 0x00,
19 CLOSE_AND_STORE, // ; TODO: do we need close_and_store at all, or is scope_end enough?
20 SCOPE_START, // (
21 SCOPE_END, // )
22 CACHE_POINT, // cache dxb from this point on
23 CACHE_RESET, // reset dxb scope cache
24
25 // internal variables and other shorthands 0x30 - 0x4f
26 VAR_RESULT,
27 SET_VAR_RESULT,
28 SET_VAR_RESULT_REFERENCE,
29 VAR_RESULT_ACTION,
30
31 VAR_SUB_RESULT,
32 SET_VAR_SUB_RESULT,
33 SET_VAR_SUB_RESULT_REFERENCE,
34 VAR_SUB_RESULT_ACTION,
35
36 VAR_VOID,
37 SET_VAR_VOID,
38 SET_VAR_VOID_REFERENCE,
39 VAR_VOID_ACTION,
40
41 _VAR_ORIGIN,
42 _SET_VAR_ORIGIN,
43 _SET_VAR_ORIGIN_REFERENCE,
44 _VAR_ORIGIN_ACTION,
45
46 VAR_IT,
47 SET_VAR_IT,
48 SET_VAR_IT_REFERENCE,
49 VAR_IT_ACTION,
50
51 VAR_REMOTE,
52
53 VAR_REMOTE_ACTION,
54 VAR_ORIGIN,
55 VAR_ENDPOINT,
56 VAR_ENTRYPOINT,
57 VAR_STD,
58 // VAR_TIMESTAMP ,
59 VAR_META,
60 VAR_PUBLIC,
61 VAR_THIS,
62 VAR_LOCATION,
63 VAR_ENV,
64
65 APPLY_ZERO,
66 APPLY_SINGLE,
67 APPLY,
68
69 // runtime commands 0x50 - 0x7f
70 RETURN, // return
71 TEMPLATE, // template
72 EXTENDS, // extends
73 IMPLEMENTS, // implements
74 MATCHES, // matches
75 DEBUGGER, // debugger
76 JMP, // jmp labelname
77 JTR, // jtr labelname
78 JFA, // jfa labelname (TODO replace with 0xa)
79 COUNT, // count x
80 ABOUT, // about x
81 NEW, // new <x> ()
82 DELETE_POINTER, // delete $aa
83 COPY, // copy $aa
84 CLONE, // clone $aa
85 ORIGIN, // origin $aa
86 SUBSCRIBERS, // subscribers $aa
87 PLAIN_SCOPE, // scope xy;
88 // don't use 0x64 (magic number)
89 TRANSFORM, // transform x <Int>
90 OBSERVE, // observe x ()=>()
91 RUN, // run xy;
92 AWAIT, // await xy;
93 DEFER, // maybe xy;
94 FUNCTION, // function ()
95 ASSERT, // assert
96 ITERATOR, // iterator ()
97 NEXT, // next it
98 FREEZE, // freeze
99 SEAL, // seal
100 HAS, // x has y
101 KEYS, // keys x
102 GET_TYPE, // type $aa
103 GET, // get file://..., get @user::34
104 RANGE, // ..
105 RESOLVE_RELATIVE_PATH, // ./abc
106 DO, // do xy;
107 DEFAULT, // x default y
108 COLLAPSE, // collapse x
109 RESPONSE, // response x
110 CLONE_COLLAPSE, // collapse
111
112 // comparators 0x80 - 0x8f
113 STRUCTURAL_EQUAL, // ==
114 NOT_STRUCTURAL_EQUAL, // !=
115 EQUAL, // ===
116 NOT_EQUAL, // !==
117 GREATER, // >
118 LESS, // <
119 GREATER_EQUAL, // >=
120 LESS_EQUAL, // <=
121 IS, // is
122
123 // logical + algebraic operators 0x90 - 0x9f
124 AND, // &
125 OR, // |
126 ADD, // +
127 SUBTRACT, // -
128 MULTIPLY, // *
129 DIVIDE, // /
130 NOT, // !
131 MODULO, // %
132 POWER, // ^
133 INCREMENT, // ++
134 DECREMENT, // --
135
136 UNARY_PLUS,
137 UNARY_MINUS,
138 BITWISE_NOT, // ~
139
140 UNION, // | // TODO #428: maybe create a union collection of multiple values, instead of using this as a binary operator?
141
142 // assignment operators
143 ASSIGN, // =
144 ADD_ASSIGN, // +=
145 SUBTRACT_ASSIGN, // -=
146 MULTIPLY_ASSIGN, // *=
147 DIVIDE_ASSIGN, // /=
148 MODULO_ASSIGN, // %=
149 POWER_ASSIGN, // ^=
150
151 // pointers & variables 0xa0 - 0xbf
152
153 // slots
154 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
155 SET_SLOT, // #aa = ...
156 ALLOCATE_SLOT, // #aa = ...
157 SLOT_ACTION, // #x += ...
158 DROP_SLOT, // drop #aa
159
160 LABEL, // $x
161 SET_LABEL, // $x = ...,
162 INIT_LABEL, // $x := ...
163 LABEL_ACTION, // $x += ...
164
165 GET_REF, // $x
166 GET_INTERNAL_REF, // $y, containing globally unique internal id
167 GET_LOCAL_REF, // $x, containing only the id, origin id is inferred from sender
168 GET_OR_INIT_REF, // $aa := ...
169 POINTER_ACTION, // $aa += ...
170 CREATE_REF, // &()
171 CREATE_REF_MUT, // &mut ()
172 CREATE_REF_FINAL, // &final ()
173 SET_REF, // &aa = ...
174
175 ASSIGN_TO_REF, // *x = 10;
176
177 DEREF, // *x
178
179 CHILD_GET, // .y
180 CHILD_SET, // .y = a
181 CHILD_SET_REFERENCE, // .y $= a
182 CHILD_ACTION, // .y += a, ...
183 CHILD_GET_REF, // ->y
184
185 WILDCARD, // *
186
187 /// type byte codes --> switch to Type Space
188 TYPED_VALUE,
189 TYPE_EXPRESSION, // type()
190
191 // ...
192
193 // values 0xc0 - 0xdf
194 TEXT,
195 INT_8, // byte
196 INT_16,
197 INT_32,
198 INT_64,
199 INT_128,
200 INT_BIG,
201
202 UINT_8, // u8
203 UINT_16,
204 UINT_32,
205 UINT_64,
206 UINT_128,
207
208 DECIMAL_F32,
209 DECIMAL_F64,
210 DECIMAL_BIG,
211 DECIMAL_AS_INT_32,
212 DECIMAL_AS_INT_16,
213
214 TRUE,
215 FALSE,
216 NULL,
217 VOID,
218 BUFFER,
219 EXECUTION_BLOCK,
220 QUANTITY,
221
222 SHORT_TEXT, // string with max. 255 characters
223
224 PERSON_ALIAS,
225 PERSON_ALIAS_WILDCARD,
226 INSTITUTION_ALIAS,
227 INSTITUTION_ALIAS_WILDCARD,
228 BOT,
229 BOT_WILDCARD,
230
231 ENDPOINT,
232 ENDPOINT_WILDCARD,
233
234 URL, //file://... , https://...
235
236 TIME, // ~2022-10-10~
237
238 // lists and maps 0xe0 - 0xef
239 LIST_START, // (1,2,3)
240 MAP_START, // (a:1, b:2)
241 STRUCT_START, // {a:1, b:2} - optimized structural map, field names are inferred from struct type
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 EXTEND, // ...
256
257 YEET, // !
258
259 REMOTE_EXECUTION, // ::
260
261 _SYNC_SILENT, // <==:
262}