The VirtualMachine Class

The VirtualMachine base class provides an interface for VM implementations that can run BEAST byte code programs. The CpuVirtualMachine Class is one such concrete implementation.

class VirtualMachine

A base class for virtual machine types to execute BEAST code.

This base class provides messaging functionalities and a base function signature to allow integrating different types of virtual machines that are executing BEAST instructions.

Author
Jan Winkler
Date
2022-12-19

Subclassed by beast::CpuVirtualMachine

Public Functions

VirtualMachine()

Constructor for the VirtualMachine base class.

This is the base class constructor for all virtual machine implementations.

~VirtualMachine()

Virtual destructor performing no operation to ensure vtable consistency.

setMinimumMessageSeverity(MessageSeverity minimum_severity)

Sets the minimum message severity for displaying messages.

If a message to be printed is below the minimum severity, it is silently dropped. The default severity is MessageSeverity::Info. To display all messages (including a trace of executed operators and their operands), set the severity to MessageSeverity::Debug.

step(VmSession &session, bool dry_run) = 0

Executes the next step a program in its current state as denoted by a VM session.

This function must be implemented by subclasses of the VirtualMachine class. A VmSession is passed in that contains a program to execute, and a state at which the program currently is (including instruction pointer, variable memory, and string table).

When the dry_run parameter is passed, the VM is supposed to only step through the operations in a program and not actually execute them. This can be used to count the effective amount and individual types of operators in a program, as well as analyze its structure.

Return
A boolean flag denoting whether the session can further execute instructions.
Parameters
  • session: The VmSession instance that holds the program and state to step through.
  • dry_run: Determines whether operators are executed or just read.