LispBM
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions | Variables
extensions.h File Reference
#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.

Data Structures

struct  lbm_extension_t
 

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

bool lbm_extensions_init (lbm_extension_t *extension_storage, lbm_uint extension_storage_size)
 
void lbm_extensions_set_next (lbm_uint i)
 
lbm_uint lbm_get_max_extensions (void)
 
lbm_uint lbm_get_num_extensions (void)
 
bool lbm_lookup_extension_id (char *sym_str, lbm_uint *ix)
 
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_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 lbm_extensions_default (lbm_value *args, lbm_uint argn)
 
lbm_value make_list (int num,...)
 
bool strmatch (const char *str1, const char *str2)
 
static lbm_value mk_lam (lbm_value args, lbm_value body)
 
static lbm_value mk_call_cc (lbm_value body)
 
static lbm_value mk_let (lbm_value bindings, lbm_value body)
 
static lbm_value mk_if (lbm_value cond, lbm_value tb, lbm_value fb)
 
static lbm_value mk_inc (lbm_value v)
 
static lbm_value mk_lt (lbm_value a, lbm_value b)
 
static lbm_value mk_eq (lbm_value a, lbm_value b)
 
static lbm_value mk_car (lbm_value a)
 
static lbm_value mk_cdr (lbm_value a)
 

Variables

lbm_extension_textension_table
 

Macro Definition Documentation

◆ LBM_CHECK_ARGN

#define LBM_CHECK_ARGN (   n)    if (!lbm_check_argn(argn, n)) {return ENC_SYM_EERROR;}

◆ LBM_CHECK_ARGN_NUMBER

#define LBM_CHECK_ARGN_NUMBER (   n)    if (!lbm_check_argn_number(args, argn, n)) {return ENC_SYM_EERROR;}

◆ LBM_CHECK_NUMBER_ALL

#define LBM_CHECK_NUMBER_ALL ( )    if (!lbm_check_number_all(args, argn)) {return ENC_SYM_EERROR;}

◆ LBM_EXTENSION

#define LBM_EXTENSION (   name,
  argv,
  argn 
)     __attribute__((aligned(LBM_STORABLE_ADDRESS_ALIGNMENT))) lbm_value name(lbm_value *(argv), lbm_uint (argn))

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_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_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.

◆ 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,
  ... 
)
extern

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.

◆ mk_call_cc()

static lbm_value mk_call_cc ( lbm_value  body)
inlinestatic

Create a call-cc given a body expression. The body should be a lambda expression taking a continuation.

Warning
Thread Requirement: This function MUST be called from the LBM evaluator thread only.
Parameters
bodyCall-cc body expression.
Returns
Call-cc expression or MERROR.

◆ mk_car()

static lbm_value mk_car ( lbm_value  a)
inlinestatic

Create an expression that takes the car of an expression

Warning
Thread Requirement: This function MUST be called from the LBM evaluator thread only.
Parameters
aValue expression.
Returns
Expression that takes the car or the value.

◆ mk_cdr()

static lbm_value mk_cdr ( lbm_value  a)
inlinestatic

Create an expression that takes the cdr of an expression

Warning
Thread Requirement: This function MUST be called from the LBM evaluator thread only.
Parameters
aValue expression.
Returns
Expression that takes the cdr or the value.

◆ mk_eq()

static lbm_value mk_eq ( lbm_value  a,
lbm_value  b 
)
inlinestatic

Create an expression that compares equality

Warning
Thread Requirement: This function MUST be called from the LBM evaluator thread only.
Parameters
aValue expression.
bValue expression.
Returns
equality comparison expression or MERROR.

◆ mk_if()

static lbm_value mk_if ( lbm_value  cond,
lbm_value  tb,
lbm_value  fb 
)
inlinestatic

Create an if expression given condition, then-branch and else-branch

Warning
Thread Requirement: This function MUST be called from the LBM evaluator thread only.
Parameters
condBoolean condition expression.
tbThen-branch expression.
fbElse-branch expression.
Returns
If expression or MERROR.

◆ mk_inc()

static lbm_value mk_inc ( lbm_value  v)
inlinestatic

Create an expression that adds one to a value.

Warning
Thread Requirement: This function MUST be called from the LBM evaluator thread only.
Parameters
vValue to add one to.
Returns
increment expression or MERROR.

◆ mk_lam()

static lbm_value mk_lam ( lbm_value  args,
lbm_value  body 
)
inlinestatic

Create a lambda given argument list and body

Warning
Thread Requirement: This function MUST be called from the LBM evaluator thread only.
Parameters
argsArgument list.
bodyFunction body.
Returns
Lambda or MERROR.

◆ mk_let()

static lbm_value mk_let ( lbm_value  bindings,
lbm_value  body 
)
inlinestatic

Create a let expression given bindings list and body

Warning
Thread Requirement: This function MUST be called from the LBM evaluator thread only.
Parameters
bindingsList of bindings.
bodyExpression to evaluate in the extended environment.
Returns
Let expression or MERROR.

◆ mk_lt()

static lbm_value mk_lt ( lbm_value  a,
lbm_value  b 
)
inlinestatic

Create an expression that compares less-than

Warning
Thread Requirement: This function MUST be called from the LBM evaluator thread only.
Parameters
aValue expression.
bValue expression.
Returns
less-than comparison expression or MERROR.

◆ strmatch()

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

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

◆ extension_table

lbm_extension_t* extension_table
extern