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