LispBM
heap.h
Go to the documentation of this file.
1 /*
2  Copyright 2018, 2024 Joel Svensson svenssonjoel@yahoo.se
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
19 #ifndef HEAP_H_
20 #define HEAP_H_
21 
22 #include <string.h>
23 #include <stdarg.h>
24 
25 #include "lbm_types.h"
26 #include "symrepr.h"
27 #include "stack.h"
28 #include "lbm_memory.h"
29 #include "lbm_defines.h"
30 #include "lbm_channel.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37 Planning for a more space efficient heap representation.
38 TODO: Need to find a good reference to read up on this.
39  - List based heap
40  - Easy to implement and somewhat efficient
41 
42 0000 0000 Size Free bits
43 003F FFFF 4MB 10
44 007F FFFF 8MB 9
45 00FF FFFF 16MB 8
46 01FF FFFF 32MB 7
47 03FF FFFF 64MB 6 * Kind of heap size I am looking for
48 07FF FFFF 128MB 5
49 0FFF FFFF 256MB 4
50 1FFF FFFF 512MB 3
51 
52 
53 --- May 9 2021 ---
54 Actually now I am much more interested in way smaller memories ;)
55 
56 0000 0000 Size Free bits
57 0000 0FFF 4KB 20 |
58 0000 1FFF 8KB 19 |
59 0000 3FFF 16KB 18 |
60 0000 7FFF 32KB 17 |
61 0000 FFFF 64KB 16 |
62 0001 FFFF 128KB 15 |
63 0003 FFFF 256KB 14 | - This range is very interesting.
64 0007 FFFF 512KB 13
65 000F FFFF 1MB 12
66 001F FFFF 2MB 11
67 003F FFFF 4MB 10
68 007F FFFF 8MB 9
69 00FF FFFF 16MB 8
70 01FF FFFF 32MB 7
71 03FF FFFF 64MB 6
72 07FF FFFF 128MB 5
73 0FFF FFFF 256MB 4
74 1FFF FFFF 512MB 3
75 
76 Those are the kind of platforms that are fun... so a bunch of
77 wasted bits in heap pointers if we run on small MCUs.
78 
79 -----------------
80 
81 it is also the case that not all addresses will be used if all "cells" are
82 of the same size, 8 bytes...
83 
84 value 0: 0000 0000
85 value 1: 0000 0008
86 value 3: 0000 0010
87 value 4: 0000 0018
88 
89 Means bits 0,1,2 will always be empty in a valid address.
90 
91 Cons cells also need to be have room for 2 pointers. So each ted cell from
92 memory should be 8bytes.
93 
94 Things that needs to be represented within these bits:
95 
96  - GC MARK one per cell
97  - TYPE: type of CAR and type of cons
98 
99 Types I would want:
100  - Full 32bit integer. Does not leave room for identification of type
101  - Float values. Same problem
102 
103 
104 Free bits in pointers 64MB heap:
105 31 30 29 28 27 26 2 1 0
106 0 0 0 0 0 0 XX XXXX XXXX XXXX XXXX XXXX X 0 0 0
107 
108 
109 Information needed for each cell:
110  Meaning | bits total | bits per car | bits per cdr
111  GC mark | 2 | 1 | 1 - only one of them will be used (the other is wasted)
112  Type | 2x | x | x
113  Ptr/!ptr | 2 | 1 | 1
114 
115 
116 Types (unboxed):
117  - Symbols
118  - 28bit integer ( will need signed shift right functionality )
119  - 28bit unsigned integer
120  - Character
121 
122 If four types is all that should be possible (unboxed). then 2 bits are needed to differentiate.
123 2 + 1 + 1 = 4 => 28bits for data.
124 
125 bit 0: ptr/!ptr
126 bit 1: gc
127 bit 2-3: type (if not ptr)
128 bit 3 - 24 ptr (if ptr)
129 bit 4 - 31 value (if value)
130 
131 An unboxed value can occupy a car or cdr field in a cons cell.
132 
133 types (boxed) extra information in pointer to cell can contain information
134  - 32 bit integer
135  - 32 bit unsigned integer
136  - 32 bit float
137 
138 boxed representation:
139  [ptr| cdr]
140  |
141  [Value | Aux + GC_MARK]
142 
143 Kinds of pointers:
144  - Pointer to cons cell.
145  - Pointer to unboxed value (fixnums not in a list, I hope this is so rare that it can be removed )
146  - integer
147  - unsigned integer
148  - symbol
149  - float
150  - Pointer to boxed value.
151  - 32 bit integer
152  - 32 bit unsigned integer
153  - 32 bit float
154  - (Maybe something else ? Vectors/strings allocated in memory not occupied by heap?)
155  - vector of int
156  - vector of uint
157  - vector of float
158  - vector of double
159  - String
160 
161 13 pointer"types" -> needs 4 bits
162 for 64MB heap there are 6 free bits. So with this scheme going to 128MB or 256MB heap
163 is also possible
164 
165  a pointer to some off heap vector/string could be represented by
166 
167  [ptr | cdr]
168  |
169  [full pointer | Aux + GC_MARK]
170  |
171  [VECTOR]
172 
173 Aux bits could be used for storing vector size. Up to 30bits should be available there
174 >> This is problematic. Now the information that something is a vector is split up
175 >> between 2 cons cells. This means GC needs both of these intact to be able to make
176 >> proper decision.
177 >> Will try to resolve this by adding some special symbols. But these must be symbols
178 >> that cannot occur normally in programs. Then an array could be:
179 
180  [Full pointer | ARRAY_SYM + GC_MARK]
181  |
182  [VECTOR]
183 
184 >> Boxed values same treatment as above.
185 >> TODO: Could this be simpler?
186 
187 [ VALUE | TYPE_SYM + GC_MARK]
188 
189 
190 0000 00XX XXXX XXXX XXXX XXXX XXXX X000 : 0x03FF FFF8
191 1111 AA00 0000 0000 0000 0000 0000 0000 : 0xFC00 0000 (AA bits left unused for now, future heap growth?)
192  */
193 
194 typedef enum {
199 
203 typedef struct {
206 } lbm_cons_t;
207 
211 typedef struct {
213  lbm_value freelist; // list of free cons cells.
215 
216  lbm_uint heap_size; // In number of cells.
217  lbm_uint heap_bytes; // In bytes.
218 
219  lbm_uint num_alloc; // Number of cells allocated.
220  lbm_uint num_alloc_arrays; // Number of arrays allocated.
221 
222  lbm_uint gc_num; // Number of times gc has been performed.
223  lbm_uint gc_marked; // Number of cells marked by mark phase.
224  lbm_uint gc_recovered; // Number of cells recovered by sweep phase.
225  lbm_uint gc_recovered_arrays;// Number of arrays recovered by sweep.
226  lbm_uint gc_least_free; // The smallest length of the freelist.
227  lbm_uint gc_last_free; // Number of elements on the freelist
228  // after most recent GC.
230 
232 
233 typedef bool (*const_heap_write_fun)(lbm_uint ix, lbm_uint w);
234 
235 typedef struct {
237  lbm_uint next; // next free index.
238  lbm_uint size; // in lbm_uint words. (cons-cells = words / 2)
240 
246 typedef struct {
250 
251 typedef struct {
254  uint32_t index; // Limits arrays to max 2^32-1 elements.
256 
261 void lbm_gc_lock(void);
262 /* Unlock GC mutex
263  */
264 void lbm_gc_unlock(void);
265 
272 int lbm_heap_init(lbm_cons_t *addr, lbm_uint num_cells,
273  lbm_uint gc_stack_size);
274 
289 static inline lbm_uint lbm_heap_num_free(void) {
291 }
292 
302 lbm_uint lbm_heap_size(void);
327 lbm_value lbm_heap_allocate_list_init_va(unsigned int n, va_list valist);
333 lbm_value lbm_heap_allocate_list_init(unsigned int n, ...);
339 char *lbm_dec_str(lbm_value val);
377 uint8_t lbm_dec_as_char(lbm_value a);
383 uint32_t lbm_dec_as_u32(lbm_value val);
389 int32_t lbm_dec_as_i32(lbm_value val);
395 float lbm_dec_as_float(lbm_value val);
401 uint64_t lbm_dec_as_u64(lbm_value val);
407 int64_t lbm_dec_as_i64(lbm_value val);
413 double lbm_dec_as_double(lbm_value val);
414 
421 
428 
438 
496 int lbm_set_car_and_cdr(lbm_value c, lbm_value car_val, lbm_value cdr_val);
497 // List functions
506 
515 unsigned int lbm_list_length_pred(lbm_value c, bool *pres, bool (*pred)(lbm_value));
540 lbm_value lbm_list_copy(int *m, lbm_value list);
541 
549 
555 lbm_value lbm_list_drop(unsigned int n, lbm_value ls);
561 lbm_value lbm_index_list(lbm_value l, int32_t n);
562 
563 // State and statistics
578 // Garbage collection
582 void lbm_gc_state_inc(void);
586 void lbm_nil_freelist(void);
594 void lbm_gc_mark_phase(lbm_value root);
602 void lbm_gc_mark_aux(lbm_uint *data, lbm_uint n);
607 void lbm_gc_mark_roots(lbm_uint *roots, lbm_uint num_roots);
612 int lbm_gc_sweep_phase(void);
613 
614 // Array functionality
637 int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt);
647 const uint8_t *lbm_heap_array_get_data_ro(lbm_value arr);
658 
664 
666  lbm_const_heap_t *heap,
667  lbm_uint *addr,
668  lbm_uint num_words);
669 
677 
683 static inline lbm_type lbm_type_of(lbm_value x) {
684  return (x & LBM_PTR_BIT) ? (x & LBM_PTR_TYPE_MASK) : (x & LBM_VAL_TYPE_MASK);
685 }
686 
687 // type-of check that is safe in functional code
689  return (x & LBM_PTR_BIT) ?
691  (x & LBM_VAL_TYPE_MASK);
692 }
693 
695  return ((x << LBM_ADDRESS_SHIFT) | LBM_TYPE_CONS | LBM_PTR_BIT);
696 }
697 
698 static inline lbm_uint lbm_dec_ptr(lbm_value p) {
699  return ((LBM_PTR_VAL_MASK & p) >> LBM_ADDRESS_SHIFT);
700 }
701 
702 extern lbm_cons_t *lbm_heaps[2];
703 
706  return lbm_dec_ptr(p) >> h;
707 }
708 
709 static inline lbm_cons_t *lbm_dec_heap(lbm_value p) {
711  return lbm_heaps[h];
712 }
713 
715  return ((LBM_PTR_VAL_MASK & p) | t | LBM_PTR_BIT);
716 }
717 
718 static inline lbm_value lbm_enc_sym(lbm_uint s) {
719  return (s << LBM_VAL_SHIFT) | LBM_TYPE_SYMBOL;
720 }
721 
722 static inline lbm_value lbm_enc_i(lbm_int x) {
723  return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_I;
724 }
725 
726 static inline lbm_value lbm_enc_u(lbm_uint x) {
727  return (x << LBM_VAL_SHIFT) | LBM_TYPE_U;
728 }
729 
734 extern lbm_value lbm_enc_i32(int32_t x);
735 
740 extern lbm_value lbm_enc_u32(uint32_t x);
741 
746 extern lbm_value lbm_enc_float(float x);
747 
752 extern lbm_value lbm_enc_i64(int64_t x);
753 
758 extern lbm_value lbm_enc_u64(uint64_t x);
759 
764 extern lbm_value lbm_enc_double(double x);
765 
766 static inline lbm_value lbm_enc_char(uint8_t x) {
767  return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_CHAR;
768 }
769 
770 static inline lbm_int lbm_dec_i(lbm_value x) {
771  return (lbm_int)x >> LBM_VAL_SHIFT;
772 }
773 
774 static inline lbm_uint lbm_dec_u(lbm_value x) {
775  return x >> LBM_VAL_SHIFT;
776 }
777 
778 static inline uint8_t lbm_dec_char(lbm_value x) {
779  return (uint8_t)(x >> LBM_VAL_SHIFT);
780 }
781 
782 static inline lbm_uint lbm_dec_sym(lbm_value x) {
783  return x >> LBM_VAL_SHIFT;
784 }
785 
790 extern float lbm_dec_float(lbm_value x);
791 
796 extern double lbm_dec_double(lbm_value x);
797 
798 
799 static inline uint32_t lbm_dec_u32(lbm_value x) {
800 #ifndef LBM64
801  return (uint32_t)lbm_car(x);
802 #else
803  return (uint32_t)(x >> LBM_VAL_SHIFT);
804 #endif
805 }
806 
811 extern uint64_t lbm_dec_u64(lbm_value x);
812 
813 static inline int32_t lbm_dec_i32(lbm_value x) {
814 #ifndef LBM64
815  return (int32_t)lbm_car(x);
816 #else
817  return (int32_t)(x >> LBM_VAL_SHIFT);
818 #endif
819 }
820 
825 extern int64_t lbm_dec_i64(lbm_value x);
826 
832 static inline bool lbm_is_ptr(lbm_value x) {
833  return (x & LBM_PTR_BIT);
834 }
835 
841 static inline bool lbm_is_cons_rw(lbm_value x) {
842  return (lbm_type_of(x) == LBM_TYPE_CONS);
843 }
844 
850 static inline bool lbm_is_cons(lbm_value x) {
851  return lbm_is_ptr(x) && ((x & LBM_CONS_TYPE_MASK) == LBM_TYPE_CONS);
852 }
853 
854 static inline bool lbm_is_symbol_nil(lbm_value exp) {
855  return !exp;
856 }
857 
862 static inline bool lbm_is_number(lbm_value x) {
863  return
864  (x & LBM_PTR_BIT) ?
865  ((x & LBM_NUMBER_MASK) == LBM_NUMBER_MASK) :
866  (x & LBM_VAL_TYPE_MASK);
867 }
868 
869 // Check if an array is valid (an invalid array has been freed by someone explicitly)
870 static inline bool lbm_heap_array_valid(lbm_value arr) {
871  return !(lbm_is_symbol_nil(lbm_car(arr))); // this is an is_zero check similar to (a == NULL)
872 }
873 
878 static inline bool lbm_is_array_r(lbm_value x) {
879  lbm_type t = lbm_type_of(x);
881 }
882 
883 static inline bool lbm_is_array_rw(lbm_value x) {
884  return ((lbm_type_of(x) == LBM_TYPE_ARRAY) &&
885  !(x & LBM_PTR_TO_CONSTANT_BIT) &&
887 }
888 
889 static inline bool lbm_is_lisp_array_r(lbm_value x) {
890  lbm_type t = lbm_type_of(x);
892 }
893 
894 static inline bool lbm_is_lisp_array_rw(lbm_value x) {
895  return( (lbm_type_of(x) == LBM_TYPE_LISPARRAY) && !(x & LBM_PTR_TO_CONSTANT_BIT));
896 }
897 
898 
899 static inline bool lbm_is_channel(lbm_value x) {
900  return (lbm_type_of(x) == LBM_TYPE_CHANNEL &&
903 }
904 static inline bool lbm_is_char(lbm_value x) {
905  return (lbm_type_of(x) == LBM_TYPE_CHAR);
906 }
907 
908 static inline bool lbm_is_special(lbm_value symrep) {
909  return ((lbm_type_of(symrep) == LBM_TYPE_SYMBOL) &&
910  (lbm_dec_sym(symrep) < SPECIAL_SYMBOLS_END));
911 }
912 
913 static inline bool lbm_is_closure(lbm_value exp) {
914  return ((lbm_is_cons(exp)) &&
915  (lbm_type_of(lbm_car(exp)) == LBM_TYPE_SYMBOL) &&
916  (lbm_car(exp) == ENC_SYM_CLOSURE));
917 }
918 
919 static inline bool lbm_is_continuation(lbm_value exp) {
920  return ((lbm_type_of(exp) == LBM_TYPE_CONS) &&
921  (lbm_type_of(lbm_car(exp)) == LBM_TYPE_SYMBOL) &&
922  (lbm_car(exp) == ENC_SYM_CONT));
923 }
924 
925 static inline bool lbm_is_macro(lbm_value exp) {
926  return ((lbm_type_of(exp) == LBM_TYPE_CONS) &&
927  (lbm_type_of(lbm_car(exp)) == LBM_TYPE_SYMBOL) &&
928  (lbm_car(exp) == ENC_SYM_MACRO));
929 }
930 
931 static inline bool lbm_is_match_binder(lbm_value exp) {
932  return (lbm_is_cons(exp) &&
933  (lbm_type_of(lbm_car(exp)) == LBM_TYPE_SYMBOL) &&
934  (lbm_car(exp) == ENC_SYM_MATCH_ANY));
935 }
936 
937 static inline bool lbm_is_comma_qualified_symbol(lbm_value exp) {
938  return (lbm_is_cons(exp) &&
939  (lbm_type_of(lbm_car(exp)) == LBM_TYPE_SYMBOL) &&
940  (lbm_car(exp) == ENC_SYM_COMMA) &&
942 }
943 
944 static inline bool lbm_is_symbol(lbm_value exp) {
945  return !(exp & LBM_LOW_RESERVED_BITS);
946 }
947 
948 static inline bool lbm_is_symbol_true(lbm_value exp) {
949  return (lbm_is_symbol(exp) && exp == ENC_SYM_TRUE);
950 }
951 
952 static inline bool lbm_is_symbol_eval(lbm_value exp) {
953  return (lbm_is_symbol(exp) && exp == ENC_SYM_EVAL);
954 }
955 
956 static inline bool lbm_is_symbol_merror(lbm_value exp) {
957  return lbm_is_symbol(exp) && (exp == ENC_SYM_MERROR);
958 }
959 
960 static inline bool lbm_is_list(lbm_value x) {
961  return (lbm_is_cons(x) || lbm_is_symbol_nil(x));
962 }
963 
964 static inline bool lbm_is_list_rw(lbm_value x) {
965  return (lbm_is_cons_rw(x) || lbm_is_symbol_nil(x));
966 }
967 
968 static inline bool lbm_is_quoted_list(lbm_value x) {
969  return (lbm_is_cons(x) &&
970  lbm_is_symbol(lbm_car(x)) &&
971  (lbm_car(x) == ENC_SYM_QUOTE) &&
972  lbm_is_cons(lbm_cdr(x)) &&
973  lbm_is_cons(lbm_cadr(x)));
974 }
975 
976 #ifndef LBM64
977 #define ERROR_SYMBOL_MASK 0xFFFFFFF0
978 #else
979 #define ERROR_SYMBOL_MASK 0xFFFFFFFFFFFFFFF0
980 #endif
981 
982 /* all error signaling symbols are in the range 0x20 - 0x2F */
983 static inline bool lbm_is_error(lbm_value v){
984  return (lbm_is_symbol(v) &&
985  ((lbm_dec_sym(v) & ERROR_SYMBOL_MASK) == 0x20));
986 }
987 
988 // ref_cell: returns a reference to the cell addressed by bits 3 - 26
989 // Assumes user has checked that is_ptr was set
990 static inline lbm_cons_t* lbm_ref_cell(lbm_value addr) {
991  return &lbm_dec_heap(addr)[lbm_dec_cons_cell_ptr(addr)];
992  //return &lbm_heap_state.heap[lbm_dec_ptr(addr)];
993 }
994 
995 
996 // lbm_uint a = lbm_heaps[0];
997 // lbm_uint b = lbm_heaps[1];
998 // lbm_uint i = (addr & LBM_PTR_TO_CONSTANT_BIT) >> LBM_PTR_TO_CONSTANT_SHIFT) - 1;
999 // lbm_uint h = (a & i) | (b & ~i);
1000 
1001 #ifdef __cplusplus
1002 }
1003 #endif
1004 #endif
lbm_enc_i
static lbm_value lbm_enc_i(lbm_int x)
Definition: heap.h:722
ERROR_SYMBOL_MASK
#define ERROR_SYMBOL_MASK
Definition: heap.h:977
lbm_cons_t::cdr
lbm_value cdr
Definition: heap.h:205
lbm_enc_char
static lbm_value lbm_enc_char(uint8_t x)
Definition: heap.h:766
LBM_NUMBER_MASK
#define LBM_NUMBER_MASK
Definition: lbm_defines.h:74
lbm_enc_u32
lbm_value lbm_enc_u32(uint32_t x)
Definition: heap.c:104
lbm_heap_num_free
static lbm_uint lbm_heap_num_free(void)
Definition: heap.h:289
lbm_car
lbm_value lbm_car(lbm_value cons)
Definition: heap.c:994
LBM_PTR_BIT
#define LBM_PTR_BIT
Definition: lbm_defines.h:32
SPECIAL_SYMBOLS_END
#define SPECIAL_SYMBOLS_END
Definition: lbm_defines.h:385
lbm_heap_new_gc_time
void lbm_heap_new_gc_time(lbm_uint dur)
lbm_gc_state_inc
void lbm_gc_state_inc(void)
Definition: heap.c:983
lbm_allocate_const_raw
lbm_flash_status lbm_allocate_const_raw(lbm_uint nwords, lbm_uint *res)
Definition: heap.c:1456
LBM_TYPE_CHANNEL
#define LBM_TYPE_CHANNEL
Definition: lbm_defines.h:54
lbm_list_append
lbm_value lbm_list_append(lbm_value list1, lbm_value list2)
Definition: heap.c:1169
lbm_defines.h
lbm_dec_ptr
static lbm_uint lbm_dec_ptr(lbm_value p)
Definition: heap.h:698
ENC_SYM_CONT
#define ENC_SYM_CONT
Definition: lbm_defines.h:488
lbm_heap_state_t::gc_num
lbm_uint gc_num
Definition: heap.h:222
lbm_is_channel
static bool lbm_is_channel(lbm_value x)
Definition: heap.h:899
const_heap_write_fun
bool(* const_heap_write_fun)(lbm_uint ix, lbm_uint w)
Definition: heap.h:233
lbm_const_heap_t::size
lbm_uint size
Definition: heap.h:238
ENC_SYM_QUOTE
#define ENC_SYM_QUOTE
Definition: lbm_defines.h:474
lbm_ref_cell
static lbm_cons_t * lbm_ref_cell(lbm_value addr)
Definition: heap.h:990
lbm_set_car_and_cdr
int lbm_set_car_and_cdr(lbm_value c, lbm_value car_val, lbm_value cdr_val)
Definition: heap.c:1068
lbm_enc_double
lbm_value lbm_enc_double(double x)
Definition: heap.c:165
LBM_PTR_TYPE_MASK
#define LBM_PTR_TYPE_MASK
Definition: lbm_defines.h:34
lbm_is_continuation
static bool lbm_is_continuation(lbm_value exp)
Definition: heap.h:919
lbm_dec_as_int
lbm_int lbm_dec_as_int(lbm_value val)
Definition: heap.c:444
lbm_array_header_extended_t::size
lbm_uint size
Definition: heap.h:252
LBM_LOW_RESERVED_BITS
#define LBM_LOW_RESERVED_BITS
Definition: lbm_defines.h:82
lbm_dec_array_r
lbm_array_header_t * lbm_dec_array_r(lbm_value val)
Definition: heap.c:246
lbm_is_quoted_list
static bool lbm_is_quoted_list(lbm_value x)
Definition: heap.h:968
lbm_dec_as_i32
int32_t lbm_dec_as_i32(lbm_value val)
Definition: heap.c:344
lbm_uint
uint32_t lbm_uint
Definition: lbm_types.h:48
lbm_gc_mark_env
void lbm_gc_mark_env(lbm_value)
Definition: heap.c:885
lbm_const_write
lbm_flash_status lbm_const_write(lbm_uint *tgt, lbm_uint val)
Definition: heap.c:1488
lbm_dec_sym
static lbm_uint lbm_dec_sym(lbm_value x)
Definition: heap.h:782
lbm_is_macro
static bool lbm_is_macro(lbm_value exp)
Definition: heap.h:925
lbm_is_cons_rw
static bool lbm_is_cons_rw(lbm_value x)
Definition: heap.h:841
lbm_is_lisp_array_r
static bool lbm_is_lisp_array_r(lbm_value x)
Definition: heap.h:889
lbm_list_length_pred
unsigned int lbm_list_length_pred(lbm_value c, bool *pres, bool(*pred)(lbm_value))
Definition: heap.c:1092
ENC_SYM_CHANNEL_TYPE
#define ENC_SYM_CHANNEL_TYPE
Definition: lbm_defines.h:427
lbm_cadr
lbm_value lbm_cadr(lbm_value c)
Definition: heap.c:1018
lbm_heap_state_t::heap_size
lbm_uint heap_size
Definition: heap.h:216
LBM_TYPE_SYMBOL
#define LBM_TYPE_SYMBOL
Definition: lbm_defines.h:77
lbm_heap_array_valid
static bool lbm_heap_array_valid(lbm_value arr)
Definition: heap.h:870
lbm_list_drop
lbm_value lbm_list_drop(unsigned int n, lbm_value ls)
Definition: heap.c:1185
lbm_dec_as_u32
uint32_t lbm_dec_as_u32(lbm_value val)
Definition: heap.c:320
LBM_FLASH_FULL
@ LBM_FLASH_FULL
Definition: heap.h:196
lbm_dec_double
double lbm_dec_double(lbm_value x)
Definition: heap.c:195
lbm_dec_i64
int64_t lbm_dec_i64(lbm_value x)
Definition: heap.c:224
lbm_is_symbol_nil
static bool lbm_is_symbol_nil(lbm_value exp)
Definition: heap.h:854
lbm_dec_as_double
double lbm_dec_as_double(lbm_value val)
Definition: heap.c:494
lbm_cdr
lbm_value lbm_cdr(lbm_value cons)
Definition: heap.c:1029
lbm_channel.h
lbm_heap_allocate_lisp_array
int lbm_heap_allocate_lisp_array(lbm_value *res, lbm_uint size)
Definition: heap.c:1273
lbm_heap_allocate_list
lbm_value lbm_heap_allocate_list(lbm_uint n)
Definition: heap.c:610
lbm_heap_state
lbm_heap_state_t lbm_heap_state
Definition: heap.c:65
lbm_gc_mark_aux
void lbm_gc_mark_aux(lbm_uint *data, lbm_uint n)
Definition: heap.c:901
lbm_heap_state_t::heap_bytes
lbm_uint heap_bytes
Definition: heap.h:217
LBM_FLASH_WRITE_ERROR
@ LBM_FLASH_WRITE_ERROR
Definition: heap.h:197
lbm_is_symbol_merror
static bool lbm_is_symbol_merror(lbm_value exp)
Definition: heap.h:956
lbm_heap_state_t::num_alloc
lbm_uint num_alloc
Definition: heap.h:219
lbm_heap_array_get_data_ro
const uint8_t * lbm_heap_array_get_data_ro(lbm_value arr)
Definition: heap.c:1317
lbm_dec_str
char * lbm_dec_str(lbm_value val)
Definition: heap.c:237
lbm_is_error
static bool lbm_is_error(lbm_value v)
Definition: heap.h:983
lbm_array_header_extended_t::data
lbm_uint * data
Definition: heap.h:253
lbm_flash_memory_usage
lbm_uint lbm_flash_memory_usage(void)
Definition: heap.c:1515
lbm_is_comma_qualified_symbol
static bool lbm_is_comma_qualified_symbol(lbm_value exp)
Definition: heap.h:937
lbm_heap_size
lbm_uint lbm_heap_size(void)
Definition: heap.c:669
lbm_write_const_raw
lbm_flash_status lbm_write_const_raw(lbm_uint *data, lbm_uint n, lbm_uint *res)
Definition: heap.c:1469
lbm_array_header_t
Definition: heap.h:246
lbm_dec_as_float
float lbm_dec_as_float(lbm_value val)
Definition: heap.c:469
lbm_nil_freelist
void lbm_nil_freelist(void)
Definition: heap.c:545
ENC_SYM_COMMA
#define ENC_SYM_COMMA
Definition: lbm_defines.h:459
lbm_dec_array_rw
lbm_array_header_t * lbm_dec_array_rw(lbm_value val)
Definition: heap.c:254
lbm_stack_t
Definition: stack.h:33
lbm_is_special
static bool lbm_is_special(lbm_value symrep)
Definition: heap.h:908
lbm_const_heap_t
Definition: heap.h:235
lbm_list_destructive_reverse
lbm_value lbm_list_destructive_reverse(lbm_value list)
Definition: heap.c:1125
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)
Definition: heap.c:1406
lbm_dec_u64
uint64_t lbm_dec_u64(lbm_value x)
Definition: heap.c:211
lbm_const_heap_t::next
lbm_uint next
Definition: heap.h:237
lbm_heap_state_t::heap
lbm_cons_t * heap
Definition: heap.h:212
LBM_ADDRESS_SHIFT
#define LBM_ADDRESS_SHIFT
Definition: lbm_defines.h:28
ENC_SYM_EVAL
#define ENC_SYM_EVAL
Definition: lbm_defines.h:505
lbm_is_array_r
static bool lbm_is_array_r(lbm_value x)
Definition: heap.h:878
lbm_index_list
lbm_value lbm_index_list(lbm_value l, int32_t n)
Definition: heap.c:1195
lbm_heap_state_t::gc_recovered
lbm_uint gc_recovered
Definition: heap.h:224
lbm_array_header_extended_t
Definition: heap.h:251
lbm_enc_u
static lbm_value lbm_enc_u(lbm_uint x)
Definition: heap.h:726
lbm_caar
lbm_value lbm_caar(lbm_value c)
Definition: heap.c:1006
LBM_PTR_TO_CONSTANT_BIT
#define LBM_PTR_TO_CONSTANT_BIT
Definition: lbm_defines.h:38
lbm_enc_sym
static lbm_value lbm_enc_sym(lbm_uint s)
Definition: heap.h:718
lbm_is_closure
static bool lbm_is_closure(lbm_value exp)
Definition: heap.h:913
lbm_char_channel_s
Definition: lbm_channel.h:69
lbm_heap_allocate_array
int lbm_heap_allocate_array(lbm_value *res, lbm_uint size)
Definition: heap.c:1269
lbm_is_match_binder
static bool lbm_is_match_binder(lbm_value exp)
Definition: heap.h:931
ENC_SYM_TRUE
#define ENC_SYM_TRUE
Definition: lbm_defines.h:404
ENC_SYM_CLOSURE
#define ENC_SYM_CLOSURE
Definition: lbm_defines.h:489
lbm_array_header_t::size
lbm_uint size
Definition: heap.h:247
lbm_gc_mark_phase
void lbm_gc_mark_phase(lbm_value root)
Definition: heap.c:801
lbm_get_heap_state
void lbm_get_heap_state(lbm_heap_state_t *)
Definition: heap.c:677
write_const_car
lbm_flash_status write_const_car(lbm_value cell, lbm_value val)
Definition: heap.c:1508
LBM_PTR_TO_CONSTANT_MASK
#define LBM_PTR_TO_CONSTANT_MASK
Definition: lbm_defines.h:39
lbm_type_of_functional
static lbm_type lbm_type_of_functional(lbm_value x)
Definition: heap.h:688
lbm_list_length
lbm_uint lbm_list_length(lbm_value c)
Definition: heap.c:1080
lbm_allocate_const_cell
lbm_flash_status lbm_allocate_const_cell(lbm_value *res)
Definition: heap.c:1435
lbm_array_header_t::data
lbm_uint * data
Number of elements.
Definition: heap.h:248
lbm_heap_size_bytes
lbm_uint lbm_heap_size_bytes(void)
Definition: heap.c:673
lbm_heap_explicit_free_array
int lbm_heap_explicit_free_array(lbm_value arr)
Definition: heap.c:1353
lbm_dec_char
static uint8_t lbm_dec_char(lbm_value x)
Definition: heap.h:778
lbm_heaps
lbm_cons_t * lbm_heaps[2]
Definition: heap.c:69
lbm_is_number
static bool lbm_is_number(lbm_value x)
Definition: heap.h:862
lbm_heap_state_t::gc_stack
lbm_stack_t gc_stack
Definition: heap.h:214
lbm_gc_sweep_phase
int lbm_gc_sweep_phase(void)
Definition: heap.c:922
lbm_cons_t::car
lbm_value car
Definition: heap.h:204
lbm_get_gc_stack_max
lbm_uint lbm_get_gc_stack_max(void)
Definition: heap.c:681
lbm_dec_u
static lbm_uint lbm_dec_u(lbm_value x)
Definition: heap.h:774
lbm_size_of
lbm_uint lbm_size_of(lbm_type t)
Definition: heap.c:1373
lbm_array_header_extended_t::index
uint32_t index
Definition: heap.h:254
lbm_set_car
int lbm_set_car(lbm_value c, lbm_value v)
Definition: heap.c:1047
lbm_dec_heap
static lbm_cons_t * lbm_dec_heap(lbm_value p)
Definition: heap.h:709
lbm_heap_array_get_data_rw
uint8_t * lbm_heap_array_get_data_rw(lbm_value arr)
Definition: heap.c:1326
lbm_is_lisp_array_rw
static bool lbm_is_lisp_array_rw(lbm_value x)
Definition: heap.h:894
LBM_FLASH_WRITE_OK
@ LBM_FLASH_WRITE_OK
Definition: heap.h:195
lbm_set_ptr_type
static lbm_value lbm_set_ptr_type(lbm_value p, lbm_type t)
Definition: heap.h:714
lbm_is_ptr
static bool lbm_is_ptr(lbm_value x)
Definition: heap.h:832
LBM_TYPE_ARRAY
#define LBM_TYPE_ARRAY
Definition: lbm_defines.h:52
lbm_cons
lbm_value lbm_cons(lbm_value car, lbm_value cdr)
Definition: heap.c:990
lbm_dec_as_i64
int64_t lbm_dec_as_i64(lbm_value val)
Definition: heap.c:369
lbm_flash_status
lbm_flash_status
Definition: heap.h:194
lbm_heap_state_t::freelist
lbm_value freelist
Definition: heap.h:213
LBM_VAL_SHIFT
#define LBM_VAL_SHIFT
Definition: lbm_defines.h:29
lbm_heap_state_t::gc_least_free
lbm_uint gc_least_free
Definition: heap.h:226
ENC_SYM_MACRO
#define ENC_SYM_MACRO
Definition: lbm_defines.h:487
lbm_enc_cons_ptr
static lbm_value lbm_enc_cons_ptr(lbm_uint x)
Definition: heap.h:694
lbm_heap_init
int lbm_heap_init(lbm_cons_t *addr, lbm_uint num_cells, lbm_uint gc_stack_size)
Definition: heap.c:575
LBM_TYPE_I
#define LBM_TYPE_I
Definition: lbm_defines.h:80
lbm_enc_u64
lbm_value lbm_enc_u64(uint64_t x)
Definition: heap.c:155
lbm_dec_lisp_array_r
lbm_array_header_t * lbm_dec_lisp_array_r(lbm_value val)
Definition: heap.c:262
symrepr.h
lbm_dec_i32
static int32_t lbm_dec_i32(lbm_value x)
Definition: heap.h:813
lbm_heap_num_allocated
lbm_uint lbm_heap_num_allocated(void)
Definition: heap.c:666
lbm_types.h
lbm_list_copy
lbm_value lbm_list_copy(int *m, lbm_value list)
Definition: heap.c:1142
lbm_dec_i
static lbm_int lbm_dec_i(lbm_value x)
Definition: heap.h:770
lbm_heap_state_t::num_alloc_arrays
lbm_uint num_alloc_arrays
Definition: heap.h:220
lbm_heap_state_t::gc_recovered_arrays
lbm_uint gc_recovered_arrays
Definition: heap.h:225
lbm_cons_t
Definition: heap.h:203
lbm_heap_state_t
Definition: heap.h:211
lbm_heap_allocate_list_init
lbm_value lbm_heap_allocate_list_init(unsigned int n,...)
Definition: heap.c:658
lbm_dec_channel
lbm_char_channel_t * lbm_dec_channel(lbm_value val)
Definition: heap.c:278
LBM_TYPE_LISPARRAY
#define LBM_TYPE_LISPARRAY
Definition: lbm_defines.h:56
lbm_gc_unlock
void lbm_gc_unlock(void)
Definition: heap.c:87
lbm_heap_allocate_list_init_va
lbm_value lbm_heap_allocate_list_init_va(unsigned int n, va_list valist)
Definition: heap.c:634
lbm_dec_u32
static uint32_t lbm_dec_u32(lbm_value x)
Definition: heap.h:799
lbm_heap_state_t::gc_last_free
lbm_uint gc_last_free
Definition: heap.h:227
lbm_const_heap_t::heap
lbm_uint * heap
Definition: heap.h:236
lbm_set_cdr
int lbm_set_cdr(lbm_value c, lbm_value v)
Definition: heap.c:1058
lbm_heap_new_freelist_length
void lbm_heap_new_freelist_length(void)
Definition: heap.c:568
LBM_PTR_TO_CONSTANT_SHIFT
#define LBM_PTR_TO_CONSTANT_SHIFT
Definition: lbm_defines.h:40
lbm_gc_mark_roots
void lbm_gc_mark_roots(lbm_uint *roots, lbm_uint num_roots)
Definition: heap.c:915
lbm_type_of
static lbm_type lbm_type_of(lbm_value x)
Definition: heap.h:683
lbm_heap_state_t::gc_marked
lbm_uint gc_marked
Definition: heap.h:223
lbm_dec_as_u64
uint64_t lbm_dec_as_u64(lbm_value val)
Definition: heap.c:394
lbm_value
uint32_t lbm_value
Definition: lbm_types.h:44
lbm_int
int32_t lbm_int
Definition: lbm_types.h:49
ENC_SYM_MATCH_ANY
#define ENC_SYM_MATCH_ANY
Definition: lbm_defines.h:436
lbm_is_symbol_true
static bool lbm_is_symbol_true(lbm_value exp)
Definition: heap.h:948
LBM_VAL_TYPE_MASK
#define LBM_VAL_TYPE_MASK
Definition: lbm_defines.h:72
LBM_PTR_VAL_MASK
#define LBM_PTR_VAL_MASK
Definition: lbm_defines.h:33
LBM_TYPE_CONS
#define LBM_TYPE_CONS
Definition: lbm_defines.h:43
lbm_gc_lock
void lbm_gc_lock(void)
Definition: heap.c:85
ENC_SYM_MERROR
#define ENC_SYM_MERROR
Definition: lbm_defines.h:411
lbm_enc_i32
lbm_value lbm_enc_i32(int32_t x)
Definition: heap.c:94
LBM_TYPE_CHAR
#define LBM_TYPE_CHAR
Definition: lbm_defines.h:78
LBM_TYPE_U
#define LBM_TYPE_U
Definition: lbm_defines.h:81
lbm_list_reverse
lbm_value lbm_list_reverse(lbm_value list)
Definition: heap.c:1106
lbm_is_array_rw
static bool lbm_is_array_rw(lbm_value x)
Definition: heap.h:883
lbm_dec_as_uint
lbm_uint lbm_dec_as_uint(lbm_value val)
Definition: heap.c:419
lbm_is_symbol
static bool lbm_is_symbol(lbm_value exp)
Definition: heap.h:944
LBM_CONS_TYPE_MASK
#define LBM_CONS_TYPE_MASK
Definition: lbm_defines.h:62
lbm_dec_raw
lbm_uint lbm_dec_raw(lbm_value v)
lbm_dec_as_char
uint8_t lbm_dec_as_char(lbm_value a)
Definition: heap.c:295
lbm_enc_float
lbm_value lbm_enc_float(float x)
Definition: heap.c:114
lbm_enc_i64
lbm_value lbm_enc_i64(int64_t x)
Definition: heap.c:145
lbm_get_gc_stack_size
lbm_uint lbm_get_gc_stack_size(void)
Definition: heap.c:685
lbm_is_list_rw
static bool lbm_is_list_rw(lbm_value x)
Definition: heap.h:964
lbm_is_list
static bool lbm_is_list(lbm_value x)
Definition: heap.h:960
lbm_dec_float
float lbm_dec_float(lbm_value x)
Definition: heap.c:181
lbm_heap_allocate_cell
lbm_value lbm_heap_allocate_cell(lbm_type ptr_type, lbm_value car, lbm_value cdr)
Definition: heap.c:594
lbm_dec_lisp_array_rw
lbm_array_header_t * lbm_dec_lisp_array_rw(lbm_value val)
Definition: heap.c:270
lbm_dec_custom
lbm_uint lbm_dec_custom(lbm_value val)
Definition: heap.c:287
lbm_is_cons
static bool lbm_is_cons(lbm_value x)
Definition: heap.h:850
lbm_type
uint32_t lbm_type
Definition: lbm_types.h:46
lbm_dec_cons_cell_ptr
static lbm_uint lbm_dec_cons_cell_ptr(lbm_value p)
Definition: heap.h:704
lbm_heap_array_get_size
lbm_int lbm_heap_array_get_size(lbm_value arr)
Definition: heap.c:1307
lbm_is_symbol_eval
static bool lbm_is_symbol_eval(lbm_value exp)
Definition: heap.h:952
lbm_memory.h
lbm_cddr
lbm_value lbm_cddr(lbm_value c)
Definition: heap.c:1037
stack.h
lbm_lift_array
int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt)
Definition: heap.c:1279
write_const_cdr
lbm_flash_status write_const_cdr(lbm_value cell, lbm_value val)
Definition: heap.c:1501
lbm_is_char
static bool lbm_is_char(lbm_value x)
Definition: heap.h:904