ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
VirtualMachine::Command Class Reference

Description:

A command of the VM.

Definition at line 36 of file virtualmachine.hpp.

#include <virtualmachine.hpp>

Collaboration diagram for VirtualMachine::Command:
[legend]

Inner Type Index:

struct  DbgInformation
 
union  OperationParam
 A union of different parameter types for the commands. More...
 

Public Type Index:

enum  Bits { CMD_MASK = 0x07 , FlagEOC = 0x08 , CMD_MASK_WITH_EOC = 0x0F , TYPE_MASK = 0xF0 }
 Some meanings and masks of field bits. More...
 
enum class  JumpType { Conditional , Unconditional }
 Denotes the two different jump types (used only as parameter, not stored.) More...
 
enum  ListingTypes {
  LiteralConstant = 0x00 , OptimizationConstant = 0x10 , UnaryOp = 0x20 , BinaryOp = 0x30 ,
  Identifier = 0x40 , FunctionCall = 0x50 , AutoCast = 0x60 , NestedExpression = 0x70
}
 Denotes the type of parsing de-compilation information attached to the command. More...
 
enum  OpCodes {
  Constant = 0 , Function = 1 , Subroutine = 2 , JumpIfFalse = 4 ,
  Jump = 5
}
 The opcode type of VM commands. More...
 

Public Field Index:

DbgInformation DbgInfo
 Operation code of this command. Available only with debug-builds.
 
String DecompileSymbol
 
uinteger ExpressionPositions
 
OperationParam Parameter
 The parameter of the operation.
 
Box ResultType
 

Public Method Index:

 Command (CallbackDecl callback, bool isIdentifier, int qtyFunctionArgs, const Box &resultType, const String &functionOrOp, bool isOperator, integer idxOriginal, integer idxNormalized)
 
 Command (const Box &value, bool isOptimization, integer idxOriginal, integer idxNormalized)
 
 Command (integer idxOriginal, integer idxNormalized, JumpType jumpType)
 
ALIB_API Command (Program *program, const Box &resultType, const String &functionOrOp, integer idxOriginal, integer idxNormalized)
 
bool HasArgs () const
 
bool IsConstant () const
 
bool IsIdentifier () const
 
bool IsJump () const
 
constexpr OpCodes OpCode () const
 
int QtyArgs () const
 
void SetEndOfConditionalFlag ()
 Marks the command as the end of a conditional term.
 
constexpr ListingTypes TerminalType () const
 

Protected Field Index:

int16_t bits
 Operation code of this command.
 
uint16_t qtyArgs
 

Enumeration Details:

◆ Bits

enum Bits

Some meanings and masks of field bits.

Enumerator
CMD_MASK 

Used to mask the command out of an opcode.

FlagEOC 

Flags a command to be the last of a conditional.

CMD_MASK_WITH_EOC 

Used to mask the command out of an opcode, including the EOC flag.

TYPE_MASK 

The mask for the ListingTypes.

Definition at line 40 of file virtualmachine.hpp.

◆ JumpType

enum class JumpType
strong

Denotes the two different jump types (used only as parameter, not stored.)

Enumerator
Conditional 

Denotes JumpIfFalse.

Unconditional 

Denotes Jump.

Definition at line 75 of file virtualmachine.hpp.

◆ ListingTypes

Denotes the type of parsing de-compilation information attached to the command.

Enumerator
LiteralConstant 

Command results from a literal constant.

OptimizationConstant 

Command results from a constant resulting from an optimization.

UnaryOp 

Command results from an unary operator.

BinaryOp 

Command results from a binary operator.

Identifier 

Command results from a function call with no parenthesis given.

FunctionCall 

Command results from a function call.

AutoCast 

Command results from an automatically inserted cast.

NestedExpression 

Command results from a nested expression.

Definition at line 62 of file virtualmachine.hpp.

◆ OpCodes

enum OpCodes

The opcode type of VM commands.

Enumerator
Constant 

Pushes a constant to the stack.

Function 

Invokes a C++ callback function.

Subroutine 

Invokes another program.

JumpIfFalse 

Jumps if top of the stack indicates false.

Jump 

Jumps.

Definition at line 50 of file virtualmachine.hpp.

Field Details:

◆ bits

int16_t bits
protected

Operation code of this command.

Definition at line 121 of file virtualmachine.hpp.

◆ DbgInfo

DbgInformation DbgInfo

Operation code of this command. Available only with debug-builds.

Definition at line 152 of file virtualmachine.hpp.

◆ DecompileSymbol

String DecompileSymbol

The operator symbol or function name used with de-compilation to recreate an expression string.

Definition at line 147 of file virtualmachine.hpp.

◆ ExpressionPositions

uinteger ExpressionPositions

