Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Bond::StackFrame Class Reference

The activation record of a function invoked by a VM. More...

#include <bond/vm/vm.h>

Public Member Functions

 StackFrame (VM &vm)
 Constructs a StackFrame object that is not associated with any function.
 StackFrame (VM &vm, const Function &function, uint8_t *framePointer, uint8_t *stackPointer, uint8_t *returnPointer)
 Constructs a StackFrame object for an invocation of the given function.
 StackFrame (const StackFrame &other)=delete
StackFrame & operator= (const StackFrame &other)=delete
template<typename ArgType>
const ArgType & GetArg (size_t index) const
 Returns a reference to an argument of the invoked function.
template<typename ReturnType>
void SetReturnValue (const ReturnType &returnValue)
 Sets the return value of the invoked function.
VM & GetVM ()
 Returns the VM that owns the stack frame.
const VM & GetVM () const
 Returns the VM that owns the stack frame.
Collector & GetCollector ()
 Returns the Collector whose Collectable objects are destroyed when the stack frame is popped off of the VM's call stack.
const Collector & GetCollector () const
 Returns the Collector whose Collectable objects are destroyed when the stack frame is popped off of the VM's call stack.

Friends

class VM
class InvocationStackFrame

Detailed Description

The activation record of a function invoked by a VM.

A StackFrame gives access to the arguments and return value of a function call. Native functions receive the StackFrame of their own invocation, through which they read their arguments with GetArg() and set their return value with SetReturnValue(). StackFrames are created and destroyed by the VM and by InvocationStackFrame; they are not constructed directly by applications.

See also
InvocationStackFrame, NativeFunction, VM

Constructor & Destructor Documentation

◆ StackFrame() [1/3]

Bond::StackFrame::StackFrame ( VM & vm)
inlineexplicit

Constructs a StackFrame object that is not associated with any function.

Parameters
vmThe VM that owns the stack frame.

◆ StackFrame() [2/3]

Bond::StackFrame::StackFrame ( VM & vm,
const Function & function,
uint8_t * framePointer,
uint8_t * stackPointer,
uint8_t * returnPointer )
inline

Constructs a StackFrame object for an invocation of the given function.

Parameters
vmThe VM that owns the stack frame.
functionThe function being invoked.
framePointerPointer to the base of the function's frame on the VM stack, relative to which its arguments and local variables are addressed.
stackPointerPointer to the top of the function's frame on the VM stack.
returnPointerPointer to where the function's return value is written, or null if the function returns void.

◆ StackFrame() [3/3]

Bond::StackFrame::StackFrame ( const StackFrame & other)
delete

Member Function Documentation

◆ GetArg()

template<typename ArgType>
const ArgType & Bond::StackFrame::GetArg ( size_t index) const

Returns a reference to an argument of the invoked function.

When BOND_RUNTIME_CHECKS_ENABLED is non-zero, a Bond::Exception is thrown if the index is out of range or if ArgType does not match the type of the parameter. Integer types match any Bond integer type of the same size, regardless of signedness.

Template Parameters
ArgTypeThe native type of the argument.
Parameters
indexThe zero-based index of the argument.

◆ GetCollector() [1/2]

Collector & Bond::StackFrame::GetCollector ( )
inline

Returns the Collector whose Collectable objects are destroyed when the stack frame is popped off of the VM's call stack.

A native function that allocates memory or objects on behalf of the calling Bond function typically registers them with the Collector of the caller's stack frame, obtained with VM::GetCallerStackFrame(), so that they live until the caller returns.

◆ GetCollector() [2/2]

const Collector & Bond::StackFrame::GetCollector ( ) const
inline

Returns the Collector whose Collectable objects are destroyed when the stack frame is popped off of the VM's call stack.

◆ GetVM() [1/2]

VM & Bond::StackFrame::GetVM ( )
inline

Returns the VM that owns the stack frame.

◆ GetVM() [2/2]

const VM & Bond::StackFrame::GetVM ( ) const
inline

Returns the VM that owns the stack frame.

◆ operator=()

StackFrame & Bond::StackFrame::operator= ( const StackFrame & other)
delete

◆ SetReturnValue()

template<typename ReturnType>
void Bond::StackFrame::SetReturnValue ( const ReturnType & returnValue)

Sets the return value of the invoked function.

Integers smaller than 32 bits are widened to 32 bits according to the Bond return type, and enums are stored as their underlying type. When BOND_RUNTIME_CHECKS_ENABLED is non-zero, a Bond::Exception is thrown if ReturnType does not match the return type of the function.

Template Parameters
ReturnTypeThe native type of the return value.
Parameters
returnValueThe value to be returned.

◆ InvocationStackFrame

friend class InvocationStackFrame
friend

◆ VM

friend class VM
friend

The documentation for this class was generated from the following file:
  • include/bond/vm/vm.h