glados-0.1.0.0
Stabilitystable
Safe HaskellNone
LanguageHaskell2010

VM.Instruction.Index

Description

Handles relative jumps and conditional branching instructions. These instructions modify the bytecodeIndex (Instruction Pointer) of the VMState.

Synopsis

Documentation

instJump :: VirtualMachine () Source #

Implements Unconditional Jump (Opcode 0x30).

@details 1. Reads a signed 32-bit integer (offset) from the bytecode. 2. Adds this offset to the current bytecodeIndex.

Note: Since readInt32 advances the index by 4 bytes, the offset is effectively relative to the instruction immediately following the JUMP.

instJumpIfFalse :: VirtualMachine () Source #

Implements Jump If False (Opcode 0x31).

@details Conditional jump used for 'if' statements and loops. 1. Reads the jump offset. 2. Pops a value from the stack. 3. If the value is 'VBool False', applies the jump. 4. If 'VBool True', continues execution normally (fall-through).

@throws Error "VM Error: JUMP_IF_FALSE expects Boolean" if the popped value is not a boolean.

instJumpIfTrue :: VirtualMachine () Source #

Implements Jump If True (Opcode 0x32).

@details Conditional jump (reverse logic of JumpIfFalse). 1. Reads the jump offset. 2. Pops a value from the stack. 3. If the value is 'VBool True', applies the jump.

@throws Error "VM Error: JUMP_IF_TRUE expects Boolean" if the popped value is not a boolean.