koto_bytecode

Enum Op

Source
#[repr(u8)]
pub enum Op {
Show 256 variants NewFrame = 0, Copy = 1, SetNull = 2, SetFalse = 3, SetTrue = 4, Set0 = 5, Set1 = 6, SetNumberU8 = 7, SetNumberNegU8 = 8, LoadFloat = 9, LoadInt = 10, LoadString = 11, LoadNonLocal = 12, Import = 13, MakeTempTuple = 14, TempTupleToTuple = 15, MakeMap = 16, MakeIterator = 17, SequenceStart = 18, SequencePush = 19, SequencePushN = 20, SequenceToList = 21, SequenceToTuple = 22, StringStart = 23, StringPush = 24, StringFinish = 25, Function = 26, Capture = 27, Range = 28, RangeInclusive = 29, RangeTo = 30, RangeToInclusive = 31, RangeFrom = 32, RangeFull = 33, Negate = 34, Not = 35, Add = 36, Subtract = 37, Multiply = 38, Divide = 39, Remainder = 40, AddAssign = 41, SubtractAssign = 42, MultiplyAssign = 43, DivideAssign = 44, RemainderAssign = 45, Less = 46, LessOrEqual = 47, Greater = 48, GreaterOrEqual = 49, Equal = 50, NotEqual = 51, Jump = 52, JumpBack = 53, JumpIfFalse = 54, JumpIfTrue = 55, JumpIfNull = 56, Call = 57, CallInstance = 58, Return = 59, Yield = 60, Throw = 61, IterNext = 62, IterNextTemp = 63, IterNextQuiet = 64, IterUnpack = 65, TempIndex = 66, SliceFrom = 67, SliceTo = 68, Index = 69, IndexMut = 70, MapInsert = 71, MetaInsert = 72, MetaInsertNamed = 73, MetaExport = 74, MetaExportNamed = 75, ValueExport = 76, Access = 77, AccessString = 78, Size = 79, TryStart = 80, TryEnd = 81, Debug = 82, CheckSizeEqual = 83, CheckSizeMin = 84, AssertType = 85, AssertOptionalType = 86, CheckType = 87, CheckOptionalType = 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 (where N is at least 1) 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. Byte prefixes: * - Shows that the byte is referring to a register. @ - Indicates 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. ? - Used for optional values, the presence of which will be indicated by previous flags in the instruction.

Variants§

§

NewFrame = 0

Marks the start of a new frame

The VM will reserve space for the given number of registers used by the frame.

[registers]

§

Copy = 1

Copies the source value to the target register

[*target, *source]

§

SetNull = 2

Sets a register to contain Null

[*target]

§

SetFalse = 3

Sets a register to contain Bool(false)

[*target]

§

SetTrue = 4

Sets a register to contain Bool(true)

[*target]

§

Set0 = 5

Sets a register to contain Int(0)

[*target]

§

Set1 = 6

Sets a register to contain Int(1)

[*target]

§

SetNumberU8 = 7

Sets a register to contain Int(n)

[*target, n]

§

SetNumberNegU8 = 8

Sets a register to contain Int(-n)

[*target, n]

§

LoadFloat = 9

Loads an f64 constant into a register

[*target, @constant]

§

LoadInt = 10

Loads an i64 constant into a register

[*target, @constant]

§

LoadString = 11

Loads a string constant into a register

[*target, @constant]

§

LoadNonLocal = 12

Loads a non-local value into a register

[*target, @constant]

§

Import = 13

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 = 14

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 = 15

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 = 16

Makes an empty map with the given size hint

[*target, @size hint]

§

MakeIterator = 17

Makes an Iterator out of an iterable value

[*target, *iterable]

§

SequenceStart = 18

Starts a new sequence with the given size hint

[@size hint]

§

SequencePush = 19

Pushes a single value to the end of the current sequence

[*value]

§

SequencePushN = 20

Pushes values from consecutive registers to the end of the current sequence

[*start, value count]

§

SequenceToList = 21

Converts the current sequence into a List

[*register]

§

SequenceToTuple = 22

Converts the current sequence into a Tuple

[*register]

§

StringStart = 23

Starts the construction of a new string with a given size hint

[@size hint]

§

StringPush = 24

Pushes a value to the end of the current string

Values will be rendered and then formatted according to the specified format flags.

See StringFormatFlags for a description of the the format flags.

[*value, format_flags, ?@min_width, ?@precision, ?@fill_character]

§

StringFinish = 25

Places the finished string in the target register

[*target]

§

Function = 26

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 = 27

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 = 28

Makes a Range with defined start and end values

[*target, *start, *end]

§

RangeInclusive = 29

Makes an inclusive Range with defined start and end values

[*target, *start, *end]

§

RangeTo = 30

Makes a Range with a defined end value and no start

[*target, *end]

§

RangeToInclusive = 31

Makes an inclusive Range with a defined end value and no start

[*target, *end]

§

RangeFrom = 32

Makes a Range with a defined start value and no end

[*target, *start]

§

RangeFull = 33

Makes a full Range with undefined start and end

[*target]

§

Negate = 34

Negates a value

Used for the unary negation operator, i.e. x = -y

[*target, *source]

§

Not = 35

Flips the value of a boolean

[*target, *source]

§

Add = 36

Adds lhs and rhs together

[*result, *lhs, *rhs]

§

Subtract = 37

Subtracts rhs from lhs

[*result, *lhs, *rhs]

§

Multiply = 38

Multiplies lhs and rhs together

[*result, *lhs, *rhs]

§

Divide = 39

Divides lhs by rhs

[*result, *lhs, *rhs]

§

Remainder = 40

Performs the remainder operation with lhs and rhs

[*result, *lhs, *rhs]

§

AddAssign = 41

Add-assign rhs -> lhs

[*lhs, *rhs]

§

SubtractAssign = 42

Subtract-assign rhs -> lhs

[*lhs, *rhs]

§

MultiplyAssign = 43

Multiply-assign rhs -> lhs

[*lhs, *rhs]

§

DivideAssign = 44

Divide-assign rhs -> lhs

[*lhs, *rhs]

§

RemainderAssign = 45

Remainder-assign rhs -> lhs

[*lhs, *rhs]

§

Less = 46

Compares lhs and rhs using the ‘<’ operator

[*result, *lhs, *rhs]

§

LessOrEqual = 47

Compares lhs and rhs using the ‘<=’ operator

[*result, *lhs, *rhs]

§

Greater = 48

Compares lhs and rhs using the ‘>’ operator

[*result, *lhs, *rhs]

§

GreaterOrEqual = 49

Compares lhs and rhs using the ‘>=’ operator

[*result, *lhs, *rhs]

§

Equal = 50

Compares lhs and rhs using the ‘==’ operator

[*result, *lhs, *rhs]

§

NotEqual = 51

Compares lhs and rhs using the ‘!=’ operator

[*result, *lhs, *rhs]

§

Jump = 52

Causes the instruction pointer to jump forward by a number of bytes

[offset[2]]

§

JumpBack = 53

Causes the instruction pointer to jump back by a number of bytes

[offset[2]]

§

JumpIfFalse = 54

Jumps the instruction pointer forward if a value is false or null

[*value, offset[2]]

§

JumpIfTrue = 55

Jumps the instruction pointer forward if a value is neither false or null

[*value, offset[2]]

§

JumpIfNull = 56

Jumps the instruction pointer forward if a value is null

[*value, offset[2]]

§

Call = 57

Calls a standalone function

The frame base register (which contains the instance during a method call) will be set to Null by the runtime before the function is called.

If the result can be ignored then it will be placed in the frame base at the end of the call, which will result in it being discarded.

[*result, *function, *frame base, arg count]

§

CallInstance = 58

Calls an instance function

The instance will be copied into the frame base register by the runtime if necessary.

If the result can be ignored then it will be placed in the frame base at the end of the call, which will result in it being discarded.

[*result, *function, *instance, *frame base, arg count]

§

Return = 59

Returns from the current frame with the given result

[*result]

§

Yield = 60

Yields a value from the current generator

[*value]

§

Throw = 61

Throws an error

[*error]

§

IterNext = 62

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 = 63

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, and is treated as temporary, with assigned values being unpacked from the output.

e.g. for key, value in map

If the iterator is finished then the instruction jumps forward by the given offset.

[*output, *iterator, offset[2]]

§

IterNextQuiet = 64

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 = 65

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 = 66

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 = 67

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 = 68

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 = 69

Accesses a contained value via index

[*result, *indexable, *index]

§

IndexMut = 70

Sets a contained value via index

[*indexable, *value, *index]

§

MapInsert = 71

Inserts a key/value entry into a map

[*map, *key, *value]

§

MetaInsert = 72

Inserts a key/value entry into a map’s metamap

[*map, *key, *value]

§

MetaInsertNamed = 73

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 = 74

Adds a key/value entry into the module’s exported metamap

Used for expressions like @tests = ...

[*key, *value]

§

MetaExportNamed = 75

Adds a named key/value entry into the module’s exported metamap

Used for expressions like @tests = ...

[*key, *name, *value]

§

ValueExport = 76

Exports a value by adding it to the module’s exports map

Used for expressions like export foo = ...

[*name, *value]

§

Access = 77

Accesses a contained value via a constant key

[*target, @constant]

§

AccessString = 78

Access a contained value via a string key

Used in ‘.’ access operations that use a quoted string, e.g. foo."bar".

[*result, *value, *key]

§

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

A placeholder is used here to ensure that each op has at least one byte following it.

[placeholder]

§

Debug = 82

Displays the contents of a value along with the source expression that produced it

[*value, @expression constant]

§

CheckSizeEqual = 83

Throws an error if the value doesn’t match the expected size

Used when matching function arguments.

[*value, size]

§

CheckSizeMin = 84

Throws an error if the value isn’t at least the expected size

Used when matching function arguments.

[*value, size]

§

AssertType = 85

Throws an error if the value doesn’t match the provided type

This is used for type hints on variable declarations, and can be disabled via the compiler’s enable_type_checks flag.

[*value, @type constant]

§

AssertOptionalType = 86

Throws an error if the value doesn’t match the provided type

This is used for type hints on variable declarations, and can be disabled via the compiler’s enable_type_checks flag.

[*value, @type constant]

§

CheckType = 87

Checks if the value matches the provided type

If the value doesn’t match the type then the instruction pointer will be jumped forward to the location referred to by the jump offset.

This is used for type hints that can affect conditional logic, like match patterns.

[*value, @type constant, jump_offset[2]]

§

CheckOptionalType = 88

Checks if the value matches the provided type

If the value doesn’t match the type then the instruction pointer will be jumped forward to the location referred to by the jump offset.

This is used for type hints that can affect conditional logic, like match patterns.

[*value, @type constant, jump_offset[2]]

§

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

Trait Implementations§

Source§

impl Clone for Op

Source§

fn clone(&self) -> Op

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Op

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<u8> for Op

Source§

fn from(op: u8) -> Op

Converts to this type from the input type.
Source§

impl PartialEq for Op

Source§

fn eq(&self, other: &Op) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Op

Source§

impl Eq for Op

Source§

impl StructuralPartialEq for Op

Auto Trait Implementations§

§

impl Freeze for Op

§

impl RefUnwindSafe for Op

§

impl Send for Op

§

impl Sync for Op

§

impl Unpin for Op

§

impl UnwindSafe for Op

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.