Simple Virtual Machine
A simple but flexible virtual machine
SVM functions

This module contains API functions to handle SVM functions. More...

Functions

SVM_FUNCTION SVM_Variable svm_function_call (const void *svm, const SVM_Value_PluginEntryPoint name, const SVM_Size argc, SVM_Parameter argv[])
 This function calls a plugin defined function. More...
 
SVM_FUNCTION SVM_String svm_function_get_prototype (const void *svm, const SVM_Value_PluginEntryPoint name)
 This function returns a string representing the prototype of a plugin defined function. More...
 

Detailed Description

This module contains API functions to handle SVM functions.

Functions are a generic mechanism to allow plugin cooperation:

Function Documentation

◆ svm_function_call()

SVM_FUNCTION SVM_Variable svm_function_call ( const void *  svm,
const SVM_Value_PluginEntryPoint  name,
const SVM_Size  argc,
SVM_Parameter  argv[] 
)

This function calls a plugin defined function.

Parameters
[in]svmThe SVM pointer passed as first argument of the callback function.
[in]nameThe plugin function name to call.
[in]argcThe number of parameters.
[in]argvThe function parameters. These parameters can be:
  • values,
  • markers,
  • keywords,
  • structures.
Note
The called function is not a raw plugin callback function. Callable functions are objects defined as FUNCTION in plugins.
The called function will not share the caller SVM first pointer. The current kernel, process or scheduler remain the same in the called function when the call is done within a kernel. But all local variables are not accessible to the function, and the global variables are the ones of the plugin of the called function.
If a call to an instruction callback has to performed from a plugin, a function can be created in the plugin code containing the instruction callback to delegate the call:
SVM_Variable function_<instruction name>(const void *svm, const unsigned long int argc, const SVM_Parameter argv[])
{
return instruction_<instruction name>(svm, argc, argv);
}
SVM_TYPE typedef const void * SVM_Parameter
This type is used by the SVM to pass instruction parameters to the corresponding plugin function.
Definition: svm.h:180
SVM_TYPE typedef const void * SVM_Variable
This type is used to represent any object managed by the SVM.
Definition: svm.h:171
This allows the plugin developper to allow only a subset of instructions to be called from other plugins.
Warning
If the argv size is smaller than argc, it will result in an undefined behavior.

Usage example:

parameters[0] = svm_parameter_value_new(svm,svm_parameter_value_get(svm,argv[0]));
parameters[1] = svm_parameter_marker_new__raw(svm,">");
parameters[2] = svm_parameter_value_new(svm,svm_value_integer_new(svm,42));
// call to FUNCTION remote.compare . ( [ < > = ] INT | 'IN' { INT , INT } ) -> BLN
SVM_Value_Boolean result = svm_function_call(svm,svm_value_pluginentrypoint_new__raw(svm,"remote","compare"),3,parameters);
if(svm_value_boolean_get(svm,result))
{
// ...
}
SVM_TYPE typedef const void * SVM_Value_Boolean
This type is used to represent a boolean the SVM can store in one of its memories.
Definition: svm.h:557
SVM_FUNCTION SVM_Boolean svm_value_boolean_get(const void *svm, const SVM_Value_Boolean boolean)
This function extracts the SVM_Boolean contained in a boolean value.
SVM_FUNCTION SVM_Variable svm_function_call(const void *svm, const SVM_Value_PluginEntryPoint name, const SVM_Size argc, SVM_Parameter argv[])
This function calls a plugin defined function.
SVM_FUNCTION SVM_Value_Integer svm_value_integer_new(const void *svm, const long int integer)
This function creates an integer value the SVM can store in its memories from a raw integer.
SVM_FUNCTION SVM_Parameter svm_parameter_marker_new__raw(const void *svm, const char *marker)
This function creates a parameter from a marker string.
SVM_FUNCTION SVM_Parameter * svm_parameter_array_new(const void *svm, const SVM_Size argc)
This function creates an array of parameters.
SVM_FUNCTION SVM_Value_PluginEntryPoint svm_value_pluginentrypoint_new__raw(const void *svm, const char *plugin_name, const char *entry_name)
This function creates a plugin entry point value the SVM can store in its memories from two C nul-ter...
SVM_FUNCTION SVM_Parameter svm_parameter_value_new(const void *svm, const SVM_Value value)
This function creates a parameter from a value.
SVM_FUNCTION SVM_Value svm_parameter_value_get(const void *svm, const SVM_Parameter parameter)
This function converts a parameter into a value.
Returns
The function result. This result can be:
  • a value,
  • a null value,
  • a structure,
  • a variable,
  • the NULL pointer when no result is returned.
Exceptions
FAILUREinterruption when a parameter is incorrect. (Please refer to the main description page of this API.)
FAILUREinterruption when the function does not exist.
FAILUREinterruption when the parameters function are not compatible with the function definition.
FAILUREinterruption when the return value of the function is not compatible with the function definition.
See also
svm_parameter_array_new

◆ svm_function_get_prototype()

SVM_FUNCTION SVM_String svm_function_get_prototype ( const void *  svm,
const SVM_Value_PluginEntryPoint  name 
)

This function returns a string representing the prototype of a plugin defined function.

Parameters
[in]svmThe SVM pointer passed as first argument of the callback function.
[in]nameThe plugin function name.
Returns
The function prototype as a string.
Exceptions
FAILUREinterruption when a parameter is incorrect. (Please refer to the main description page of this API.)
FAILUREinterruption when the function does not exist.