LispBM
Functions | Variables
heap.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <inttypes.h>
#include <lbm_memory.h>
#include <lbm_custom_type.h>
#include <lbm_defrag_mem.h>
#include "heap.h"
#include "symrepr.h"
#include "stack.h"
#include "lbm_channel.h"
#include "platform_mutex.h"
#include "eval_cps.h"
Include dependency graph for heap.c:

Functions

static lbm_value lbm_set_gc_mark (lbm_value x)
 
static lbm_value lbm_clr_gc_mark (lbm_value x)
 
static bool lbm_get_gc_mark (lbm_value x)
 
static bool lbm_get_gc_flag (lbm_value x)
 
static lbm_value lbm_set_gc_flag (lbm_value x)
 
static lbm_value lbm_clr_gc_flag (lbm_value x)
 
void lbm_gc_lock (void)
 
void lbm_gc_unlock (void)
 
lbm_value lbm_enc_i32 (int32_t x)
 
lbm_value lbm_enc_u32 (uint32_t x)
 
lbm_value lbm_enc_float (float x)
 
static lbm_value enc_64_on_32 (uint8_t *source, lbm_uint type_qual, lbm_uint type)
 
lbm_value lbm_enc_i64 (int64_t x)
 
lbm_value lbm_enc_u64 (uint64_t x)
 
lbm_value lbm_enc_double (double x)
 
float lbm_dec_float (lbm_value x)
 
double lbm_dec_double (lbm_value x)
 
uint64_t lbm_dec_u64 (lbm_value x)
 
int64_t lbm_dec_i64 (lbm_value x)
 
char * lbm_dec_str (lbm_value val)
 
lbm_char_channel_tlbm_dec_channel (lbm_value val)
 
lbm_uint lbm_dec_custom (lbm_value val)
 
uint8_t lbm_dec_as_char (lbm_value a)
 
uint32_t lbm_dec_as_u32 (lbm_value a)
 
int32_t lbm_dec_as_i32 (lbm_value a)
 
int64_t lbm_dec_as_i64 (lbm_value a)
 
uint64_t lbm_dec_as_u64 (lbm_value a)
 
lbm_uint lbm_dec_as_uint (lbm_value a)
 
lbm_int lbm_dec_as_int (lbm_value a)
 
float lbm_dec_as_float (lbm_value a)
 
double lbm_dec_as_double (lbm_value a)
 
static int generate_freelist (size_t num_cells)
 
void lbm_nil_freelist (void)
 
static void heap_init_state (lbm_cons_t *addr, lbm_uint num_cells, lbm_uint *gc_stack_storage, lbm_uint gc_stack_size)
 
void lbm_heap_new_freelist_length (void)
 
int lbm_heap_init (lbm_cons_t *addr, lbm_uint num_cells, lbm_uint gc_stack_size)
 
lbm_value lbm_heap_allocate_cell (lbm_type ptr_type, lbm_value car, lbm_value cdr)
 
lbm_value lbm_heap_allocate_list (lbm_uint n)
 
lbm_value lbm_heap_allocate_list_init_va (unsigned int n, va_list valist)
 
lbm_value lbm_heap_allocate_list_init (unsigned int n,...)
 
lbm_uint lbm_heap_num_allocated (void)
 
lbm_uint lbm_heap_size (void)
 
lbm_uint lbm_heap_size_bytes (void)
 
void lbm_get_heap_state (lbm_heap_state_t *res)
 
lbm_uint lbm_get_gc_stack_max (void)
 
lbm_uint lbm_get_gc_stack_size (void)
 
void lbm_gc_mark_phase (lbm_value root)
 
void lbm_gc_mark_env (lbm_value env)
 
void lbm_gc_mark_aux (lbm_uint *aux_data, lbm_uint aux_size)
 
void lbm_gc_mark_roots (lbm_uint *roots, lbm_uint num_roots)
 
int lbm_gc_sweep_phase (void)
 
void lbm_gc_state_inc (void)
 
lbm_value lbm_cons (lbm_value car, lbm_value cdr)
 
lbm_value lbm_car (lbm_value c)
 
lbm_value lbm_caar (lbm_value c)
 
lbm_value lbm_cadr (lbm_value c)
 
lbm_value lbm_cdr (lbm_value c)
 
lbm_value lbm_cddr (lbm_value c)
 
int lbm_set_car (lbm_value c, lbm_value v)
 
int lbm_set_cdr (lbm_value c, lbm_value v)
 
int lbm_set_car_and_cdr (lbm_value c, lbm_value car_val, lbm_value cdr_val)
 
lbm_uint lbm_list_length (lbm_value c)
 
unsigned int lbm_list_length_pred (lbm_value c, bool *pres, bool(*pred)(lbm_value))
 
lbm_value lbm_list_reverse (lbm_value list)
 
lbm_value lbm_list_destructive_reverse (lbm_value list)
 
lbm_value lbm_list_copy (int *m, lbm_value list)
 
lbm_value lbm_list_append (lbm_value list1, lbm_value list2)
 
lbm_value lbm_list_drop (unsigned int n, lbm_value ls)
 
lbm_value lbm_index_list (lbm_value l, int32_t n)
 
int lbm_heap_allocate_array_base (lbm_value *res, bool byte_array, lbm_uint size)
 
int lbm_heap_allocate_array (lbm_value *res, lbm_uint size)
 
int lbm_heap_allocate_lisp_array (lbm_value *res, lbm_uint size)
 
int lbm_lift_array (lbm_value *value, char *data, lbm_uint num_elt)
 
lbm_int lbm_heap_array_get_size (lbm_value arr)
 
const uint8_t * lbm_heap_array_get_data_ro (lbm_value arr)
 
uint8_t * lbm_heap_array_get_data_rw (lbm_value arr)
 
int lbm_heap_explicit_free_array (lbm_value arr)
 
lbm_uint lbm_size_of (lbm_type t)
 
static bool dummy_flash_write (lbm_uint ix, lbm_uint val)
 
int lbm_const_heap_init (const_heap_write_fun w_fun, lbm_const_heap_t *heap, lbm_uint *addr, lbm_uint num_words)
 
lbm_flash_status lbm_allocate_const_cell (lbm_value *res)
 
lbm_flash_status lbm_allocate_const_raw (lbm_uint nwords, lbm_uint *res)
 
lbm_flash_status lbm_write_const_raw (lbm_uint *data, lbm_uint n, lbm_uint *res)
 
lbm_flash_status lbm_const_write (lbm_uint *tgt, lbm_uint val)
 
lbm_flash_status write_const_cdr (lbm_value cell, lbm_value val)
 
lbm_flash_status write_const_car (lbm_value cell, lbm_value val)
 
lbm_uint lbm_flash_memory_usage (void)
 

Variables

lbm_heap_state_t lbm_heap_state
 
lbm_const_heap_tlbm_const_heap_state
 
lbm_cons_tlbm_heaps [2] = {NULL, NULL}
 
static mutex_t lbm_const_heap_mutex
 
static bool lbm_const_heap_mutex_initialized = false
 
static mutex_t lbm_mark_mutex
 
static bool lbm_mark_mutex_initialized = false
 
eval_context_tctx_running
 
static const_heap_write_fun const_heap_write = dummy_flash_write
 

Function Documentation

◆ dummy_flash_write()

static bool dummy_flash_write ( lbm_uint  ix,
lbm_uint  val 
)
static

◆ enc_64_on_32()

static lbm_value enc_64_on_32 ( uint8_t *  source,
lbm_uint  type_qual,
lbm_uint  type 
)
static

◆ generate_freelist()

static int generate_freelist ( size_t  num_cells)
static

◆ heap_init_state()

static void heap_init_state ( lbm_cons_t addr,
lbm_uint  num_cells,
lbm_uint gc_stack_storage,
lbm_uint  gc_stack_size 
)
static

◆ lbm_allocate_const_cell()

lbm_flash_status lbm_allocate_const_cell ( lbm_value res)

◆ lbm_allocate_const_raw()

lbm_flash_status lbm_allocate_const_raw ( lbm_uint  nwords,
lbm_uint res 
)

◆ lbm_caar()

lbm_value lbm_caar ( lbm_value  c)

Accesses the car field the car field of an lbm_cons_t.

