LispBM
Macros | Typedefs | Functions
extensions.h File Reference
#include "symrepr.h"
#include "heap.h"
#include "lbm_types.h"
#include "lbm_constants.h"
Include dependency graph for extensions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LBM_EXTENSION(name, argv, argn)    __attribute__((aligned(LBM_STORABLE_ADDRESS_ALIGNMENT))) lbm_value name(lbm_value *(argv), lbm_uint (argn))
 
#define LBM_CHECK_NUMBER_ALL()   if (!lbm_check_number_all(args, argn)) {return ENC_SYM_EERROR;}
 
#define LBM_CHECK_ARGN(n)   if (!lbm_check_argn(argn, n)) {return ENC_SYM_EERROR;}
 
#define LBM_CHECK_ARGN_NUMBER(n)   if (!lbm_check_argn_number(args, argn, n)) {return ENC_SYM_EERROR;}
 

Typedefs

typedef lbm_value(* extension_fptr) (lbm_value *, lbm_uint)
 

Functions

int lbm_extensions_init (extension_fptr *extension_storage, int extension_storage_size)
 
lbm_uint lbm_get_max_extensions (void)
 
lbm_uint lbm_get_num_extensions (void)
 
extension_fptr lbm_get_extension (lbm_uint sym)
 
bool lbm_clr_extension (lbm_uint sym_id)
 
bool lbm_add_extension (char *sym_str, extension_fptr ext)
 
static bool lbm_is_extension (lbm_value exp)
 
bool lbm_check_true_false (lbm_value v)
 
bool lbm_check_number_all (lbm_value *args, lbm_uint argn)
 
bool lbm_check_argn (lbm_uint argn, lbm_uint n)
 
bool lbm_check_argn_number (lbm_value *args, lbm_uint argn, lbm_uint n)
 

Typedef Documentation

◆ extension_fptr

typedef lbm_value(* extension_fptr) (lbm_value *, lbm_uint)

Type representing an extension function.

Parameters
Pointerto array of lbm_values.
Numberof arguments.
Returns
Result value.

Function Documentation

◆ lbm_add_extension()

bool lbm_add_extension ( char *  sym_str,
extension_fptr  ext 
)

Adds a symbol-extension mapping.

Parameters
sym_strString representation of symbol to use as key.
extThe extension function pointer.
Returns
true on success and false on failure.

◆ lbm_check_argn()

bool lbm_check_argn ( lbm_uint  argn,
lbm_uint  n 
)

Check if the number of arguments is n. Sets error-reason if result is false.

Parameters
argnnumber of arguments.
nnumber of expected arguments.
Returns
true if the number of arguments is correct. false otherwise

◆ lbm_check_argn_number()

bool lbm_check_argn_number ( lbm_value args,
lbm_uint  argn,
lbm_uint  n 
)

Check if all arguments are numbers and that there is n of them. Sets error-reason if result is false.

Parameters
argsThe argument array.
argnThe number of arguments.
nThe expected number of arguments.
Returns
true or false.

◆ lbm_check_number_all()

bool lbm_check_number_all ( lbm_value args,
lbm_uint  argn 
)

Check if all arguments are numbers. Sets error-reason if result is false.

Parameters
argsThe argument array.
argnThe number of arguments.
Returns
true if all arguments are numbers, false otherwise.

◆ lbm_check_true_false()

bool lbm_check_true_false ( lbm_value  v)

Check if a value is the symbol t or the symbol nil

Parameters
vThe value.
Returns
true if the value is t or nil otherwise false.

◆ lbm_clr_extension()

bool lbm_clr_extension ( lbm_uint  sym_id)

Reset an extension back to the default value. Trying to apply the extension after clearing it will result in an eval error.

Parameters
sym_idSymbol id of the extension to clear.
Returns
true if successfully cleared an extension otherwise false.

◆ lbm_extensions_init()

int lbm_extensions_init ( extension_fptr extension_storage,
int  extension_storage_size 
)

Initialize the extensions subsystem.

Parameters
extension_storagePointer to array of extension_fptr.
extension_storage_sizeSize of function pointer array.
Returns
1 on success and 0 for failure

◆ lbm_get_extension()

extension_fptr lbm_get_extension ( lbm_uint  sym)

Look up an extension associated with a key symbol.

Parameters
symSymbol bound to the extension to look for.
Returns
extension_fptr on success or NULL on failure.

◆ lbm_get_max_extensions()

lbm_uint lbm_get_max_extensions ( void  )

The number of extensions that can be allocated.

Returns
The maximum number of extensions that can be added.

◆ lbm_get_num_extensions()

lbm_uint lbm_get_num_extensions ( void  )

Get the number of allocated extensions

Returns
The number of extensions that have been added.

◆ lbm_is_extension()

static bool lbm_is_extension ( lbm_value  exp)
inlinestatic

Check if an lbm_value is a symbol that is bound to an extension.

Parameters
expKey to look up.
Returns
true if the lbm_value respresents an extension otherwise false.