glados-0.1.0.0
Stabilitystable
Safe HaskellNone
LanguageHaskell2010

VM.Instruction.Function

Description

Handles the creation and destruction of stack frames (CallSnapshots). Ensures proper scope management and control flow between functions.

Synopsis

Documentation

instCall :: VirtualMachine () Source #

Implements CALL (Opcode 0x40).

@details Static call. Reads relative offset, calculates target, and delegates frame setup.

instTailCall :: VirtualMachine () Source #

Implements TAIL_CALL (Opcode 0x41).

@details Optimized call. Replaces current frame (no snapshot pushed).

instCallIndirect :: VirtualMachine () Source #

Implements CALL_INDIRECT (Opcode 0x42).

@details Pops the top value and delegates to dispatchIndirectCall.

instRet :: VirtualMachine () Source #

Implements RET (Opcode 0x43).

@details 1. Pops the return value from the top of the stack. 2. Retrieves and removes the top CallSnapshot. 3. Cleans the stack by truncating it to the start of the current frame. This effectively discards all local variables. 4. Restores the Caller's context (IP and FP). 5. Pushes the return value back onto the restored stack.

@throws Error "VM Error: Return called with empty call stack" if executed in global scope.

instMakeClosure :: VirtualMachine () Source #

Implements MAKE_CLOSURE (Opcode 0x60).

@details Reads arguments then checks if the stack has enough elements. If yes, calls pushClosure.

instGetFuncAddr :: VirtualMachine () Source #

Implements GET_FUNC_ADDR (Opcode 0x61).

@details Reads an absolute address (Int) and pushes it as a VFuncPtr. Used to pass functions as values before potentially wrapping them in closures.