Parameters
consValue
Returns
The car of car field or nil.

◆ lbm_cadr()

lbm_value lbm_cadr ( lbm_value  c)

Accesses the car of the cdr of an cons cell

Parameters
cValue
Returns
the cdr field or type error.

◆ lbm_car()

lbm_value lbm_car ( lbm_value  cons)

Accesses the car field of an lbm_cons_t.

Parameters
consValue
Returns
The car field of the lbm_cons_t if cons is a reference to a heap cell. If cons is nil, the return value is nil. If the value is not cons or nil, the return value is enc_sym(SYM_TERROR) for type error.

◆ lbm_cddr()

lbm_value lbm_cddr ( lbm_value  c)

Accesses the cdr of an cdr field of an lbm_cons_t.

Parameters
consValue
Returns
The cdr of the cdr field of the lbm_cons_t if cons is a reference to a heap cell. If cons is nil, the return value is nil. If the value if not cons or nil, the return value is enc_sym(SYM_TERROR) for type error.

◆ lbm_cdr()

lbm_value lbm_cdr ( lbm_value  cons)

Accesses the cdr field of an lbm_cons_t.

Parameters
consValue
Returns
The cdr field of the lbm_cons_t if cons is a reference to a heap cell. If cons is nil, the return value is nil. If the value if not cons or nil, the return value is enc_sym(SYM_TERROR) for type error.

◆ lbm_clr_gc_flag()

static lbm_value lbm_clr_gc_flag ( lbm_value  x)
inlinestatic

◆ lbm_clr_gc_mark()

static lbm_value lbm_clr_gc_mark ( lbm_value  x)
inlinestatic

◆ lbm_cons()

lbm_value lbm_cons ( lbm_value  car,
lbm_value  cdr 
)

Allocates an lbm_cons_t cell from the heap and populates it.

Parameters
carThe value to put in the car field of the allocated lbm_cons_t.
cdrThe value to put in the cdr field of the allocated lbm_cons_t.
Returns
A value referencing the lbm_cons_t or enc_sym(SYM_MERROR) if heap is full.

◆ lbm_const_heap_init()

int lbm_const_heap_init ( const_heap_write_fun  w_fun,
lbm_const_heap_t heap,
lbm_uint addr,
lbm_uint  num_words 
)

◆ lbm_const_write()

lbm_flash_status lbm_const_write ( lbm_uint tgt,
lbm_uint  val 
)

◆ lbm_dec_as_char()

uint8_t lbm_dec_as_char ( lbm_value  a)

Decode a numerical value as if it is char

Parameters
valValue to decode
Returns
The value encoded in val casted to a char. Returns 0 if val does not encode a number.

◆ lbm_dec_as_double()

double lbm_dec_as_double ( lbm_value  val)

Decode a numerical value as a float.

Parameters
valValue to decode.
Returns
The value encoded in val casted to a float. Returns 0 if val does not encode a number.

◆ lbm_dec_as_float()

float lbm_dec_as_float ( lbm_value  val)

Decode a numerical value as a float.

Parameters
valValue to decode.
Returns
The value encoded in val casted to a float. Returns 0 if val does not encode a number.

◆ lbm_dec_as_i32()

int32_t lbm_dec_as_i32 ( lbm_value  val)

Decode a numerical value as a signed integer.

Parameters
valValue to decode
Returns
The value encoded in val casted to a signed int. Returns 0 if val does not encode a number.

◆ lbm_dec_as_i64()

int64_t lbm_dec_as_i64 ( lbm_value  val)

Decode a numerical value as a 64bit signed integer.

Parameters
valValue to decode
Returns
The value encoded in val casted to a signed int. Returns 0 if val does not encode a number.

◆ lbm_dec_as_int()

lbm_int lbm_dec_as_int ( lbm_value  val)

Decode a numerical value into the architecture defined signed integer type.

Parameters
valValue to decode
Returns
The value encoded in val casted to a signed int. Returns 0 if val does not encode a number.

◆ lbm_dec_as_u32()

uint32_t lbm_dec_as_u32 ( lbm_value  val)

Decode a numerical value as if it is unsigned

