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
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,
num_enum::IntoPrimitive,
)]
#[repr(u8)]
pub enum InstructionCode {
// 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)
APPLY_ZERO,
APPLY_SINGLE,
APPLY,
GET_PROPERTY_DYNAMIC, // get property with arbitrary key value
GET_PROPERTY_INDEX, // get property with integer index
GET_PROPERTY_TEXT, // get property with text key
TAKE_PROPERTY_DYNAMIC, // take property with arbitrary key value
TAKE_PROPERTY_INDEX, // take property with integer index
TAKE_PROPERTY_TEXT, // take property with text key
SET_PROPERTY_DYNAMIC, // set property with arbitrary key value
SET_PROPERTY_INDEX, // set property with integer index
SET_PROPERTY_TEXT, // set property with text key
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,
// 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] = ...
MODIFY_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
// 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]
PERFORM_MOVES, // PERFORM_MOVE(3) $a, $b, $c (indicates two executing endpoint that pointers should be moved from sender to local, triggers MOVE)
MOVE, // MOVE(3) $a->$a2, $b->$b2, $c->$c2 (indicates that pointers should be moved from local to receiver, triggered by PERFORM_MOVE, includes mapping to new ids)
GET_SHARED_REF, // dynamic 'x
GET_SHARED_REF_MUT, // dynamic 'mut x
CREATE_SHARED, // shared x
CREATE_SHARED_MUT, // shared mut x
MODIFY_SHARED_CONTAINER_VALUE, // *x += 10;
SET_SHARED_CONTAINER_VALUE, // *x = 10;
UNBOX, // *x
/// type byte codes --> switch to Type Space
TYPED_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,
TAGGED_VALUE, // e.g. #Example or #Example {example: 42}
// lists and maps 0xe0 - 0xef
LIST, // (1,2,3)
SHORT_LIST, // (1,2,3) - optimized short list with up to 255 elements
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, // ::
}
#[cfg(test)]
mod tests {
use super::*;
use log::info;
use strum::IntoEnumIterator;
#[ignore]
#[test]
fn instruction_code_values() {
// print a list of all instruction codes and their values for debugging purposes
for code in InstructionCode::iter() {
info!("{:?} = {:2X}", code, code as u8);
}
}
}