glados-0.1.0.0
Stabilitystable
Safe HaskellNone
LanguageHaskell2010

VM.VMStack

Description

This module provides the core abstractions to interact with the VM's operand stack. It abstracts the underlying Vector implementation and handles underflow safety checks.

Synopsis

Documentation

stackPush :: VMValue -> VirtualMachine () Source #

Pushes a value onto the top of the global value stack.

@args - val: The VMValue to push.

@details Modifies the VM state by appending the value to the end of the vStack vector. This operation is generally O(1).

stackPop :: VirtualMachine VMValue Source #

Removes and returns the value at the top of the stack.

@details Retrieves the last element of the vStack vector and removes it from the state. Uses 'case' instead of 'if' to avoid DoAndIfThenElse extension.

@throws Error "VM Error: Stack Underflow" if the stack is empty.

@return The VMValue that was at the top.

stackTop :: VirtualMachine VMValue Source #

Returns the value at the top of the stack without removing it (Peek).

@details Useful for instructions like DUP or conditional jumps that need to inspect the value without consuming it.

@throws Error "VM Error: Stack Underflow (Top)" if the stack is empty.

@return The VMValue currently at the top.