Parameters
valValue to decode
Returns
The value encoded in val casted to an unsigned int. Returns 0 if val does not encode a number.

◆ lbm_dec_as_u64()

uint64_t lbm_dec_as_u64 ( lbm_value  val)

Decode a numerical value as if it is a 64bit unsigned

Parameters
valValue to decode
Returns
The value encoded in val casted to an unsigned int. Returns 0 if val does not encode a number.

◆ lbm_dec_as_uint()

lbm_uint lbm_dec_as_uint ( lbm_value  val)

Decode a numerical value into the architecture defined unsigned integer type.

Parameters
valValue to decode
Returns
The value encoded in val casted to an unsigned int. Returns 0 if val does not encode a number.

◆ lbm_dec_channel()

lbm_char_channel_t* lbm_dec_channel ( lbm_value  val)

Decode an lbm_value representing a char channel into an lbm_char_channel_t pointer.

Parameters
valValue
Returns
A pointer to an lbm_char_channel_t or NULL if the value does not encode a channel.

◆ lbm_dec_custom()

lbm_uint lbm_dec_custom ( lbm_value  val)

Decode an lbm_value representing a custom type into a lbm_uint value.

Parameters
valValue.
Returns
The custom type payload.

◆ lbm_dec_double()

double lbm_dec_double ( lbm_value  x)

Decode an lbm_value representing a double.

Parameters
xValue to decode.
Returns
decoded float.

◆ lbm_dec_float()

float lbm_dec_float ( lbm_value  x)

Decode an lbm_value representing a float.

Parameters
xValue to decode.
Returns
decoded float.

◆ lbm_dec_i64()

int64_t lbm_dec_i64 ( lbm_value  x)

Decode an lbm_value representing a 64 bit integer.

Parameters
xValue to decode.
Returns
decoded int64_t.

◆ lbm_dec_str()

char* lbm_dec_str ( lbm_value  val)

Decode an lbm_value representing a string into a C string

Parameters
valValue
Returns
allocated list or error symbol

◆ lbm_dec_u64()

uint64_t lbm_dec_u64 ( lbm_value  x)

Decode an lbm_value representing a 64 bit unsigned integer.

Parameters
xValue to decode.
Returns
decoded uint64_t.

◆ lbm_enc_double()

lbm_value lbm_enc_double ( double  x)

Encode a double into an lbm_value.

Parameters
xdouble to encode.
Returns
result encoded value.

◆ lbm_enc_float()

lbm_value lbm_enc_float ( float  x)

Encode a float into an lbm_value.

Parameters
xfloat value to encode.
Returns
result encoded value.

◆ lbm_enc_i32()

lbm_value lbm_enc_i32 ( int32_t  x)

Encode 32 bit integer into an lbm_value.

Parameters
xValue to encode.
Returns
result encoded value.

◆ lbm_enc_i64()

lbm_value lbm_enc_i64 ( int64_t  x)

Encode a 64 bit integer into an lbm_value.

Parameters
x64 bit integer to encode.
Returns
result encoded value.

◆ lbm_enc_u32()

lbm_value lbm_enc_u32 ( uint32_t  x)

Encode 32 bit unsigned integer into an lbm_value.

Parameters
xValue to encode.
Returns
result encoded value.

◆ lbm_enc_u64()

lbm_value lbm_enc_u64 ( uint64_t  x)

Encode a 64 bit unsigned integer into an lbm_value.

Parameters
x64 bit unsigned integer to encode.
Returns
result encoded value.

◆ lbm_flash_memory_usage()

lbm_uint lbm_flash_memory_usage ( void  )

◆ lbm_gc_lock()

void lbm_gc_lock ( void  )

Lock GC mutex Locks a mutex during GC marking when using the pointer reversal algorithm. Does nothing when using stack based GC mark.

◆ lbm_gc_mark_aux()

void lbm_gc_mark_aux ( lbm_uint data,
lbm_uint  n 
)

Performs lbm_gc_mark_phase on all the values of an array. This function is similar to lbm_gc_mark_roots but performs extra checks to not traverse into non-standard values. TODO: Check if this function is really needed.

Parameters
dataArray of roots to traverse from.
nNumber of elements in roots-array.

