pub struct VirtualMachine { /* private fields */ }
Expand description

A running instance of a virtual machine.

All internal registers are initialized to zero at start up. The type exposes methods to either submit new data (iinput, dinput) or to extract results (ioutput, doutput).

Operand addresses are evaluated modulo the size of the register array they refer to, to keep them within the allocated memory for that array.

This type is not thread safe. However, multiple instances do not share state and so can be used concurrently (for example, one virtual machine instance per thread) without interfering with each other.

Implementations

Create a new instance of a virtual machine. This is the main method exposed by the crate.

Arguments
  • architecture - Configuration of memory sizes and other parameters.
  • instructions - Instructions to execute.

Call to run the virtual machine until one of the following criteria are met.

Stopping Criteria
  • SYN instruction executed. Caller should use results in output memory, update input memory if required and call run again.
  • HLT instruction executed. Execution has finished. Caller should use results in output memory and not call run again.
  • The maximum number of instructions has been executed. Execution has finished. Caller should use results in output memory and not call run again.
End of code behavior

Code execution will jump back to the first instruction on reaching the end of the provided instructions (ie wraps around). To prevent this behaviour, add a HLT instruction as the last instruction.

Arguments
  • budget - The maximum number of instructions to implement.

A modifiable bank of integers that act as input to the virtual machine.

A bank of floating point values that act as input to the virtual machine.

A snapshot of the bank of integers that act as output from the virtual machine.

A snapshot of the bank of floating point values that act as output from the virtual machine.

A snapshot copy of the memory of the virtual machine.

The next instruction to execute.

The next instruction to execute.

The number of instructions executed so far.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.