LispBM
|
#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"
Variables | |
lbm_heap_state_t | lbm_heap_state |
lbm_const_heap_t * | lbm_const_heap_state |
lbm_cons_t * | lbm_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_t * | ctx_running |
static const_heap_write_fun | const_heap_write = dummy_flash_write |
|
static |
|
static |
lbm_flash_status lbm_allocate_const_cell | ( | lbm_value * | res | ) |
lbm_flash_status lbm_allocate_const_raw | ( | lbm_uint | nwords, |
lbm_uint * | res | ||
) |
Accesses the car field the car field of an lbm_cons_t.
cons | Value |
Accesses the car of the cdr of an cons cell
c | Value |
Accesses the car field of an lbm_cons_t.
cons | Value |
Accesses the cdr of an cdr field of an lbm_cons_t.
cons | Value |
Accesses the cdr field of an lbm_cons_t.
cons | Value |
Allocates an lbm_cons_t cell from the heap and populates it.
car | The value to put in the car field of the allocated lbm_cons_t. |
cdr | The value to put in the cdr field of the allocated lbm_cons_t. |
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_const_write | ( | lbm_uint * | tgt, |
lbm_uint | val | ||
) |
uint8_t lbm_dec_as_char | ( | lbm_value | a | ) |
Decode a numerical value as if it is char
val | Value to decode |
double lbm_dec_as_double | ( | lbm_value | val | ) |
Decode a numerical value as a float.
val | Value to decode. |
float lbm_dec_as_float | ( | lbm_value | val | ) |
Decode a numerical value as a float.
val | Value to decode. |
int32_t lbm_dec_as_i32 | ( | lbm_value | val | ) |
Decode a numerical value as a signed integer.
val | Value to decode |
int64_t lbm_dec_as_i64 | ( | lbm_value | val | ) |
Decode a numerical value as a 64bit signed integer.
val | Value to decode |
Decode a numerical value into the architecture defined signed integer type.
val | Value to decode |
uint32_t lbm_dec_as_u32 | ( | lbm_value | val | ) |
Decode a numerical value as if it is unsigned
val | Value to decode |
uint64_t lbm_dec_as_u64 | ( | lbm_value | val | ) |
Decode a numerical value as if it is a 64bit unsigned
val | Value to decode |
Decode a numerical value into the architecture defined unsigned integer type.
val | Value to decode |
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.
val | Value |
Decode an lbm_value representing a custom type into a lbm_uint value.
val | Value. |
double lbm_dec_double | ( | lbm_value | x | ) |
Decode an lbm_value representing a double.
x | Value to decode. |
float lbm_dec_float | ( | lbm_value | x | ) |
Decode an lbm_value representing a float.
x | Value to decode. |
int64_t lbm_dec_i64 | ( | lbm_value | x | ) |
Decode an lbm_value representing a 64 bit integer.
x | Value to decode. |
char* lbm_dec_str | ( | lbm_value | val | ) |
Decode an lbm_value representing a string into a C string
val | Value |
uint64_t lbm_dec_u64 | ( | lbm_value | x | ) |
Decode an lbm_value representing a 64 bit unsigned integer.
x | Value to decode. |
lbm_value lbm_enc_double | ( | double | x | ) |
Encode a double into an lbm_value.
x | double to encode. |
lbm_value lbm_enc_float | ( | float | x | ) |
Encode a float into an lbm_value.
x | float value to encode. |
lbm_value lbm_enc_i32 | ( | int32_t | x | ) |
Encode 32 bit integer into an lbm_value.
x | Value to encode. |
lbm_value lbm_enc_i64 | ( | int64_t | x | ) |
Encode a 64 bit integer into an lbm_value.
x | 64 bit integer to encode. |
lbm_value lbm_enc_u32 | ( | uint32_t | x | ) |
Encode 32 bit unsigned integer into an lbm_value.
x | Value to encode. |
lbm_value lbm_enc_u64 | ( | uint64_t | x | ) |
Encode a 64 bit unsigned integer into an lbm_value.
x | 64 bit unsigned integer to encode. |
lbm_uint lbm_flash_memory_usage | ( | void | ) |
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.
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.
data | Array of roots to traverse from. |
n | Number of elements in roots-array. |
void lbm_gc_mark_env | ( | lbm_value | ) |
Mark all heap cells reachable from an environment.
environment. |
void lbm_gc_mark_phase | ( | lbm_value | root | ) |
Mark heap cells reachable from the lbm_value v.
root |
Performs lbm_gc_mark_phase on all the values in the roots array.
roots | pointer to array of roots. |
num_roots | size of array of roots. |
void lbm_gc_state_inc | ( | void | ) |
Increment the counter that is counting the number of times GC ran
int lbm_gc_sweep_phase | ( | void | ) |
Sweep up all non marked heap cells and place them on the free list.
void lbm_gc_unlock | ( | void | ) |
|
inlinestatic |
|
inlinestatic |
lbm_uint lbm_get_gc_stack_max | ( | void | ) |
Get the maximum stack level of the GC stack
lbm_uint lbm_get_gc_stack_size | ( | void | ) |
Get the size of the GC stack.
void lbm_get_heap_state | ( | lbm_heap_state_t * | ) |
Get a copy of the heap statistics structure.
A | pointer to an lbm_heap_state_t to populate with the current statistics. |
Allocate an bytearray in symbols and arrays memory (lispbm_memory.h) and create a heap cell that refers to this bytearray.
res | The resulting lbm_value is returned through this argument. |
size | Array size in number of 32 bit words. |
Allocate an lbm_cons_t cell from the heap.
type | A type that can be encoded onto the cell (most often LBM_PTR_TYPE_CONS). |
car | Value to write into car position of allocated cell. |
cdr | Value to write into cdr position of allocated cell. |
Allocate an array in symbols and arrays memory (lispbm_memory.h) and create a heap cell that refers to this array.
res | The resulting lbm_value is returned through this argument. |
size | Array size in number of 32 bit words. |
Allocate a list of n heap-cells.
n | The number of heap-cells to allocate. |
lbm_value lbm_heap_allocate_list_init | ( | unsigned int | n, |
... | |||
) |
Allocate a list of n heap-cells and initialize the values.
n | The length of list to allocate. |
... | The values to initialize the list with. |
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.
n | The length of list to allocate. |
valist | The values in a va_list to initialize the list with. |
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.
arr | lbm_value array to get pointer from. |
uint8_t* lbm_heap_array_get_data_rw | ( | lbm_value | arr | ) |
Get a pointer to the data of an array for read/write purposes.
arr | lbm_value array to get pointer from. |
Get the size of an array value.
arr | lbm_value array to get size of. |
int lbm_heap_explicit_free_array | ( | lbm_value | arr | ) |
Explicitly free an array. This function needs to be used with care and knowledge.
arr | Array value. |
int lbm_heap_init | ( | lbm_cons_t * | addr, |
lbm_uint | num_cells, | ||
lbm_uint | gc_stack_size | ||
) |
Initialize heap storage.
addr | Pointer to an array of lbm_cons_t elements. This array must at least be aligned 4. |
num_cells | Number of lbm_cons_t elements in the array. |
gc_stack_size | Size of the gc_stack in number of words. |
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_uint lbm_heap_num_allocated | ( | void | ) |
Check how many lbm_cons_t cells are allocated.
lbm_uint lbm_heap_size | ( | void | ) |
Size of the heap in number of lbm_cons_t cells.
lbm_uint lbm_heap_size_bytes | ( | void | ) |
Size of the heap in bytes.
Index into a list.
l | List to index into. |
n | Position to read out of the list. |
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.
res | lbm_value result pointer for storage of the result array. |
data | C array. |
type | The type tag to assign to the resulting LBM array. |
num_elt | Number of elements in the array. |
A destructive append of two lists
list1 | A list |
list2 | A list |
Copy a list
m | Number of elements to copy or -1 for all. If 1, m will be updated with the length of the list |
list | A list. |
Reverse a proper list destroying the original.
list | A list |
Drop values from the head of a list.
n | Number of values to drop. |
ls | List to drop values from. |
Calculate the length of a proper list
c | A list |
Calculate the length of a proper list and evaluate a predicate for each element.
c | A list |
pres | Boolean result of predicate, false if predicate is false for any of the elements in the list, otherwise true. |
pred | Predicate to evaluate for each element of the list. |
Reverse a proper list
list | A list |
void lbm_nil_freelist | ( | void | ) |
Set the freelist to NIL. Means that no memory will be available until after a garbage collection.
Update the value stored in the car field of a heap cell.
c | Value referring to a heap cell. |
v | Value to replace the car field with. |
Update the value stored in the car and cdr fields of a heap cell.
c | Value referring to a heap cell. |
car_val | Value to replace the car field with. |
cdr_val | Value to replace the cdr field with. |
Update the value stored in the cdr field of a heap cell.
c | Value referring to a heap cell. |
v | Value to replace the cdr field with. |
Query the size in bytes of an lbm_type.
t | Type |
lbm_flash_status lbm_write_const_raw | ( | lbm_uint * | data, |
lbm_uint | n, | ||
lbm_uint * | res | ||
) |
lbm_flash_status write_const_car | ( | lbm_value | cell, |
lbm_value | val | ||
) |
lbm_flash_status write_const_cdr | ( | lbm_value | cell, |
lbm_value | val | ||
) |
|
static |
eval_context_t* ctx_running |
|
static |
|
static |
lbm_const_heap_t* lbm_const_heap_state |
lbm_heap_state_t lbm_heap_state |
lbm_cons_t* lbm_heaps[2] = {NULL, NULL} |
|
static |
|
static |