◆ lbm_gc_mark_env()

void lbm_gc_mark_env ( lbm_value  )

Mark all heap cells reachable from an environment.

Parameters
environment.

◆ lbm_gc_mark_phase()

void lbm_gc_mark_phase ( lbm_value  root)

Mark heap cells reachable from the lbm_value v.

Parameters
root

◆ lbm_gc_mark_roots()

void lbm_gc_mark_roots ( lbm_uint roots,
lbm_uint  num_roots 
)

Performs lbm_gc_mark_phase on all the values in the roots array.

Parameters
rootspointer to array of roots.
num_rootssize of array of roots.

◆ lbm_gc_state_inc()

void lbm_gc_state_inc ( void  )

Increment the counter that is counting the number of times GC ran

◆ lbm_gc_sweep_phase()

int lbm_gc_sweep_phase ( void  )

Sweep up all non marked heap cells and place them on the free list.

Returns
1

◆ lbm_gc_unlock()

void lbm_gc_unlock ( void  )

◆ lbm_get_gc_flag()

static bool lbm_get_gc_flag ( lbm_value  x)
inlinestatic

◆ lbm_get_gc_mark()

static bool lbm_get_gc_mark ( lbm_value  x)
inlinestatic

◆ lbm_get_gc_stack_max()

lbm_uint lbm_get_gc_stack_max ( void  )

Get the maximum stack level of the GC stack

Returns
maximum value the gc stack sp reached so far.

◆ lbm_get_gc_stack_size()

lbm_uint lbm_get_gc_stack_size ( void  )

Get the size of the GC stack.

Returns
the size of the gc stack.

◆ lbm_get_heap_state()

void lbm_get_heap_state ( lbm_heap_state_t )

Get a copy of the heap statistics structure.

Parameters
Apointer to an lbm_heap_state_t to populate with the current statistics.

◆ lbm_heap_allocate_array()

int lbm_heap_allocate_array ( lbm_value res,
lbm_uint  size 
)

Allocate an bytearray in symbols and arrays memory (lispbm_memory.h) and create a heap cell that refers to this bytearray.

Parameters
resThe resulting lbm_value is returned through this argument.
sizeArray size in number of 32 bit words.
Returns
1 for success of 0 for failure.

◆ lbm_heap_allocate_array_base()

int lbm_heap_allocate_array_base ( lbm_value res,
bool  byte_array,
lbm_uint  size 
)

◆ lbm_heap_allocate_cell()

lbm_value lbm_heap_allocate_cell ( lbm_type  ptr_type,
lbm_value  car,
lbm_value  cdr 
)

Allocate an lbm_cons_t cell from the heap.

Parameters
typeA type that can be encoded onto the cell (most often LBM_PTR_TYPE_CONS).
carValue to write into car position of allocated cell.
cdrValue to write into cdr position of allocated cell.
Returns
a heap cell on success and Memory_error on failure.

◆ lbm_heap_allocate_lisp_array()

int lbm_heap_allocate_lisp_array ( lbm_value res,
lbm_uint  size 
)

Allocate an array in symbols and arrays memory (lispbm_memory.h) and create a heap cell that refers to this array.

Parameters
resThe resulting lbm_value is returned through this argument.
sizeArray size in number of 32 bit words.
Returns
1 for success of 0 for failure.

◆ lbm_heap_allocate_list()

lbm_value lbm_heap_allocate_list ( lbm_uint  n)

Allocate a list of n heap-cells.

Parameters
nThe number of heap-cells to allocate.
Returns
A list of heap-cells of Memory error if unable to allocate.

◆ lbm_heap_allocate_list_init()

lbm_value lbm_heap_allocate_list_init ( unsigned int  n,
  ... 
)

Allocate a list of n heap-cells and initialize the values.

Parameters
nThe length of list to allocate.
...The values to initialize the list with.
Returns
allocated list or error symbol.

◆ lbm_heap_allocate_list_init_va()

lbm_value lbm_heap_allocate_list_init_va ( unsigned int  n,
va_list  valist 
)

Allocate a list of n heap-cells and initialize the values. \pram ls The result list is passed through this ptr.

Parameters
nThe length of list to allocate.
valistThe values in a va_list to initialize the list with.
Returns
True of False depending on success of allocation.

◆ lbm_heap_array_get_data_ro()

const uint8_t* lbm_heap_array_get_data_ro ( lbm_value  arr)

Get a pointer to the data of an array for read only purposes.

Parameters
arrlbm_value array to get pointer from.
Returns
NULL or valid pointer.

◆ lbm_heap_array_get_data_rw()

uint8_t* lbm_heap_array_get_data_rw ( lbm_value  arr)

Get a pointer to the data of an array for read/write purposes.

Parameters
arrlbm_value array to get pointer from.
Returns
NULL or valid pointer.

◆ lbm_heap_array_get_size()

lbm_int lbm_heap_array_get_size ( lbm_value  arr)

Get the size of an array value.

Parameters
arrlbm_value array to get size of.
Returns
-1 for failure or length of array.

◆ lbm_heap_explicit_free_array()

int lbm_heap_explicit_free_array ( lbm_value  arr)

Explicitly free an array. This function needs to be used with care and knowledge.

Parameters
arrArray value.

◆ lbm_heap_init()

int lbm_heap_init ( lbm_cons_t addr,
lbm_uint  num_cells,
lbm_uint  gc_stack_size 
)

Initialize heap storage.

Parameters
addrPointer to an array of lbm_cons_t elements. This array must at least be aligned 4.
num_cellsNumber of lbm_cons_t elements in the array.
gc_stack_sizeSize of the gc_stack in number of words.
Returns
1 on success or 0 for failure.

◆ lbm_heap_new_freelist_length()

void lbm_heap_new_freelist_length ( void  )

Add a new free_list length to the heap_stats. Calculates a new freelist length and updates the GC statistics.

◆ lbm_heap_num_allocated()

lbm_uint lbm_heap_num_allocated ( void  )

Check how many lbm_cons_t cells are allocated.

Returns
Number of lbm_cons_t cells that are currently allocated.

◆ lbm_heap_size()

lbm_uint lbm_heap_size ( void  )

Size of the heap in number of lbm_cons_t cells.

Returns
Size of the heap in number of lbm_cons_t cells.

◆ lbm_heap_size_bytes()

lbm_uint lbm_heap_size_bytes ( void  )

Size of the heap in bytes.

Returns
Size of heap in bytes.

◆ lbm_index_list()

lbm_value lbm_index_list ( lbm_value  l,
int32_t  n 
)

Index into a list.

Parameters
lList to index into.
nPosition to read out of the list.
Returns
Value at position n of l or nil if out of bounds.

◆ lbm_lift_array()

int lbm_lift_array ( lbm_value value,
char *  data,
lbm_uint  num_elt 
)

Convert a C array into an lbm array. If the C array is allocated in LBM MEMORY the lifetime of the array will be managed by GC.

Parameters
reslbm_value result pointer for storage of the result array.
dataC array.
typeThe type tag to assign to the resulting LBM array.
num_eltNumber of elements in the array.
Returns
1 for success and 0 for failure.

◆ lbm_list_append()

lbm_value lbm_list_append ( lbm_value  list1,
lbm_value  list2 
)

A destructive append of two lists

Parameters
list1A list
list2A list
Returns
list1 with list2 appended at the end.

◆ lbm_list_copy()

lbm_value lbm_list_copy ( int *  m,
lbm_value  list 
)

Copy a list

Warning
This is a dangerous function that should be used carefully. Cyclic structures on the heap may lead to the function not terminating.
Parameters
mNumber of elements to copy or -1 for all. If 1, m will be updated with the length of the list
listA list.
Returns
Reversed list or enc_sym(SYM_MERROR) if heap is full.

◆ lbm_list_destructive_reverse()

lbm_value lbm_list_destructive_reverse ( lbm_value  list)

Reverse a proper list destroying the original.

Warning
This is a dangerous function that should be used carefully. Cyclic structures on the heap may lead to the function not terminating.
Parameters
listA list
Returns
The list reversed

◆ lbm_list_drop()

lbm_value lbm_list_drop ( unsigned int  n,
lbm_value  ls 
)

Drop values from the head of a list.

