MXVM 1.8.1
Virtual Machine, Compiler, and Pascal Frontend
Loading...
Searching...
No Matches
mxvm::RuntimeFunction Class Reference

Wraps a dynamically loaded native function from a shared library module. More...

#include <icode.hpp>

Public Member Functions

 RuntimeFunction ()
 Default constructor — null function pointer and handle.
 RuntimeFunction (const RuntimeFunction &r)
 Copy constructor.
RuntimeFunctionoperator= (const RuntimeFunction &r)
 Copy-assignment operator.
 ~RuntimeFunction ()=default
 RuntimeFunction (const std::string &mod, const std::string &name)
 Load a function symbol from a shared library.
void call (Program *program, std::vector< Operand > &operands)
 Invoke the loaded function.

Public Attributes

void * func = nullptr
 resolved function pointer
void * handle = nullptr
 dlopen handle
std::string mod_name
 module name
std::string fname
 function symbol name

Static Public Attributes

static std::unordered_map< std::string, void * > handles
 cached library handles

Detailed Description

Wraps a dynamically loaded native function from a shared library module.

Manages dlopen handles and function pointers for external module calls. Shared library handles are cached in a static map.

Definition at line 78 of file icode.hpp.

Constructor & Destructor Documentation

◆ RuntimeFunction() [1/3]

mxvm::RuntimeFunction::RuntimeFunction ( )
inline

Default constructor — null function pointer and handle.

Definition at line 81 of file icode.hpp.

References func, and handle.

Referenced by RuntimeFunction(), and operator=().

◆ RuntimeFunction() [2/3]

mxvm::RuntimeFunction::RuntimeFunction ( const RuntimeFunction & r)
inline

Copy constructor.

Definition at line 84 of file icode.hpp.

References RuntimeFunction(), fname, func, handle, and mod_name.

◆ ~RuntimeFunction()

mxvm::RuntimeFunction::~RuntimeFunction ( )
default

◆ RuntimeFunction() [3/3]

mxvm::RuntimeFunction::RuntimeFunction ( const std::string & mod,
const std::string & name )

Load a function symbol from a shared library.

Parameters
modModule/library name (without extension)
nameFunction symbol name to resolve

Definition at line 201 of file icode.cpp.

References fname, func, handle, and handles.

Member Function Documentation

◆ call()

void mxvm::RuntimeFunction::call ( Program * program,
std::vector< Operand > & operands )

Invoke the loaded function.

Parameters
programPointer to the running Program for variable access
operandsInstruction operands passed to the native function

Definition at line 224 of file icode.cpp.

References fname, func, handle, and mod_name.

◆ operator=()

RuntimeFunction & mxvm::RuntimeFunction::operator= ( const RuntimeFunction & r)
inline

Copy-assignment operator.

Definition at line 87 of file icode.hpp.

References RuntimeFunction(), fname, func, handle, and mod_name.

Member Data Documentation

◆ fname

std::string mxvm::RuntimeFunction::fname

function symbol name

Definition at line 110 of file icode.hpp.

Referenced by RuntimeFunction(), RuntimeFunction(), call(), and operator=().

◆ func

void* mxvm::RuntimeFunction::func = nullptr

resolved function pointer

Definition at line 107 of file icode.hpp.

Referenced by RuntimeFunction(), RuntimeFunction(), RuntimeFunction(), call(), and operator=().

◆ handle

void* mxvm::RuntimeFunction::handle = nullptr

dlopen handle

Definition at line 108 of file icode.hpp.

Referenced by RuntimeFunction(), RuntimeFunction(), RuntimeFunction(), call(), and operator=().

◆ handles

std::unordered_map< std::string, void * > mxvm::RuntimeFunction::handles
static

cached library handles

Definition at line 111 of file icode.hpp.

Referenced by RuntimeFunction(), and mxvm::Program::~Program().

◆ mod_name

std::string mxvm::RuntimeFunction::mod_name

module name

Definition at line 109 of file icode.hpp.

Referenced by RuntimeFunction(), call(), and operator=().


The documentation for this class was generated from the following files: