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

Sets up and invokes a call to a Bond function from native code. More...

#include <bond/vm/vm.h>

Inheritance diagram for Bond::InvocationStackFrame:

Public Member Functions

 InvocationStackFrame (VM &vm, const QualifiedName &functionName)
 Constructs an InvocationStackFrame object for a call to a function that returns void.
 InvocationStackFrame (VM &vm, const char *functionName)
 Constructs an InvocationStackFrame object for a call to a function that returns void.
 InvocationStackFrame (VM &vm, const Function &function)
 Constructs an InvocationStackFrame object for a call to a function that returns void.
template<typename ReturnType>
 InvocationStackFrame (VM &vm, const QualifiedName &functionName, ReturnType *returnPointer)
 Constructs an InvocationStackFrame object for a call to a function that returns a value.
template<typename ReturnType>
 InvocationStackFrame (VM &vm, const char *functionName, ReturnType *returnPointer)
 Constructs an InvocationStackFrame object for a call to a function that returns a value.
template<typename ReturnType>
 InvocationStackFrame (VM &vm, const Function &function, ReturnType *returnPointer)
 Constructs an InvocationStackFrame object for a call to a function that returns a value.
template<typename ArgType>
void PushArg (const ArgType &arg)
 Pushes the next argument of the function call.
template<typename... Args>
void PushArgs (Args... args)
 Pushes the next arguments of the function call, in order, as if by calling PushArg() for each of them.
void Call ()
 Invokes the function. Must be called after all of its arguments have been pushed.
InvocationStackFrame & operator= (const InvocationStackFrame &other)=delete

Detailed Description

Sets up and invokes a call to a Bond function from native code.

Constructing an InvocationStackFrame pushes a new StackFrame onto the VM's call stack, and destroying it pops the frame off. Arguments are pushed in order with PushArg() or PushArgs(), after which the function is invoked with Call(). Since the frame is popped by the destructor, InvocationStackFrames must be destroyed in the reverse order of their construction, which is naturally the case when they are local variables.

The constructors that look up a function by name throw a Bond::Exception if no such function exists in the VM's CodeSegment, and all constructors throw a Bond::Exception if the frame does not fit on the VM stack. When BOND_RUNTIME_CHECKS_ENABLED is non-zero, the constructors also validate the return type, PushArg() validates the argument types and count, and Call() validates that all arguments have been pushed. Violations throw a Bond::Exception.

VM::CallFunction and VM::CallVoidFunction are convenient alternatives for calls whose arguments are all known up front.

See also
StackFrame, VM

Constructor & Destructor Documentation

◆ InvocationStackFrame() [1/6]

Bond::InvocationStackFrame::InvocationStackFrame ( VM & vm,
const QualifiedName & functionName )

Constructs an InvocationStackFrame object for a call to a function that returns void.

Parameters
vmThe VM on which the function is invoked.
functionNameThe fully qualified name of the function.

◆ InvocationStackFrame() [2/6]

Bond::InvocationStackFrame::InvocationStackFrame ( VM & vm,
const char * functionName )

Constructs an InvocationStackFrame object for a call to a function that returns void.

Parameters
vmThe VM on which the function is invoked.
functionNameThe fully qualified name of the function with its elements separated by the '.' character, e.g. "Namespace.Function".

◆ InvocationStackFrame() [3/6]

Bond::InvocationStackFrame::InvocationStackFrame ( VM & vm,
const Function & function )

Constructs an InvocationStackFrame object for a call to a function that returns void.

Parameters
vmThe VM on which the function is invoked.
functionThe function to be invoked. It must belong to the VM's CodeSegment.

◆ InvocationStackFrame() [4/6]

template<typename ReturnType>
Bond::InvocationStackFrame::InvocationStackFrame ( VM & vm,
const QualifiedName & functionName,
ReturnType * returnPointer )

Constructs an InvocationStackFrame object for a call to a function that returns a value.

Template Parameters
ReturnTypeThe native type of the return value. Integers smaller than 32 bits are returned widened to 32 bits, so they must be received in an int32_t or uint32_t.
Parameters
vmThe VM on which the function is invoked.
functionNameThe fully qualified name of the function.
returnPointerPointer to where the return value is written. It must remain valid until Call() returns.

◆ InvocationStackFrame() [5/6]

template<typename ReturnType>
Bond::InvocationStackFrame::InvocationStackFrame ( VM & vm,
const char * functionName,
ReturnType * returnPointer )

Constructs an InvocationStackFrame object for a call to a function that returns a value.

Template Parameters
ReturnTypeThe native type of the return value. Integers smaller than 32 bits are returned widened to 32 bits, so they must be received in an int32_t or uint32_t.
Parameters
vmThe VM on which the function is invoked.
functionNameThe fully qualified name of the function with its elements separated by the '.' character, e.g. "Namespace.Function".
returnPointerPointer to where the return value is written. It must remain valid until Call() returns.

◆ InvocationStackFrame() [6/6]

template<typename ReturnType>
Bond::InvocationStackFrame::InvocationStackFrame ( VM & vm,
const Function & function,
ReturnType * returnPointer )

Constructs an InvocationStackFrame object for a call to a function that returns a value.

Template Parameters
ReturnTypeThe native type of the return value. Integers smaller than 32 bits are returned widened to 32 bits, so they must be received in an int32_t or uint32_t.
Parameters
vmThe VM on which the function is invoked.
functionThe function to be invoked. It must belong to the VM's CodeSegment.
returnPointerPointer to where the return value is written. It must remain valid until Call() returns.

Member Function Documentation

◆ Call()

void Bond::InvocationStackFrame::Call ( )

Invokes the function. Must be called after all of its arguments have been pushed.

◆ operator=()

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

◆ PushArg()

template<typename ArgType>
void Bond::InvocationStackFrame::PushArg ( const ArgType & arg)

Pushes the next argument of the function call.

Enums are passed as their underlying type and nullptr is passed as a null void pointer.

Template Parameters
ArgTypeThe native type of the argument.
Parameters
argThe value of the argument.

◆ PushArgs()

template<typename... Args>
void Bond::InvocationStackFrame::PushArgs ( Args... args)

Pushes the next arguments of the function call, in order, as if by calling PushArg() for each of them.

Parameters
argsThe values of the arguments.

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