Enum koto_bytecode::Op
source · #[repr(u8)]pub enum Op {
Show 256 variants
Copy = 0,
SetNull = 1,
SetFalse = 2,
SetTrue = 3,
Set0 = 4,
Set1 = 5,
SetNumberU8 = 6,
SetNumberNegU8 = 7,
LoadFloat = 8,
LoadInt = 9,
LoadString = 10,
LoadNonLocal = 11,
Import = 12,
MakeTempTuple = 13,
TempTupleToTuple = 14,
MakeMap = 15,
MakeIterator = 16,
SequenceStart = 17,
SequencePush = 18,
SequencePushN = 19,
SequenceToList = 20,
SequenceToTuple = 21,
StringStart = 22,
StringPush = 23,
StringFinish = 24,
Function = 25,
Capture = 26,
Range = 27,
RangeInclusive = 28,
RangeTo = 29,
RangeToInclusive = 30,
RangeFrom = 31,
RangeFull = 32,
Negate = 33,
Not = 34,
Add = 35,
Subtract = 36,
Multiply = 37,
Divide = 38,
Remainder = 39,
AddAssign = 40,
SubtractAssign = 41,
MultiplyAssign = 42,
DivideAssign = 43,
RemainderAssign = 44,
Less = 45,
LessOrEqual = 46,
Greater = 47,
GreaterOrEqual = 48,
Equal = 49,
NotEqual = 50,
Jump = 51,
JumpBack = 52,
JumpIfTrue = 53,
JumpIfFalse = 54,
Call = 55,
CallInstance = 56,
Return = 57,
Yield = 58,
Throw = 59,
IterNext = 60,
IterNextTemp = 61,
IterNextQuiet = 62,
IterUnpack = 63,
TempIndex = 64,
SliceFrom = 65,
SliceTo = 66,
Index = 67,
SetIndex = 68,
MapInsert = 69,
MetaInsert = 70,
MetaInsertNamed = 71,
MetaExport = 72,
MetaExportNamed = 73,
ValueExport = 74,
Access = 75,
AccessString = 76,
IsList = 77,
IsTuple = 78,
Size = 79,
TryStart = 80,
TryEnd = 81,
Debug = 82,
CheckType = 83,
CheckSizeEqual = 84,
CheckSizeMin = 85,
Unused86 = 86,
Unused87 = 87,
Unused88 = 88,
Unused89 = 89,
Unused90 = 90,
Unused91 = 91,
Unused92 = 92,
Unused93 = 93,
Unused94 = 94,
Unused95 = 95,
Unused96 = 96,
Unused97 = 97,
Unused98 = 98,
Unused99 = 99,
Unused100 = 100,
Unused101 = 101,
Unused102 = 102,
Unused103 = 103,
Unused104 = 104,
Unused105 = 105,
Unused106 = 106,
Unused107 = 107,
Unused108 = 108,
Unused109 = 109,
Unused110 = 110,
Unused111 = 111,
Unused112 = 112,
Unused113 = 113,
Unused114 = 114,
Unused115 = 115,
Unused116 = 116,
Unused117 = 117,
Unused118 = 118,
Unused119 = 119,
Unused120 = 120,
Unused121 = 121,
Unused122 = 122,
Unused123 = 123,
Unused124 = 124,
Unused125 = 125,
Unused126 = 126,
Unused127 = 127,
Unused128 = 128,
Unused129 = 129,
Unused130 = 130,
Unused131 = 131,
Unused132 = 132,
Unused133 = 133,
Unused134 = 134,
Unused135 = 135,
Unused136 = 136,
Unused137 = 137,
Unused138 = 138,
Unused139 = 139,
Unused140 = 140,
Unused141 = 141,
Unused142 = 142,
Unused143 = 143,
Unused144 = 144,
Unused145 = 145,
Unused146 = 146,
Unused147 = 147,
Unused148 = 148,
Unused149 = 149,
Unused150 = 150,
Unused151 = 151,
Unused152 = 152,
Unused153 = 153,
Unused154 = 154,
Unused155 = 155,
Unused156 = 156,
Unused157 = 157,
Unused158 = 158,
Unused159 = 159,
Unused160 = 160,
Unused161 = 161,
Unused162 = 162,
Unused163 = 163,
Unused164 = 164,
Unused165 = 165,
Unused166 = 166,
Unused167 = 167,
Unused168 = 168,
Unused169 = 169,
Unused170 = 170,
Unused171 = 171,
Unused172 = 172,
Unused173 = 173,
Unused174 = 174,
Unused175 = 175,
Unused176 = 176,
Unused177 = 177,
Unused178 = 178,
Unused179 = 179,
Unused180 = 180,
Unused181 = 181,
Unused182 = 182,
Unused183 = 183,
Unused184 = 184,
Unused185 = 185,
Unused186 = 186,
Unused187 = 187,
Unused188 = 188,
Unused189 = 189,
Unused190 = 190,
Unused191 = 191,
Unused192 = 192,
Unused193 = 193,
Unused194 = 194,
Unused195 = 195,
Unused196 = 196,
Unused197 = 197,
Unused198 = 198,
Unused199 = 199,
Unused200 = 200,
Unused201 = 201,
Unused202 = 202,
Unused203 = 203,
Unused204 = 204,
Unused205 = 205,
Unused206 = 206,
Unused207 = 207,
Unused208 = 208,
Unused209 = 209,
Unused210 = 210,
Unused211 = 211,
Unused212 = 212,
Unused213 = 213,
Unused214 = 214,
Unused215 = 215,
Unused216 = 216,
Unused217 = 217,
Unused218 = 218,
Unused219 = 219,
Unused220 = 220,
Unused221 = 221,
Unused222 = 222,
Unused223 = 223,
Unused224 = 224,
Unused225 = 225,
Unused226 = 226,
Unused227 = 227,
Unused228 = 228,
Unused229 = 229,
Unused230 = 230,
Unused231 = 231,
Unused232 = 232,
Unused233 = 233,
Unused234 = 234,
Unused235 = 235,
Unused236 = 236,
Unused237 = 237,
Unused238 = 238,
Unused239 = 239,
Unused240 = 240,
Unused241 = 241,
Unused242 = 242,
Unused243 = 243,
Unused244 = 244,
Unused245 = 245,
Unused246 = 246,
Unused247 = 247,
Unused248 = 248,
Unused249 = 249,
Unused250 = 250,
Unused251 = 251,
Unused252 = 252,
Unused253 = 253,
Unused254 = 254,
Unused255 = 255,
}Expand description
The operations used in Koto bytecode
Each operation is made up of a byte, followed by N additional bytes that define its behaviour. The combined operation bytes are interpreted as an Instruction by the InstructionReader.
In the comments for each operation, the additional bytes are specified inside square brackets.
- Bytes prefixed with * show that the byte is referring to a register.
- Values prefixed with @ indicate a variable-sized integer.
- The 7 least significant bits are included in the integer.
- The 8th bit in a byte is a continuation flag.
- Continuation bits are shifted by N*7 and included in the resulting integer.
- Currently only (up to) 32 bits are used, and integers are unsigned.
Variants§
Copy = 0
Copies the source value to the target register
[Copy, *target, *source]
SetNull = 1
Sets a register to contain Null
[*target]
SetFalse = 2
Sets a register to contain Bool(false)
[*target]
SetTrue = 3
Sets a register to contain Bool(true)
[*target]
Set0 = 4
Sets a register to contain Int(0)
[*target]
Set1 = 5
Sets a register to contain Int(1)
[*target]
SetNumberU8 = 6
Sets a register to contain Int(n)
[*target, n]
SetNumberNegU8 = 7
Sets a register to contain Int(-n)
[*target, n]
LoadFloat = 8
Loads an f64 constant into a register
[*target, @constant]
LoadInt = 9
Loads an i64 constant into a register
[*target, @constant]
LoadString = 10
Loads a string constant into a register
[*target, @constant]
LoadNonLocal = 11
Loads a non-local value into a register
[*target, @constant]
Import = 12
Imports a value
The name of the value to be imported will be placed in the register before running this op, the imported value will then be placed in the same register.
[*register]
MakeTempTuple = 13
Makes a temporary tuple out of values stored in consecutive registers
Used when a tuple is made which won’t be assigned to a value,
e.g. in match expressions: match a, b, c
[*target, *start, value count]
TempTupleToTuple = 14
Converts a temporary tuple into a regular Tuple
Used when the result of an expression that uses a temporary tuple is needed.
e.g. in multi-assignment in a return position: return x, y, z = 1, 2, 3
[*target, *source]
MakeMap = 15
Makes an empty map with the given size hint
[*target, @size hint]
MakeIterator = 16
Makes an Iterator out of an iterable value
[*target, *iterable]
SequenceStart = 17
Starts a new sequence with the given size hint
[@size hint]
SequencePush = 18
Pushes a single value to the end of the current sequence
[*value]
SequencePushN = 19
Pushes values from consecutive registers to the end of the current sequence
[*start, value count]
SequenceToList = 20
Converts the current sequence into a List
[*register]
SequenceToTuple = 21
Converts the current sequence into a Tuple
[*register]
StringStart = 22
Starts the construction of a new string with a given size hint
[@size hint]
StringPush = 23
Pushes a value to the end of the current string
Strings will have their contents added directly to the string being built. Other values will be formatted and then added to the string.
[*value]
StringFinish = 24
Places the finished string in the target register
[*target]
Function = 25
Makes a Function
The flags are a bitfield constructed from FunctionFlags. The N size bytes following this instruction make up the body of the function.
[*target, arg count, capture count, flags, function size[2]]
Capture = 26
Captures a value for a Function
The value gets cloned to the Function’s captures list at the given index.
[*function, capture index, *value]
Range = 27
Makes a Range with defined start and end values
[*target, *start, *end]
RangeInclusive = 28
Makes an inclusive Range with defined start and end values
[*target, *start, *end]
RangeTo = 29
Makes a Range with a defined end value and no start
[*target, *end]
RangeToInclusive = 30
Makes an inclusive Range with a defined end value and no start
[*target, *end]
RangeFrom = 31
Makes a Range with a defined start value and no end
[*target, *start]
RangeFull = 32
Makes a full Range with undefined start and end
[*target]
Negate = 33
Negates a value
Used for the unary negation operator, i.e. x = -y
[*target, *source]
Not = 34
Flips the value of a boolean
[*target, *source]
Add = 35
Adds lhs and rhs together
[*result, *lhs, *rhs]
Subtract = 36
Subtracts rhs from lhs
[*result, *lhs, *rhs]
Multiply = 37
Multiplies lhs and rhs together
[*result, *lhs, *rhs]
Divide = 38
Divides lhs by rhs
[*result, *lhs, *rhs]
Remainder = 39
Performs the remainder operation with lhs and rhs
[*result, *lhs, *rhs]
AddAssign = 40
Add-assign rhs -> lhs
[*lhs, *rhs]
SubtractAssign = 41
Subtract-assign rhs -> lhs
[*lhs, *rhs]
MultiplyAssign = 42
Multiply-assign rhs -> lhs
[*lhs, *rhs]
DivideAssign = 43
Divide-assign rhs -> lhs
[*lhs, *rhs]
RemainderAssign = 44
Remainder-assign rhs -> lhs
[*lhs, *rhs]
Less = 45
Compares lhs and rhs using the ‘<’ operator
[*result, *lhs, *rhs]
LessOrEqual = 46
Compares lhs and rhs using the ‘<=’ operator
[*result, *lhs, *rhs]
Greater = 47
Compares lhs and rhs using the ‘>’ operator
[*result, *lhs, *rhs]
GreaterOrEqual = 48
Compares lhs and rhs using the ‘>=’ operator
[*result, *lhs, *rhs]
Equal = 49
Compares lhs and rhs using the ‘==’ operator
[*result, *lhs, *rhs]
NotEqual = 50
Compares lhs and rhs using the ‘!=’ operator
[*result, *lhs, *rhs]
Jump = 51
Causes the instruction pointer to jump forward by a number of bytes
[offset[2]]
JumpBack = 52
Causes the instruction pointer to jump back by a number of bytes
[offset[2]]
JumpIfTrue = 53
Causes the instruction pointer to jump forward, if a condition is true
[*condition, offset[2]]
JumpIfFalse = 54
Causes the instruction pointer to jump forward, if a condition is false
[*condition, offset[2]]
Call = 55
Calls a function
[*result, *function, *first arg, arg count]
CallInstance = 56
Calls an instance function
[*result, *function, *first arg, arg count, *instance]
Return = 57
Returns from the current frame with the given result
[*result]
Yield = 58
Yields a value from the current generator
[*value]
Throw = 59
Throws an error
[*error]
IterNext = 60
Gets the next value from an Iterator
The output from the iterator is placed in the output register. If the iterator is finished then the instruction jumps forward by the given offset.
[*output, *iterator, offset[2]]
IterNextTemp = 61
Gets the next value from an Iterator, used when the output is treated as temporary
The output from the iterator is placed in the output register. The output is treated as temporary, with assigned values being unpacked from the output.
- e.g.
for key, value in mapIf the iterator is finished then the instruction jumps forward by the given offset.
[*output, *iterator, offset[2]]
IterNextQuiet = 62
Gets the next value from an Iterator, used when the output can be ignored
If the iterator is finished then the instruction jumps forward by the given offset.
[*iterator, offset[2]]
IterUnpack = 63
Gets the next value from an Iterator, used during value unpacking
If the iterator is finished then null is assigned to the target register.
[*output, *iterator]
TempIndex = 64
Accesses a contained value from a temporary value using a u8 index
This is used for internal indexing operations. e.g. when unpacking a temporary value in multi-assignment
[*result, *value, index]
SliceFrom = 65
Takes a slice from the end of a given List or Tuple, starting from a u8 index
Used in unpacking expressions, e.g. in a match arm
[*result, *value, index]
SliceTo = 66
Takes a slice from the start of a given List or Tuple, ending at a u8 index
Used in unpacking expressions, e.g. in a match arm
[*result, *value, index]
Index = 67
Accesses a contained value via index
[*result, *indexable, *index]
SetIndex = 68
Sets a contained value via index
[*indexable, *value, *index]
MapInsert = 69
Inserts a key/value entry into a map
[*map, *key, *value]
MetaInsert = 70
Inserts a key/value entry into a map’s metamap
[*map, *key, *value]
MetaInsertNamed = 71
Inserts a named key/value entry into a map’s metamap
Used for meta keys that take a name as part of the key, like @test or @meta
[*map, *key, *name, *value]
MetaExport = 72
Adds a key/value entry into the module’s exported metamap
Used for expressions like @tests = ...
[*key, *value]
MetaExportNamed = 73
Adds a named key/value entry into the module’s exported metamap
Used for expressions like @tests = ...
[*key, *name, *value]
ValueExport = 74
Exports a value by adding it to the module’s exports map
Used for expressions like export foo = ...
[*name, *value]
Access = 75
Accesses a contained value via a constant key
[*target, @constant]
AccessString = 76
Access a contained value via a string key
Used in ‘.’ access operations that use a quoted string, e.g. foo."bar".
[*result, *value, *key]
IsList = 77
Sets the result register to true if the value is a List
[*result, *value]
IsTuple = 78
Sets the result register to true if the value is a Tuple
[*result, *value]
Size = 79
Gets the size of a value
[*result, *value]
TryStart = 80
Starts a try block
If an error is thrown in the try block then the error will be placed in the error register and the instruction pointer will be jumped forward to the location referred to by the catch offset.
[*error, catch offset[2]]
TryEnd = 81
Ends a try block
[]
Debug = 82
Displays the contents of a value along with the source expression that produced it
[*value, @expression constant]
CheckType = 83
Throws an error if the value doesn’t match the expected type
Used when matching function arguments.
See TypeId for the list of types that are checked against.
[*value, type]
CheckSizeEqual = 84
Throws an error if the value doesn’t match the expected size
Used when matching function arguments.
[*value, size]
CheckSizeMin = 85
Throws an error if the value isn’t at least the expected size
Used when matching function arguments.
[*value, size]