LispBM
Loading...
Searching...
No Matches
Functions | Variables
extensions.c File Reference
#include <lbm_memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <eval_cps.h>
#include "extensions.h"
#include "lbm_utils.h"
Include dependency graph for extensions.c:

Functions

void lbm_extensions_set_next (lbm_uint i)
 
lbm_value lbm_extensions_default (lbm_value *args, lbm_uint argn)
 
bool lbm_extensions_init (lbm_extension_t *extension_storage, lbm_uint 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_lookup_extension_id (char *sym_str, lbm_uint *ix)
 
bool lbm_add_extension (char *sym_str, extension_fptr ext)
 
static bool lbm_is_number_all (lbm_value *args, lbm_uint argn)
 
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)
 
lbm_value make_list (int num,...)
 
bool strmatch (const char *str1, const char *str2)
 

Variables

static lbm_uint ext_max = 0
 
static lbm_uint next_extension_ix = 0
 
lbm_extension_textension_table = NULL
 

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_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_default()

lbm_value lbm_extensions_default ( lbm_value args,
lbm_uint  argn 
)

◆ lbm_extensions_init()

bool lbm_extensions_init ( lbm_extension_t extension_storage,
lbm_uint  extension_storage_size 
)

Initialize the extensions subsystem. Extension storage is allocated on lbm_memory.

Parameters
extension_storage_sizeSize of function pointer array.
Returns
true on success and false for failure

◆ lbm_extensions_set_next()

void lbm_extensions_set_next ( lbm_uint  i)

Set the next index to be given out to the next added extension.

Parameters
iNext index.

◆ 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_number_all()

static bool lbm_is_number_all ( lbm_value args,
lbm_uint  argn 
)
static

◆ lbm_lookup_extension_id()

bool lbm_lookup_extension_id ( char *  sym_str,
lbm_uint ix 
)

Lookup an extensions index.

Parameters
sym_strExtension name to look up.
ixPointer used to store result.
Returns
true on success, false otherwise.

◆ make_list()

lbm_value make_list ( int  num,
  ... 
)

Create a list.

Warning
Thread Requirement: This function MUST be called from the LBM evaluator thread only.
Parameters
numThe number of elements to allocate space for.
...The elements to initialize the list with.
Returns
the list or MERROR.

◆ strmatch()

bool strmatch ( const char *  str1,
const char *  str2 
)

Compare strings for equality Compares two strings up to the length of the first of string arguments.

Parameters
str1First string to match against a prefix of second.
str2Second string.
Returns
true is str1 matches the prefix of str2.

Variable Documentation

◆ ext_max

lbm_uint ext_max = 0
static

◆ extension_table

lbm_extension_t* extension_table = NULL

◆ next_extension_ix

lbm_uint next_extension_ix = 0
static