glados-0.1.0.0
Stabilitystable
Safe HaskellNone
LanguageHaskell2010

VM.Instruction.Variable

Description

Handles LOAD_LOCAL and STORE_LOCAL operations. These instructions access the stack relative to the current Frame Pointer (FP). This allows functions to access their arguments (negative offsets) and local variables (positive offsets) regardless of the absolute stack depth.

Synopsis

Documentation

instLoadLocal :: VirtualMachine () Source #

Implements LOAD_LOCAL (Opcode 0x50).

@details 1. Reads the signed 32-bit index (offset) from the bytecode. 2. Calculates the absolute index: Frame Pointer (FP) + Offset. 3. Copies the value at that index to the top of the stack.

This instruction is used to retrieve arguments and local variables.

@throws Error "VM Error: LOAD_LOCAL out of bounds" if the calculated index is outside the valid stack range.

instStoreLocal :: VirtualMachine () Source #

Implements STORE_LOCAL (Opcode 0x51).

@details 1. Reads the relative index. 2. Pops the value to store. 3. Calculates the absolute index (FP + offset). 4. Delegates to updateLocalVar to handle stack growth or update.

instLoadCapture :: VirtualMachine () Source #

Implements LOAD_CAPTURE (Opcode 0x54).

@details Accesses a variable in the current function's captured environment. 1. Reads the capture index (Int32). 2. Pushes the value at 'env[index]' onto the stack.

instStoreCapture :: VirtualMachine () Source #

Implements STORE_CAPTURE (Opcode 0x55).

@details Updates a variable in the current function's captured environment. 1. Reads the capture index. 2. Pops the new value. 3. Writes to 'env[index]'.

instLoadGlobal :: VirtualMachine () Source #

Implements LOAD_GLOBAL (Opcode 0x52).

@details Accesses the Global Environment (Heap) at the given index.

instStoreGlobal :: VirtualMachine () Source #

Implements STORE_GLOBAL (Opcode 0x53).

@details Stores the top of the stack into the Global Environment at idx.