Parameters
nNumber of values to drop.
lsList to drop values from.
Returns
The list with the n first elements removed.

◆ lbm_list_length()

lbm_uint lbm_list_length ( lbm_value  c)

Calculate the length of a proper list

Warning
This is a dangerous function that should be used carefully. Cyclic structures on the heap may lead to the function not terminating.
Parameters
cA list
Returns
The length of the list. Unless the value is a cyclic structure on the heap, this function will terminate.

◆ lbm_list_length_pred()

unsigned int lbm_list_length_pred ( lbm_value  c,
bool *  pres,
bool(*)(lbm_value pred 
)

Calculate the length of a proper list and evaluate a predicate for each element.

Warning
This is a dangerous function that should be used carefully. Cyclic structures on the heap may lead to the function not terminating.
Parameters
cA list
presBoolean result of predicate, false if predicate is false for any of the elements in the list, otherwise true.
predPredicate to evaluate for each element of the list.

◆ lbm_list_reverse()

lbm_value lbm_list_reverse ( lbm_value  list)

Reverse a proper list

Warning
This is a dangerous function that should be used carefully. Cyclic structures on the heap may lead to the function not terminating.
Parameters
listA list
Returns
The list reversed or enc_sym(SYM_MERROR) if heap is full.

◆ lbm_nil_freelist()

void lbm_nil_freelist ( void  )

Set the freelist to NIL. Means that no memory will be available until after a garbage collection.

◆ lbm_set_car()

int lbm_set_car ( lbm_value  c,
lbm_value  v 
)

Update the value stored in the car field of a heap cell.

Parameters
cValue referring to a heap cell.
vValue to replace the car field with.
Returns
1 on success and 0 if the c value does not refer to a heap cell.

◆ lbm_set_car_and_cdr()

int lbm_set_car_and_cdr ( lbm_value  c,
lbm_value  car_val,
lbm_value  cdr_val 
)

Update the value stored in the car and cdr fields of a heap cell.

Parameters
cValue referring to a heap cell.
car_valValue to replace the car field with.
cdr_valValue to replace the cdr field with.
Returns
1 on success and 0 if the c value does not refer to a heap cell.

◆ lbm_set_cdr()

int lbm_set_cdr ( lbm_value  c,
lbm_value  v 
)

Update the value stored in the cdr field of a heap cell.

Parameters
cValue referring to a heap cell.
vValue to replace the cdr field with.
Returns
1 on success and 0 if the c value does not refer to a heap cell.

◆ lbm_set_gc_flag()

static lbm_value lbm_set_gc_flag ( lbm_value  x)
inlinestatic

◆ lbm_set_gc_mark()

static lbm_value lbm_set_gc_mark ( lbm_value  x)
inlinestatic

◆ lbm_size_of()

lbm_uint lbm_size_of ( lbm_type  t)

Query the size in bytes of an lbm_type.

Parameters
tType
Returns
Size in bytes of type or 0 if the type represents a composite.

◆ lbm_write_const_raw()

lbm_flash_status lbm_write_const_raw ( lbm_uint data,
lbm_uint  n,
lbm_uint res 
)

◆ write_const_car()

lbm_flash_status write_const_car ( lbm_value  cell,
lbm_value  val 
)

◆ write_const_cdr()

lbm_flash_status write_const_cdr ( lbm_value  cell,
lbm_value  val 
)

Variable Documentation

◆ const_heap_write

const_heap_write_fun const_heap_write = dummy_flash_write
static

◆ ctx_running

eval_context_t* ctx_running

◆ lbm_const_heap_mutex

mutex_t lbm_const_heap_mutex
static

◆ lbm_const_heap_mutex_initialized

bool lbm_const_heap_mutex_initialized = false
static

◆ lbm_const_heap_state

lbm_const_heap_t* lbm_const_heap_state

◆ lbm_heap_state

lbm_heap_state_t lbm_heap_state

◆ lbm_heaps

lbm_cons_t* lbm_heaps[2] = {NULL, NULL}

◆ lbm_mark_mutex

mutex_t lbm_mark_mutex
static

◆ lbm_mark_mutex_initialized

bool lbm_mark_mutex_initialized = false
static