Simple Virtual Machine A simple but flexible virtual machine

Loading...
Searching...
No Matches
Functions
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.
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.

## Detailed Description

This module contains API functions to handle SVM functions.

Functions are a generic mechanism to allow plugin cooperation:

- A plugin can trigger a call to another plugin callback function,
- Type checking is done like for instruction calls,
- The caller plugin callback function can use the name and parameters from its own parameters to allow genericity.

## 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] | svm | The SVM pointer passed as first argument of the callback function.
  [in] | name | The plugin function name to call.
  [in] | argc | The number of parameters.
  [in] | argv | The 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_Parameter
  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:181
  SVM_Variable
  SVM_TYPE typedef const void * SVM_Variable
  This type is used to represent any object managed by the SVM.
  Definition svm.h:172
  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:

SVM_Parameter *parameters = svm_parameter_array_new(svm,3);
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_Value_Boolean
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:558
svm_value_boolean_get
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_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.
svm_value_integer_new
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_parameter_marker_new__raw
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_parameter_array_new
SVM_FUNCTION SVM_Parameter * svm_parameter_array_new(const void *svm, const SVM_Size argc)
This function creates an array of parameters.
svm_value_pluginentrypoint_new__raw
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_parameter_value_new
SVM_FUNCTION SVM_Parameter svm_parameter_value_new(const void *svm, const SVM_Value value)
This function creates a parameter from a value.
svm_parameter_value_get
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

  FAILURE | interruption when a parameter is incorrect. (Please refer to the main description page of this API.)
  FAILURE | interruption when the function does not exist.
  FAILURE | interruption when the parameters function are not compatible with the function definition.
  FAILURE | interruption 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] | svm | The SVM pointer passed as first argument of the callback function.
  [in] | name | The plugin function name.

Returns
  The function prototype as a string.

Exceptions

  FAILURE | interruption when a parameter is incorrect. (Please refer to the main description page of this API.)
  FAILURE | interruption when the function does not exist.