| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Mitra VM Architecture | |||||||||||||||||||||||||
2 | Belt | |||||||||||||||||||||||||
3 | Instead of a stack or registers, Mitra has a “belt” (like conveyor belt), which kinda combines the strengths of both. A belt is like a stack, but items are only ever pushed, never poped, and after they reach a certain height, items too deep are simply dropped. This has a couple of handy advantages. | |||||||||||||||||||||||||
4 | Mitra can store up to 16 items on its belt. Instructions can reference any item on the belt, not just the top ones as with a stack based machine. | |||||||||||||||||||||||||
5 | Say this is the current state of the belt: | |||||||||||||||||||||||||
6 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | ||||||||||
7 | 5 | 8 | 6 | 1 | 8 | 4 | 2 | 6 | 9 | 4 | 2 | 5 | 8 | 5 | 3 | 9 | ||||||||||
8 | ||||||||||||||||||||||||||
9 | If we now execute the operation add(<3>, <13>), it will add 1+5, and drop the value from the belt: | |||||||||||||||||||||||||
10 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | ||||||||||
11 | 6 | 5 | 8 | 6 | 1 | 8 | 4 | 2 | 6 | 9 | 4 | 2 | 5 | 8 | 5 | 3 | ||||||||||
12 | ||||||||||||||||||||||||||
13 | Locals | |||||||||||||||||||||||||
14 | Similar to WebAssembly, there are operations for putting values from the belt to “local variables”, which can be retrieved later. | |||||||||||||||||||||||||
15 | It‘s only possible to put the top value of the belt into local variables. | |||||||||||||||||||||||||
16 | ||||||||||||||||||||||||||
17 | Type System | |||||||||||||||||||||||||
18 | There are 5 types for Mitra code: | |||||||||||||||||||||||||
19 | i8 | 8-bit integer (signed or unsigned) | ||||||||||||||||||||||||
20 | i16 | 16-bit integer (signed or unsigned) | ||||||||||||||||||||||||
21 | i32 | 32-bit integer (signed or unsigned) | ||||||||||||||||||||||||
22 | i64 | 64-bit integer (signed or unsigned) | ||||||||||||||||||||||||
23 | i128 | 128-bit integer (signed or unsigned) | ||||||||||||||||||||||||
24 | slice | Pair of 32-bit unsigned integers pointing to a slice of memory, either read-only or read-write. | ||||||||||||||||||||||||
25 | ||||||||||||||||||||||||||
26 | All values on the belt and of local variables are typed. Operations return types values depend on what‘s currently on the belt. | |||||||||||||||||||||||||
27 | Operations automatically promote values to the highest bit size of the operand. | |||||||||||||||||||||||||
28 | So say we want to add 5 (i8) and 10 (i32), the then the i8 will be promoted to an i32, and then 32-bit addition is performed. | |||||||||||||||||||||||||
29 | Operations specify if the smaller value should be 0- or sign-extended. If they don‘t, (like 'and'), they‘re 0-extended. | |||||||||||||||||||||||||
30 | Types are inferable for all operations before execution. | |||||||||||||||||||||||||
31 | ||||||||||||||||||||||||||
32 | NaN | |||||||||||||||||||||||||
33 | Some operations can fail, like load, div, in which case they return a NaN. This value is only possible on the belt and for locals, but not for the memory. | |||||||||||||||||||||||||
34 | Any operation that gets a NaN as input also returns NaN. Results can be verified, in which case they trap and fail the transaction if they are NaN. | |||||||||||||||||||||||||
35 | Any store operation traps and fails the transaction if any of its parameters is a NaN. | |||||||||||||||||||||||||
36 | ||||||||||||||||||||||||||
37 | Slices | |||||||||||||||||||||||||
38 | Slices point to a range of memory (start & length). All slices are read-only except for the pre-allocated RAM for the execution. | |||||||||||||||||||||||||
39 | No memory is ever allocated inside the Mitra VM. | |||||||||||||||||||||||||
40 | Slices can be created by either shrinking/subslicing an existing slice or getting one from the data provided by the VM. | |||||||||||||||||||||||||
41 | For example, the txinfo.input_bytecode_at opcode returns a read-only slice containing the bytecode of a specific input. This slice | |||||||||||||||||||||||||
42 | can be shrinked/subsliced, but it cannot be written to. | |||||||||||||||||||||||||
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 |