This encodes both, the position in the original and in the normalized expression string that resulted in this command. Used for generation of exception information and debug listings.

Definition at line 142 of file virtualmachine.hpp.

◆ Parameter

OperationParam Parameter

The parameter of the operation.

Definition at line 133 of file virtualmachine.hpp.

◆ qtyArgs

uint16_t qtyArgs
protected

The number of function args. If negative, this indicates that the function name was given as an 'identifier', what means that no brackets '()' had been added. This piece of information (namely having a signed integer here which allows differentiating between 0 and a negative number of arguments) is used when decompiling a program back to an expression string. Hence, this piece of it logically belongs to ListingTypes.

Definition at line 129 of file virtualmachine.hpp.

◆ ResultType

Box ResultType

With every command, this box contains the result type. For constants, also the commands' value is contained.

Definition at line 137 of file virtualmachine.hpp.

Constructor(s) / Destructor Details:

◆ Command() [1/4]

Command ( const Box & value,
bool isOptimization,
integer idxOriginal,
integer idxNormalized )
inline

Constructor creating a constant.

Parameters
valueThe constant to add.
isOptimizationDenotes if the constant results from an optimization or from a literal of the expression string.
idxOriginalExpression string index that imposed command.
idxNormalizedNormalized expression string index that imposed command.

Definition at line 161 of file virtualmachine.hpp.

◆ Command() [2/4]

Command ( CallbackDecl callback,
bool isIdentifier,
int qtyFunctionArgs,
const Box & resultType,
const String & functionOrOp,
bool isOperator,
integer idxOriginal,
integer idxNormalized )
inline

Constructor creating a native function call exposed from an identifier, function or operator.

Parameters
callbackThe callback function.
isIdentifierIf no parentheses were given, this has to be true. Otherwise it is a function call.
qtyFunctionArgsThe number of arguments that the callback function expects.
resultTypeThe result type of the function.
functionOrOpThe identifier, function or operator name/symbol. This is used for de-compilation of programs.
isOperatorIf true an unary operator was compiled, a binary operator otherwise.
idxOriginalExpression string index that imposed command.
idxNormalizedNormalized expression string index that imposed command.

Definition at line 185 of file virtualmachine.hpp.

◆ Command() [3/4]

Command ( Program * program,
const Box & resultType,
const String & functionOrOp,
integer idxOriginal,
integer idxNormalized )

Constructor creating a subroutine call.

Parameters
programThe program to call.
resultTypeThe result type of the program.
functionOrOpThe function or operator that created the nested call.
idxOriginalExpression string index that imposed command.
idxNormalizedNormalized expression string index that imposed command.

Definition at line 24 of file virtualmachine.cpp.

◆ Command() [4/4]

Command ( integer idxOriginal,
integer idxNormalized,
JumpType jumpType )
inline

Constructor creating a jump. Note, the address is usually not known yet, hence not provided.

Parameters
jumpTypeThe type of jump.
idxOriginalExpression string index that imposed command.
idxNormalizedNormalized expression string index that imposed command.

Definition at line 217 of file virtualmachine.hpp.

Method Details:

◆ HasArgs()

bool HasArgs ( ) const
inline
Returns
true if the function has arguments, false otherwise.

Definition at line 248 of file virtualmachine.hpp.

◆ IsConstant()

bool IsConstant ( ) const
inline

Returns true if the command represents a constant value, but is not the end of a conditional jump.

Returns
true if the command represents a constant value, false otherwise.

Definition at line 237 of file virtualmachine.hpp.

◆ IsIdentifier()

bool IsIdentifier ( ) const
inline
Returns
true if the function has arguments, false otherwise.

Definition at line 251 of file virtualmachine.hpp.

◆ IsJump()

bool IsJump ( ) const
inline

Returns true if the command represents a conditional or unconditional jump.

Returns
true if the command represents a jump, false otherwise.

Definition at line 242 of file virtualmachine.hpp.

◆ OpCode()

OpCodes OpCode ( ) const
inlineconstexpr

Returns the opcode of this command.

Returns
The masked command part of the opcode.

Definition at line 228 of file virtualmachine.hpp.

◆ QtyArgs()

int QtyArgs ( ) const
inline
Returns
The number of arguments of a function call.

Definition at line 254 of file virtualmachine.hpp.

◆ SetEndOfConditionalFlag()

void SetEndOfConditionalFlag ( )
inline

Marks the command as the end of a conditional term.

Definition at line 245 of file virtualmachine.hpp.

◆ TerminalType()

ListingTypes TerminalType ( ) const
inlineconstexpr

Returns the decompile type of this command.

Returns
The masked command part of the opcode.

Definition at line 232 of file virtualmachine.hpp.


The documentation for this class was generated from the following files: