| Stability | stable |
|---|---|
| Safe Haskell | None |
| Language | Haskell2010 |
VM.Bytecode.Runner
Description
This module orchestrates the execution of the Virtual Machine. It fetches opcodes from the bytecode and dispatches them to the appropriate instruction handlers defined in the Instruction modules.
Synopsis
- runBytecode :: VirtualMachine ()
- executeInstruction :: Word8 -> VirtualMachine ()
Documentation
runBytecode :: VirtualMachine () Source #
The main execution loop of the Virtual Machine.
@details
This function operates in a continuous cycle:
1. Checks if the VM isRunning flag is True.
2. Fetches the next opcode using readByte.
3. Calls executeInstruction to run the associated logic.
4. Recursively calls itself to process the next instruction.
The loop terminates when instHalt sets isRunning to False
or if an error occurs (e.g., Stack Underflow).
executeInstruction :: Word8 -> VirtualMachine () Source #
Maps a raw opcode byte to its corresponding instruction function.
@args - op: The 8-bit instruction code fetched from bytecode.
@details This pattern matching acts as the specific Decode step of the CPU cycle. Any unknown opcode will trigger a runtime error.