Simple Virtual Machine A simple but flexible virtual machine

Loading...
Searching...
No Matches
Modules | Functions
SVM variables

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

## Modules
| SVM variables scope
| This module contains API functions to handle the scope of variables.
| SVM variables detection
| This module contains API functions to detect variable types.

## Functions
SVM_FUNCTION SVM_Variable * | svm_variable_array_new (const void *svm, SVM_Size size)
| This function creates an array of variables.
SVM_FUNCTION void | svm_variable_delete (const void *svm, const SVM_Variable variable)
| This function alters the scope of the given variable.

## Detailed Description

This module contains API functions to handle variables.

A variable in this API refers to a generic pointer used as a key associated to an object internally managed by the virtual machine.

There are two ways to obtain a variable:

- Instruction and function parameters are variables,
- API function return values are variables when the indicated type corresponds to a variable type.

The scope of a variable can be:

- Limited to the plugin callback call (local variable): The variable will not be available in a subsequent plugin callback call,
- Extended to all plugin callback calls (global variable): The variable will be available in a subsequent plugin callback call within the same plugin.

The scope of the object associated to a variable can be different when:

- Several variables refer to the same object,
- The object is used by the virtual machine outside the scope of variables.

Variables are equally comparable: Two variables being equal refer to the same associated object:

static SVM_Process process;
SVM_Value instruction_one(const void *svm, SVM_Size argc, SVM_Parameter argv[])
{
process = svm_process_get_current(svm);
return NULL;
}
SVM_Value instruction_two(const void *svm, SVM_Size argc, SVM_Parameter argv[])
{
if(svm_process_get_current(svm) == process)
{
// we get here only in the last process which invoked instruction one!
}
return NULL;
}
SVM_Size
SVM_TYPE typedef unsigned long int SVM_Size
This type is used to represent an object size.
Definition svm.h:258
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_Process
SVM_TYPE typedef const void * SVM_Process
This type is used to represent an execution thread in the SVM.
Definition svm.h:305
SVM_Value
SVM_TYPE typedef const void * SVM_Value
This type is used to represent any value the SVM can store in one of its memories.
Definition svm.h:531
svm_process_get_current
SVM_FUNCTION SVM_Process svm_process_get_current(const void *svm)
This function retrieves the current process.

See also
  SVM types

## Function Documentation

## ◆ svm_variable_array_new()

SVM_FUNCTION SVM_Variable * svm_variable_array_new | ( | const void * | svm,
|  | SVM_Size | size
| ) |  |

This function creates an array of variables.

Parameters

  [in] | svm | The SVM pointer passed as first argument of the callback function.
  [in] | size | The size of the array.

Returns
  A pointer to a C array of SVM_Variable. Every cell of the array has to be initialised by a value before being passed to an API function.

Note
  The returned array is a valid SVM variable: its scope can be changed if needed, and the pointer shall not be freed explicitely.

Exceptions

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

## ◆ svm_variable_delete()

SVM_FUNCTION void svm_variable_delete | ( | const void * | svm,
|  | const SVM_Variable | variable
| ) |  |

This function alters the scope of the given variable.

Parameters

  [in] | svm | The SVM pointer passed as first argument of the callback function.
  [in] | variable | The variable to free.

This variable becomes immediately invisible.

The object associated to this variable may be deleted immediately.

Exceptions

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