Class ExContext
Represents the execution context of the virtual machine, maintaining the state during program execution.
Inherited Members
Namespace: VM.Core
Assembly: VM.dll
Syntax
public class ExContext
Remarks
The execution context includes:
- Data stack for operand storage
- Call stack for function calls
- Local variables storage
- Bytecode being executed
- Instruction pointer tracking current execution position
Fields
LocalVariables
Gets the dictionary of local variables available in the current scope.
Declaration
public Dictionary<int, VmValue> LocalVariables
Field Value
Type | Description |
---|---|
Dictionary<int, VmValue> |
Remarks
Local variables are stored with their integer identifiers as keys.
Properties
Bytecode
Gets the current bytecode being executed by the virtual machine.
Declaration
public byte[] Bytecode { get; }
Property Value
Type | Description |
---|---|
byte[] |
CallStack
Gets the call stack used for managing function calls and returns.
Declaration
public CallStack CallStack { get; }
Property Value
Type | Description |
---|---|
CallStack |
DataStack
Gets the data stack used for storing operands during execution.
Declaration
public DataStack DataStack { get; }
Property Value
Type | Description |
---|---|
DataStack |
InstructionPointer
Gets or sets the current instruction pointer (IP) position in the bytecode.
Declaration
public int InstructionPointer { get; set; }
Property Value
Type | Description |
---|---|
int |
Remarks
The instruction pointer indicates the next byte to be read from the bytecode.
Methods
LoadCode(byte[])
Loads new bytecode into the execution context and resets the instruction pointer.
Declaration
public void LoadCode(byte[] bytecode)
Parameters
Type | Name | Description |
---|---|---|
byte[] | bytecode | The bytecode program to load. |
ReadByte()
Reads a single byte from the current position in the bytecode.
Declaration
public byte ReadByte()
Returns
Type | Description |
---|---|
byte | The byte read from the bytecode. |
Remarks
Advances the instruction pointer by 1 byte after reading.
Exceptions
Type | Condition |
---|---|
VmException | Thrown when attempting to read beyond the bytecode boundary. |
ReadBytes(int)
Reads a specified number of bytes from the current position in the bytecode.
Declaration
public byte[] ReadBytes(int count)
Parameters
Type | Name | Description |
---|---|---|
int | count | The number of bytes to read. |
Returns
Type | Description |
---|---|
byte[] | An array containing the requested bytes. |
Remarks
Advances the instruction pointer by the number of bytes read.
Exceptions
Type | Condition |
---|---|
VmException | Thrown when attempting to read beyond the bytecode boundary. |
ReadInt()
Reads a 32-bit signed integer from the current position in the bytecode.
Declaration
public int ReadInt()
Returns
Type | Description |
---|---|
int | The 32-bit signed integer read from the bytecode. |
Remarks
Advances the instruction pointer by 4 bytes after reading.
ReadShort()
Reads a 16-bit signed integer from the current position in the bytecode.
Declaration
public short ReadShort()
Returns
Type | Description |
---|---|
short | The 16-bit signed integer read from the bytecode. |
Remarks
Advances the instruction pointer by 2 bytes after reading.