#[repr(u8)]pub enum Opcode {
Show 124 variants
Jmp = 1,
Jeq = 2,
ShortCircuitOr = 3,
Jne = 4,
ShortCircuitAnd = 5,
Call = 6,
Ret = 7,
Sleep = 8,
IncreaseLoopCounter = 9,
FunctionStart = 10,
WaitFor = 11,
PushNumber = 20,
PushString = 21,
PushVariable = 22,
PushArray = 23,
PushTrue = 24,
PushFalse = 25,
PushNull = 26,
PushPi = 27,
Copy = 30,
Swap = 31,
Pop = 32,
ConvertToFloat = 33,
ConvertToString = 34,
AccessMember = 35,
ConvertToObject = 36,
EndArray = 37,
NewArray = 38,
SetArray = 39,
New = 40,
MakeVar = 41,
NewObject = 42,
ConvertToVariable = 43,
ShortCircuitEnd = 44,
SetLoopVariable = 45,
GetLoopVariable = 46,
MarkLoopVariable = 47,
Assign = 50,
EndParams = 51,
Inc = 52,
Dec = 53,
Add = 60,
Subtract = 61,
Multiply = 62,
Divide = 63,
Modulo = 64,
Power = 65,
Negate = 68,
UnarySubtract = 69,
Equal = 70,
NotEqual = 71,
LessThan = 72,
GreaterThan = 73,
LessThanOrEqual = 74,
GreaterThanOrEqual = 75,
BitwiseOr = 76,
BitwiseAnd = 77,
BitwiseXor = 78,
BitwiseInvert = 79,
InRange = 80,
In = 81,
ObjIndex = 82,
ObjType = 83,
Format = 84,
Int = 85,
Abs = 86,
Random = 87,
Sin = 88,
Cos = 89,
ArcTan = 90,
Exp = 91,
Log = 92,
Min = 93,
Max = 94,
GetAngle = 95,
GetDir = 96,
VecX = 97,
VecY = 98,
ObjIndices = 99,
ObjLink = 100,
ShiftLeft = 101,
ShiftRight = 102,
Char = 103,
ObjTrim = 110,
ObjLength = 111,
ObjPos = 112,
Join = 113,
ObjCharAt = 114,
ObjSubstring = 115,
ObjStarts = 116,
ObjEnds = 117,
ObjTokenize = 118,
GetTranslation = 119,
ObjPositions = 120,
ObjSize = 130,
AssignArrayIndex = 131,
AssignArray = 132,
AssignMultiDimensionalArrayIndex = 133,
AssignMultiDimensionalArray = 134,
ObjSubArray = 135,
ObjAddString = 136,
ObjDeleteString = 137,
ObjRemoveString = 138,
ObjReplaceString = 139,
ObjInsertString = 140,
ObjClear = 141,
MultiDimenArray = 142,
With = 150,
WithEnd = 151,
ForEach = 163,
This = 180,
ThisO = 181,
Player = 182,
PlayerO = 183,
Level = 184,
Temp = 189,
Params = 190,
ImmStringByte = 240,
ImmStringShort = 241,
ImmStringInt = 242,
ImmByte = 243,
ImmShort = 244,
ImmInt = 245,
ImmFloat = 246,
}
Expand description
Enum representing opcodes for a bytecode system.
Each variant corresponds to an opcode, with its numeric value
defined as a u8
.
Variants§
Jmp = 1
Represents the opcode Jmp
Jeq = 2
Represents the opcode Jeq
ShortCircuitOr = 3
Represents the opcode ShortCircuitOr
Jne = 4
Represents the opcode Jne
ShortCircuitAnd = 5
Represents the opcode ShortCircuitAnd
Call = 6
Represents the opcode Call
Ret = 7
Represents the opcode Ret
Sleep = 8
Represents the opcode Sleep
IncreaseLoopCounter = 9
Represents the opcode IncreaseLoopCounter
FunctionStart = 10
Represents the opcode FunctionStart
WaitFor = 11
Represents the opcode WaitFor
PushNumber = 20
Represents the opcode PushNumber
PushString = 21
Represents the opcode PushString
PushVariable = 22
Represents the opcode PushVariable
PushArray = 23
Represents the opcode PushArray
PushTrue = 24
Represents the opcode PushTrue
PushFalse = 25
Represents the opcode PushFalse
PushNull = 26
Represents the opcode PushNull
PushPi = 27
Represents the opcode PushPi
Copy = 30
Represents the opcode Copy
Swap = 31
Represents the opcode Swap
Pop = 32
Represents the opcode Pop
ConvertToFloat = 33
Represents the opcode ConvertToFloat
ConvertToString = 34
Represents the opcode ConvertToString
AccessMember = 35
Represents the opcode AccessMember
ConvertToObject = 36
Represents the opcode ConvertToObject
EndArray = 37
Represents the opcode EndArray
NewArray = 38
Represents the opcode NewArray
SetArray = 39
Represents the opcode SetArray
New = 40
Represents the opcode New
MakeVar = 41
Represents the opcode MakeVar
NewObject = 42
Represents the opcode NewObject
ConvertToVariable = 43
Represents the opcode ConvertToVariable
ShortCircuitEnd = 44
Represents the opcode ShortCircuitEnd
SetLoopVariable = 45
Represents the opcode SetLoopVariable
GetLoopVariable = 46
Represents the opcode GetLoopVariable
MarkLoopVariable = 47
Represents the opcode MarkLoopVariable
Assign = 50
Represents the opcode Assign
EndParams = 51
Represents the opcode EndParams
Inc = 52
Represents the opcode Inc
Dec = 53
Represents the opcode Dec
Add = 60
Represents the opcode Add
Subtract = 61
Represents the opcode Subtract
Multiply = 62
Represents the opcode Multiply
Divide = 63
Represents the opcode Divide
Modulo = 64
Represents the opcode Modulo
Power = 65
Represents the opcode Power
Negate = 68
Represents the opcode Negate
UnarySubtract = 69
Represents the opcode UnarySubtract
Equal = 70
Represents the opcode Equal
NotEqual = 71
Represents the opcode NotEqual
LessThan = 72
Represents the opcode LessThan
GreaterThan = 73
Represents the opcode GreaterThan
LessThanOrEqual = 74
Represents the opcode LessThanOrEqual
GreaterThanOrEqual = 75
Represents the opcode GreaterThanOrEqual
BitwiseOr = 76
Represents the opcode BitwiseOr
BitwiseAnd = 77
Represents the opcode BitwiseAnd
BitwiseXor = 78
Represents the opcode BitwiseXor
BitwiseInvert = 79
Represents the opcode BitwiseInvert
InRange = 80
Represents the opcode InRange
In = 81
Represents the opcode In
ObjIndex = 82
Represents the opcode ObjIndex
ObjType = 83
Represents the opcode ObjType
Format = 84
Represents the opcode Format
Int = 85
Represents the opcode Int
Abs = 86
Represents the opcode Abs
Random = 87
Represents the opcode Random
Sin = 88
Represents the opcode Sin
Cos = 89
Represents the opcode Cos
ArcTan = 90
Represents the opcode ArcTan
Exp = 91
Represents the opcode Exp
Log = 92
Represents the opcode Log
Min = 93
Represents the opcode Min
Max = 94
Represents the opcode Max
GetAngle = 95
Represents the opcode GetAngle
GetDir = 96
Represents the opcode GetDir
VecX = 97
Represents the opcode VecX
VecY = 98
Represents the opcode VecY
ObjIndices = 99
Represents the opcode ObjIndices
ObjLink = 100
Represents the opcode ObjLink
ShiftLeft = 101
Represents the opcode ShiftLeft
ShiftRight = 102
Represents the opcode ShiftRight
Char = 103
Represents the opcode Char
ObjTrim = 110
Represents the opcode ObjTrim
ObjLength = 111
Represents the opcode ObjLength
ObjPos = 112
Represents the opcode ObjPos
Join = 113
Represents the opcode Join
ObjCharAt = 114
Represents the opcode ObjCharAt
ObjSubstring = 115
Represents the opcode ObjSubstring
ObjStarts = 116
Represents the opcode ObjStarts
ObjEnds = 117
Represents the opcode ObjEnds
ObjTokenize = 118
Represents the opcode ObjTokenize
GetTranslation = 119
Represents the opcode GetTranslation
ObjPositions = 120
Represents the opcode ObjPositions
ObjSize = 130
Represents the opcode ObjSize
AssignArrayIndex = 131
Represents the opcode AssignArrayIndex
AssignArray = 132
Represents the opcode AssignArray
AssignMultiDimensionalArrayIndex = 133
Represents the opcode AssignMultiDimensionalArrayIndex
AssignMultiDimensionalArray = 134
Represents the opcode AssignMultiDimensionalArray
ObjSubArray = 135
Represents the opcode ObjSubArray
ObjAddString = 136
Represents the opcode ObjAddString
ObjDeleteString = 137
Represents the opcode ObjDeleteString
ObjRemoveString = 138
Represents the opcode ObjRemoveString
ObjReplaceString = 139
Represents the opcode ObjReplaceString
ObjInsertString = 140
Represents the opcode ObjInsertString
ObjClear = 141
Represents the opcode ObjClear
MultiDimenArray = 142
Represents the opcode MultiDimenArray
With = 150
Represents the opcode With
WithEnd = 151
Represents the opcode WithEnd
ForEach = 163
Represents the opcode ForEach
This = 180
Represents the opcode This
ThisO = 181
Represents the opcode ThisO
Player = 182
Represents the opcode Player
PlayerO = 183
Represents the opcode PlayerO
Level = 184
Represents the opcode Level
Temp = 189
Represents the opcode Temp
Params = 190
Represents the opcode Params
ImmStringByte = 240
Represents the opcode ImmStringByte
ImmStringShort = 241
Represents the opcode ImmStringShort
ImmStringInt = 242
Represents the opcode ImmStringInt
ImmByte = 243
Represents the opcode ImmByte
ImmShort = 244
Represents the opcode ImmShort
ImmInt = 245
Represents the opcode ImmInt
ImmFloat = 246
Represents the opcode ImmFloat
Implementations§
Source§impl Opcode
impl Opcode
Sourcepub fn from_byte(byte: u8) -> Result<Self, OpcodeError>
pub fn from_byte(byte: u8) -> Result<Self, OpcodeError>
Converts a u8
into an Opcode
, if possible.
§Arguments
byte
: Theu8
value to convert.
§Returns
Some(Opcode)
if the value corresponds to a valid opcode.None
if the value does not match any defined opcode.
§Example
use gbf_core::opcode::Opcode;
let opcode = Opcode::from_byte(0x1).unwrap();
assert_eq!(opcode, Opcode::Jmp);
Sourcepub fn is_conditional_jump(self) -> bool
pub fn is_conditional_jump(self) -> bool
Sourcepub fn is_unconditional_jump(self) -> bool
pub fn is_unconditional_jump(self) -> bool
Sourcepub fn has_fall_through(self) -> bool
pub fn has_fall_through(self) -> bool
Sourcepub fn connects_to_next_block(self) -> bool
pub fn connects_to_next_block(self) -> bool
If this CFG or non-CFG related opcode should connect to the next block if it is a terminal opcode.
§Returns
true
if the opcode has a fall-through path.false
otherwise.
§Example
use gbf_core::opcode::Opcode;
let opcode = Opcode::Jmp;
assert!(!opcode.connects_to_next_block());
let opcode2 = Opcode::Ret;
assert!(!opcode2.connects_to_next_block());
Sourcepub fn has_jump_target(self) -> bool
pub fn has_jump_target(self) -> bool
Sourcepub fn is_block_end(self) -> bool
pub fn is_block_end(self) -> bool
If this CFG-related opcode should always be the last opcode in a block. If there is an instruction that succeeds this opcode, it should be considered the start of a different block.
§Returns
true
if the opcode is block-ending.false
otherwise.
§Example
use gbf_core::opcode::Opcode;
let opcode = Opcode::Ret;
assert!(opcode.is_block_end());
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Opcode
impl<'de> Deserialize<'de> for Opcode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for Opcode
impl Eq for Opcode
impl StructuralPartialEq for Opcode
Auto Trait Implementations§
impl Freeze for Opcode
impl RefUnwindSafe for Opcode
impl Send for Opcode
impl Sync for Opcode
impl Unpin for Opcode
impl UnwindSafe for Opcode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.