gbf_core::opcode

Enum Opcode

Source
#[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

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

Source

pub fn from_byte(byte: u8) -> Result<Self, OpcodeError>

Converts a u8 into an Opcode, if possible.

§Arguments
  • byte: The u8 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);
Source

pub fn to_byte(self) -> u8

Converts an Opcode to its u8 value.

§Returns
  • The numeric value (u8) of the opcode.
§Example
use gbf_core::opcode::Opcode;

let opcode = Opcode::Jmp;
assert_eq!(opcode.to_byte(), 0x1);
Source

pub fn count() -> usize

Get the number of defined opcodes.

§Returns
  • The number of opcodes.
§Example
use gbf_core::opcode::Opcode;

let count = Opcode::count();
Source

pub fn all() -> &'static [Opcode]

Get a list of all defined opcodes.

§Returns
  • A vector containing all defined opcodes.
§Example
use gbf_core::opcode::Opcode;

let opcodes = Opcode::all();
Source

pub fn is_conditional_jump(self) -> bool

If the opcode is a conditional jump instruction.

§Returns
  • true if the opcode is a conditional jump instruction.
  • false otherwise.
§Example
use gbf_core::opcode::Opcode;

let opcode = Opcode::Jeq;
assert!(opcode.is_conditional_jump());
Source

pub fn is_unconditional_jump(self) -> bool

If the opcode is an unconditional jump instruction.

§Returns
  • true if the opcode is an unconditional jump instruction.
  • false otherwise.
§Example
use gbf_core::opcode::Opcode;

let opcode = Opcode::Jmp;
assert!(opcode.is_unconditional_jump());
Source

pub fn has_fall_through(self) -> bool

If this CFG-related opcode contains a branch with a fall-through path to the next instruction.

§Returns
  • true if the opcode is a block-starting opcode.
  • false otherwise.
§Example
use gbf_core::opcode::Opcode;

let opcode = Opcode::Jmp;
assert!(!opcode.has_fall_through());
Source

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());
Source

pub fn has_jump_target(self) -> bool

If this CFG-related opcode has a corresponding jump target as an operand.

§Returns
  • true if the opcode has a jump target.
  • false otherwise.
§Example
use gbf_core::opcode::Opcode;

let opcode = Opcode::Jmp;
assert!(opcode.has_jump_target());
Source

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 Clone for Opcode

Source§

fn clone(&self) -> Opcode

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 Opcode

Source§

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

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

impl<'de> Deserialize<'de> for Opcode

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Opcode

Source§

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

Convert an Opcode to a human-readable string.

§Returns
  • A string representation of the opcode.
Source§

impl FromStr for Opcode

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Convert a string to an Opcode

§Arguments
  • name: The string to convert.
§Returns
  • Ok(Opcode) if the string corresponds to a valid opcode.
Source§

type Err = OpcodeError

The associated error which can be returned from parsing.
Source§

impl Hash for Opcode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Opcode

Source§

fn eq(&self, other: &Opcode) -> 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 Serialize for Opcode

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Opcode

Source§

impl Eq for Opcode

Source§

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> 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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,