30 #include "lbm_defines.h"
196 #define LBM_ADDRESS_SHIFT 2
197 #define LBM_VAL_SHIFT 4
199 #define LBM_PTR_MASK 0x00000001u
200 #define LBM_PTR_BIT 0x00000001u
201 #define LBM_PTR_VAL_MASK 0x03FFFFFCu
202 #define LBM_PTR_TYPE_MASK 0xFC000000u
203 #define LBM_PTR_NULL (0x03FFFFFCu >> 2)
206 #define LBM_PTR_TO_CONSTANT_BIT 0x04000000u
207 #define LBM_PTR_TO_CONSTANT_MASK ~LBM_PTR_TO_CONSTANT_BIT
208 #define LBM_PTR_TO_CONSTANT_SHIFT 26
212 #define LBM_ADDRESS_SHIFT 2
213 #define LBM_VAL_SHIFT 8
215 #define LBM_PTR_MASK (lbm_uint)0x1
216 #define LBM_PTR_BIT (lbm_uint)0x1
217 #define LBM_PTR_VAL_MASK (lbm_uint)0x03FFFFFFFFFFFFFC
218 #define LBM_PTR_TYPE_MASK (lbm_uint)0xF800000000000000
219 #define LBM_PTR_NULL ((lbm_uint)0x03FFFFFFFFFFFFFC >> 2)
221 #define LBM_PTR_TO_CONSTANT_BIT (lbm_uint)0x0400000000000000
222 #define LBM_PTR_TO_CONSTANT_MASK ~LBM_PTR_TO_CONSTANT_BIT
223 #define LBM_PTR_TO_CONSTANT_SHIFT 58
230 LBM_FLASH_WRITE_ERROR
253 lbm_uint num_alloc_arrays;
257 lbm_uint gc_recovered;
258 lbm_uint gc_recovered_arrays;
259 lbm_uint gc_least_free;
260 lbm_uint gc_last_free;
266 typedef bool (*const_heap_write_fun)(lbm_uint ix, lbm_uint w);
291 void lbm_gc_unlock(
void);
300 lbm_uint gc_stack_size);
641 int lbm_const_heap_init(const_heap_write_fun w_fun,
646 lbm_flash_status lbm_allocate_const_cell(
lbm_value *res);
647 lbm_flash_status lbm_write_const_raw(lbm_uint *data, lbm_uint n, lbm_uint *res);
650 lbm_uint lbm_flash_memory_usage(
void);
658 return (x & LBM_PTR_MASK) ? (x & LBM_PTR_TYPE_MASK) : (x & LBM_VAL_TYPE_MASK);
663 return (x & LBM_PTR_MASK) ?
664 (x & (LBM_PTR_TO_CONSTANT_MASK & LBM_PTR_TYPE_MASK)) :
665 (x & LBM_VAL_TYPE_MASK);
668 static inline lbm_value lbm_enc_cons_ptr(lbm_uint x) {
669 return ((x << LBM_ADDRESS_SHIFT) | LBM_TYPE_CONS | LBM_PTR_BIT);
672 static inline lbm_uint lbm_dec_ptr(
lbm_value p) {
673 return ((LBM_PTR_VAL_MASK & p) >> LBM_ADDRESS_SHIFT);
678 static inline lbm_uint lbm_dec_cons_cell_ptr(
lbm_value p) {
679 lbm_uint h = (p & LBM_PTR_TO_CONSTANT_BIT) >> LBM_PTR_TO_CONSTANT_SHIFT;
680 return lbm_dec_ptr(p) >> h;
684 lbm_uint h = (p & LBM_PTR_TO_CONSTANT_BIT) >> LBM_PTR_TO_CONSTANT_SHIFT;
689 return ((LBM_PTR_VAL_MASK & p) | t | LBM_PTR_BIT);
692 static inline lbm_value lbm_enc_sym(lbm_uint s) {
693 return (s << LBM_VAL_SHIFT) | LBM_TYPE_SYMBOL;
696 static inline lbm_value lbm_enc_i(lbm_int x) {
697 return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_I;
700 static inline lbm_value lbm_enc_u(lbm_uint x) {
701 return (x << LBM_VAL_SHIFT) | LBM_TYPE_U;
740 static inline lbm_value lbm_enc_char(
char x) {
741 return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_CHAR;
744 static inline lbm_int lbm_dec_i(
lbm_value x) {
745 return (lbm_int)x >> LBM_VAL_SHIFT;
748 static inline lbm_uint lbm_dec_u(
lbm_value x) {
749 return x >> LBM_VAL_SHIFT;
752 static inline char lbm_dec_char(
lbm_value x) {
753 return (
char)(x >> LBM_VAL_SHIFT);
756 static inline lbm_uint lbm_dec_sym(
lbm_value x) {
757 return x >> LBM_VAL_SHIFT;
773 static inline uint32_t lbm_dec_u32(
lbm_value x) {
777 return (uint32_t)(x >> LBM_VAL_SHIFT);
787 static inline int32_t lbm_dec_i32(
lbm_value x) {
791 return (int32_t)(x >> LBM_VAL_SHIFT);
801 static inline bool lbm_is_ptr(
lbm_value x) {
802 return (x & LBM_PTR_MASK);
805 static inline bool lbm_is_cons_rw(
lbm_value x) {
809 static inline bool lbm_is_cons(
lbm_value x) {
811 return (t == LBM_TYPE_CONS ||
812 t == (LBM_TYPE_CONS | LBM_PTR_TO_CONSTANT_BIT));
827 return ((t & LBM_PTR_TO_CONSTANT_MASK) == LBM_TYPE_ARRAY);
830 static inline bool lbm_is_array_rw(
lbm_value x) {
831 return( (
lbm_type_of(x) == LBM_TYPE_ARRAY) && !(x & LBM_PTR_TO_CONSTANT_BIT));
834 static inline bool lbm_is_channel(
lbm_value x) {
837 lbm_dec_sym(
lbm_cdr(x)) == SYM_CHANNEL_TYPE);
839 static inline bool lbm_is_char(
lbm_value x) {
843 static inline bool lbm_is_special(
lbm_value symrep) {
844 return ((
lbm_type_of(symrep) == LBM_TYPE_SYMBOL) &&
845 (lbm_dec_sym(symrep) < SPECIAL_SYMBOLS_END));
848 static inline bool lbm_is_closure(
lbm_value exp) {
849 return ((lbm_is_cons(exp)) &&
851 (lbm_dec_sym(
lbm_car(exp)) == SYM_CLOSURE));
854 static inline bool lbm_is_continuation(
lbm_value exp) {
857 (lbm_dec_sym(
lbm_car(exp)) == SYM_CONT));
860 static inline bool lbm_is_macro(
lbm_value exp) {
863 (lbm_dec_sym(
lbm_car(exp)) == SYM_MACRO));
866 static inline bool lbm_is_match_binder(
lbm_value exp) {
867 return (lbm_is_cons(exp) &&
869 ((lbm_dec_sym(
lbm_car(exp)) == SYM_MATCH_ANY)));
872 static inline bool lbm_is_comma_qualified_symbol(
lbm_value exp) {
873 return (lbm_is_cons(exp) &&
875 (lbm_dec_sym(
lbm_car(exp)) == SYM_COMMA) &&
879 static inline bool lbm_is_symbol(
lbm_value exp) {
883 static inline bool lbm_is_symbol_nil(
lbm_value exp) {
884 return (lbm_is_symbol(exp) && lbm_dec_sym(exp) == SYM_NIL);
887 static inline bool lbm_is_symbol_true(
lbm_value exp) {
888 return (lbm_is_symbol(exp) && lbm_dec_sym(exp) == SYM_TRUE);
891 static inline bool lbm_is_symbol_eval(
lbm_value exp) {
892 return (lbm_is_symbol(exp) && lbm_dec_sym(exp) == SYM_EVAL);
895 static inline bool lbm_is_symbol_merror(
lbm_value exp) {
896 return (lbm_is_symbol(exp) && lbm_dec_sym(exp) == SYM_MERROR);
899 static inline bool lbm_is_list(
lbm_value x) {
900 return (lbm_is_cons(x) || lbm_is_symbol_nil(x));
903 static inline bool lbm_is_list_rw(
lbm_value x) {
904 return (lbm_is_cons_rw(x) || lbm_is_symbol_nil(x));
907 static inline bool lbm_is_quoted_list(
lbm_value x) {
908 return (lbm_is_cons(x) &&
910 (lbm_dec_sym(
lbm_car(x)) == SYM_QUOTE) &&
916 #define ERROR_SYMBOL_MASK 0xFFFFFFF0
918 #define ERROR_SYMBOL_MASK 0xFFFFFFFFFFFFFFF0
922 static inline bool lbm_is_error(
lbm_value v){
924 ((lbm_dec_sym(v) & ERROR_SYMBOL_MASK) == 0x20));
930 return &lbm_dec_heap(addr)[lbm_dec_cons_cell_ptr(addr)];
int32_t lbm_dec_as_i32(lbm_value val)
lbm_uint lbm_heap_size_bytes(void)
lbm_value lbm_enc_double(double x)
lbm_value lbm_list_reverse(lbm_value list)
int64_t lbm_dec_as_i64(lbm_value val)
void lbm_gc_mark_env(lbm_value)
lbm_value lbm_list_append(lbm_value list1, lbm_value list2)
uint8_t * lbm_heap_array_get_data(lbm_value arr)
void lbm_heap_new_gc_time(lbm_uint dur)
lbm_value lbm_cddr(lbm_value c)
lbm_uint lbm_dec_custom(lbm_value val)
lbm_uint lbm_heap_num_free(void)
lbm_value lbm_heap_allocate_cell(lbm_type type, lbm_value car, lbm_value cdr)
lbm_uint lbm_get_gc_stack_max(void)
lbm_value lbm_enc_float(float x)
lbm_char_channel_t * lbm_dec_channel(lbm_value val)
double lbm_dec_as_double(lbm_value val)
static bool lbm_is_array_r(lbm_value x)
Definition: heap.h:825
void lbm_get_heap_state(lbm_heap_state_t *)
lbm_value lbm_cons(lbm_value car, lbm_value cdr)
lbm_int lbm_heap_array_get_size(lbm_value arr)
lbm_value lbm_list_copy(int *m, lbm_value list)
int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt)
int lbm_set_car(lbm_value c, lbm_value v)
lbm_value lbm_cdr(lbm_value cons)
void lbm_gc_mark_aux(lbm_uint *data, lbm_uint n)
void lbm_gc_state_inc(void)
lbm_value lbm_heap_allocate_list(lbm_uint n)
lbm_value lbm_caar(lbm_value c)
bool lbm_is_number(lbm_value x)
int lbm_heap_allocate_array(lbm_value *res, lbm_uint size)
lbm_uint lbm_list_length(lbm_value c)
lbm_uint lbm_size_of(lbm_type t)
uint64_t lbm_dec_u64(lbm_value x)
lbm_value lbm_heap_allocate_list_init(unsigned int n,...)
lbm_uint lbm_heap_size(void)
static lbm_type lbm_type_of(lbm_value x)
Definition: heap.h:657
int lbm_set_cdr(lbm_value c, lbm_value v)
char * lbm_dec_str(lbm_value val)
int lbm_heap_init(lbm_cons_t *addr, lbm_uint num_cells, lbm_uint gc_stack_size)
uint64_t lbm_dec_as_u64(lbm_value val)
lbm_value lbm_car(lbm_value cons)
lbm_value lbm_cadr(lbm_value c)
lbm_value lbm_enc_u32(uint32_t x)
char lbm_dec_as_char(lbm_value a)
int lbm_set_car_and_cdr(lbm_value c, lbm_value car_val, lbm_value cdr_val)
lbm_value lbm_enc_i32(int32_t x)
void lbm_heap_new_freelist_length(void)
lbm_value lbm_enc_i64(int64_t x)
lbm_value lbm_enc_u64(uint64_t x)
int lbm_gc_sweep_phase(void)
float lbm_dec_as_float(lbm_value val)
unsigned int lbm_list_length_pred(lbm_value c, bool *pres, bool(*pred)(lbm_value))
void lbm_nil_freelist(void)
int lbm_heap_explicit_free_array(lbm_value arr)
lbm_uint lbm_get_gc_stack_size(void)
lbm_value lbm_list_drop(unsigned int n, lbm_value ls)
lbm_uint lbm_heap_num_allocated(void)
void lbm_gc_mark_roots(lbm_uint *roots, lbm_uint num_roots)
lbm_value lbm_heap_allocate_list_init_va(unsigned int n, va_list valist)
int lbm_gc_mark_freelist(void)
float lbm_dec_float(lbm_value x)
uint32_t lbm_dec_as_u32(lbm_value val)
lbm_value lbm_list_destructive_reverse(lbm_value list)
int64_t lbm_dec_i64(lbm_value x)
void lbm_gc_mark_phase(lbm_value root)
double lbm_dec_double(lbm_value x)
uint32_t lbm_type
Definition: lbm_types.h:45
uint32_t lbm_value
Definition: lbm_types.h:43
Definition: lbm_channel.h:68