| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
VM.VMState
Synopsis
- data VMState = VMState {
- bytecode :: ByteString
- bytecodeIndex :: Int
- vStack :: Vector VMValue
- baseVStackIndex :: Int
- snapshotStack :: [CallSnapshot]
- env :: Vector VMValue
- globalEnv :: Vector VMValue
- isRunning :: Bool
- isDebug :: Bool
- vmFds :: Map Int Handle
- nextFd :: Int
- type VirtualMachine a = StateT VMState IO a
- createVMState :: ByteString -> Bool -> VMState
- createSnapshot :: VMState -> CallSnapshot
- doSnapshot :: Int -> Vector VMValue -> VirtualMachine ()
Documentation
The core state of the Virtual Machine.
@details This structure holds the entire context of the executing program at any given microsecond. It includes memory (stack, heap/globals), the processor registers (IP, FP), and the code itself.
Constructors
| VMState | |
Fields
| |
createVMState :: ByteString -> Bool -> VMState Source #
Creates the initial state of the VM for a given program.
@args - code: The compiled binary code to execute.
@return
A pristine VMState ready for execution.
createSnapshot :: VMState -> CallSnapshot Source #
Creates a snapshot of the current VM context (IP, FP, Env).
@args - vm: The current VM state.
@details Captures the current Instruction Pointer, Frame Pointer, and Closure Environment. Used by CALL instructions to save the state before jumping.
@return
A CallSnapshot containing the saved context.
doSnapshot :: Int -> Vector VMValue -> VirtualMachine () Source #
Sets up a new stack frame for a function call (Shared Logic).
@args - idx: The absolute address (index) to jump to. - newEnv: The closure environment to load (empty for static calls).
@details 1. Creates and pushes a snapshot of the current state. 2. Updates FP (baseVStackIndex) and IP (bytecodeIndex). 3. Sets the new environment.
@return Unit. State is modified.