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);
357 uint8_t lbm_dec_as_char(lbm_value a);
363 uint32_t lbm_dec_as_u32(lbm_value val);
369 int32_t lbm_dec_as_i32(lbm_value val);
375 float lbm_dec_as_float(lbm_value val);
381 uint64_t lbm_dec_as_u64(lbm_value val);
387 int64_t lbm_dec_as_i64(lbm_value val);
393 double lbm_dec_as_double(lbm_value val);
394 
401 
408 
418 
476 int lbm_set_car_and_cdr(lbm_value c, lbm_value car_val, lbm_value cdr_val);
477 // List functions
486 
495 unsigned int lbm_list_length_pred(lbm_value c, bool *pres, bool (*pred)(lbm_value));
520 lbm_value lbm_list_copy(int *m, lbm_value list);
521 
529 
535 lbm_value lbm_list_drop(unsigned int n, lbm_value ls);
541 lbm_value lbm_index_list(lbm_value l, int32_t n);
542 
543 // State and statistics
558 // Garbage collection
562 void lbm_gc_state_inc(void);
566 void lbm_nil_freelist(void);
574 void lbm_gc_mark_phase(lbm_value root);
582 void lbm_gc_mark_aux(lbm_uint *data, lbm_uint n);
587 void lbm_gc_mark_roots(lbm_uint *roots, lbm_uint num_roots);
592 int lbm_gc_sweep_phase(void);
593 
594 // Array functionality
617 int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt);
627 const uint8_t *lbm_heap_array_get_data_ro(lbm_value arr);
638 
644 
646  lbm_const_heap_t *heap,
647  lbm_uint *addr,
648  lbm_uint num_words);
649 
657 
663 static inline lbm_type lbm_type_of(lbm_value x) {
664  return (x & LBM_PTR_BIT) ? (x & LBM_PTR_TYPE_MASK) : (x & LBM_VAL_TYPE_MASK);
665 }
666 
667 // type-of check that is safe in functional code
669  return (x & LBM_PTR_BIT) ?
671  (x & LBM_VAL_TYPE_MASK);
672 }
673 
675  return ((x << LBM_ADDRESS_SHIFT) | LBM_TYPE_CONS | LBM_PTR_BIT);
676 }
677 
678 static inline lbm_uint lbm_dec_ptr(lbm_value p) {
679  return ((LBM_PTR_VAL_MASK & p) >> LBM_ADDRESS_SHIFT);
680 }
681 
682 extern lbm_cons_t *lbm_heaps[2];
683 
686  return lbm_dec_ptr(p) >> h;
687 }
688 
689 static inline lbm_cons_t *lbm_dec_heap(lbm_value p) {
691  return lbm_heaps[h];
692 }
693 
695  return ((LBM_PTR_VAL_MASK & p) | t | LBM_PTR_BIT);
696 }
697 
698 static inline lbm_value lbm_enc_sym(lbm_uint s) {
699  return (s << LBM_VAL_SHIFT) | LBM_TYPE_SYMBOL;
700 }
701 
702 static inline lbm_value lbm_enc_i(lbm_int x) {
703  return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_I;
704 }
705 
706 static inline lbm_value lbm_enc_u(lbm_uint x) {
707  return (x << LBM_VAL_SHIFT) | LBM_TYPE_U;
708 }
709 
714 extern lbm_value lbm_enc_i32(int32_t x);
715 
720 extern lbm_value lbm_enc_u32(uint32_t x);
721 
726 extern lbm_value lbm_enc_float(float x);
727 
732 extern lbm_value lbm_enc_i64(int64_t x);
733 
738 extern lbm_value lbm_enc_u64(uint64_t x);
739 
744 extern lbm_value lbm_enc_double(double x);
745 
746 static inline lbm_value lbm_enc_char(uint8_t x) {
747  return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_CHAR;
748 }
749 
750 static inline lbm_int lbm_dec_i(lbm_value x) {
751  return (lbm_int)x >> LBM_VAL_SHIFT;
752 }
753 
754 static inline lbm_uint lbm_dec_u(lbm_value x) {
755  return x >> LBM_VAL_SHIFT;
756 }
757 
758 static inline uint8_t lbm_dec_char(lbm_value x) {
759  return (uint8_t)(x >> LBM_VAL_SHIFT);
760 }
761 
762 static inline lbm_uint lbm_dec_sym(lbm_value x) {
763  return x >> LBM_VAL_SHIFT;
764 }
765 
770 extern float lbm_dec_float(lbm_value x);
771 
776 extern double lbm_dec_double(lbm_value x);
777 
778 
779 static inline uint32_t lbm_dec_u32(lbm_value x) {
780 #ifndef LBM64
781  return (uint32_t)lbm_car(x);
782 #else
783  return (uint32_t)(x >> LBM_VAL_SHIFT);
784 #endif
785 }
786 
791 extern uint64_t lbm_dec_u64(lbm_value x);
792 
793 static inline int32_t lbm_dec_i32(lbm_value x) {
794 #ifndef LBM64
795  return (int32_t)lbm_car(x);
796 #else
797  return (int32_t)(x >> LBM_VAL_SHIFT);
798 #endif
799 }
800 
805 extern int64_t lbm_dec_i64(lbm_value x);
806 
812 static inline bool lbm_is_ptr(lbm_value x) {
813  return (x & LBM_PTR_BIT);
814 }
815 
821 static inline bool lbm_is_cons_rw(lbm_value x) {
822  return (lbm_type_of(x) == LBM_TYPE_CONS);
823 }
824 
830 static inline bool lbm_is_cons(lbm_value x) {
831  return lbm_is_ptr(x) && ((x & LBM_CONS_TYPE_MASK) == LBM_TYPE_CONS);
832 }
833 
834 static inline bool lbm_is_symbol_nil(lbm_value exp) {
835  return !exp;
836 }
837 
842 static inline bool lbm_is_number(lbm_value x) {
843  return
844  (x & LBM_PTR_BIT) ?
845  ((x & LBM_NUMBER_MASK) == LBM_NUMBER_MASK) :
846  (x & LBM_VAL_TYPE_MASK);
847 }
848 
849 // Check if an array is valid (an invalid array has been freed by someone explicitly)
850 static inline bool lbm_heap_array_valid(lbm_value arr) {
851  return !(lbm_is_symbol_nil(lbm_car(arr))); // this is an is_zero check similar to (a == NULL)
852 }
853 
858 static inline bool lbm_is_array_r(lbm_value x) {
859  lbm_type t = lbm_type_of(x);
861 }
862 
863 static inline bool lbm_is_array_rw(lbm_value x) {
864  return ((lbm_type_of(x) == LBM_TYPE_ARRAY) &&
865  !(x & LBM_PTR_TO_CONSTANT_BIT) &&
867 }
868 
869 static inline bool lbm_is_lisp_array_r(lbm_value x) {
870  lbm_type t = lbm_type_of(x);
872 }
873 
874 static inline bool lbm_is_lisp_array_rw(lbm_value x) {
875  return( (lbm_type_of(x) == LBM_TYPE_LISPARRAY) && !(x & LBM_PTR_TO_CONSTANT_BIT));
876 }
877 
878 
879 static inline bool lbm_is_channel(lbm_value x) {
880  return (lbm_type_of(x) == LBM_TYPE_CHANNEL &&
883 }
884 static inline bool lbm_is_char(lbm_value x) {
885  return (lbm_type_of(x) == LBM_TYPE_CHAR);
886 }
887 
888 static inline bool lbm_is_special(lbm_value symrep) {
889  return ((lbm_type_of(symrep) == LBM_TYPE_SYMBOL) &&
890  (lbm_dec_sym(symrep) < SPECIAL_SYMBOLS_END));
891 }
892 
893 static inline bool lbm_is_closure(lbm_value exp) {
894  return ((lbm_is_cons(exp)) &&
895  (lbm_type_of(lbm_car(exp)) == LBM_TYPE_SYMBOL) &&
896  (lbm_car(exp) == ENC_SYM_CLOSURE));
897 }
898 
899 static inline bool lbm_is_continuation(lbm_value exp) {
900  return ((lbm_type_of(exp) == LBM_TYPE_CONS) &&
901  (lbm_type_of(lbm_car(exp)) == LBM_TYPE_SYMBOL) &&
902  (lbm_car(exp) == ENC_SYM_CONT));
903 }
904 
905 static inline bool lbm_is_macro(lbm_value exp) {
906  return ((lbm_type_of(exp) == LBM_TYPE_CONS) &&
907  (lbm_type_of(lbm_car(exp)) == LBM_TYPE_SYMBOL) &&
908  (lbm_car(exp) == ENC_SYM_MACRO));
909 }
910 
911 static inline bool lbm_is_match_binder(lbm_value exp) {
912  return (lbm_is_cons(exp) &&
913  (lbm_type_of(lbm_car(exp)) == LBM_TYPE_SYMBOL) &&
914  (lbm_car(exp) == ENC_SYM_MATCH_ANY));
915 }
916 
917 static inline bool lbm_is_comma_qualified_symbol(lbm_value exp) {
918  return (lbm_is_cons(exp) &&
919  (lbm_type_of(lbm_car(exp)) == LBM_TYPE_SYMBOL) &&
920  (lbm_car(exp) == ENC_SYM_COMMA) &&
922 }
923 
924 static inline bool lbm_is_symbol(lbm_value exp) {
925  return !(exp & LBM_LOW_RESERVED_BITS);
926 }
927 
928 static inline bool lbm_is_symbol_true(lbm_value exp) {
929  return (lbm_is_symbol(exp) && exp == ENC_SYM_TRUE);
930 }
931 
932 static inline bool lbm_is_symbol_eval(lbm_value exp) {
933  return (lbm_is_symbol(exp) && exp == ENC_SYM_EVAL);
934 }
935 
936 static inline bool lbm_is_symbol_merror(lbm_value exp) {
937  return lbm_is_symbol(exp) && (exp == ENC_SYM_MERROR);
938 }
939 
940 static inline bool lbm_is_list(lbm_value x) {
941  return (lbm_is_cons(x) || lbm_is_symbol_nil(x));
942 }
943 
944 static inline bool lbm_is_list_rw(lbm_value x) {
945  return (lbm_is_cons_rw(x) || lbm_is_symbol_nil(x));
946 }
947 
948 static inline bool lbm_is_quoted_list(lbm_value x) {
949  return (lbm_is_cons(x) &&
950  lbm_is_symbol(lbm_car(x)) &&
951  (lbm_car(x) == ENC_SYM_QUOTE) &&
952  lbm_is_cons(lbm_cdr(x)) &&
953  lbm_is_cons(lbm_cadr(x)));
954 }
955 
956 #ifndef LBM64
957 #define ERROR_SYMBOL_MASK 0xFFFFFFF0
958 #else
959 #define ERROR_SYMBOL_MASK 0xFFFFFFFFFFFFFFF0
960 #endif
961 
962 /* all error signaling symbols are in the range 0x20 - 0x2F */
963 static inline bool lbm_is_error(lbm_value v){
964  return (lbm_is_symbol(v) &&
965  ((lbm_dec_sym(v) & ERROR_SYMBOL_MASK) == 0x20));
966 }
967 
968 // ref_cell: returns a reference to the cell addressed by bits 3 - 26
969 // Assumes user has checked that is_ptr was set
970 static inline lbm_cons_t* lbm_ref_cell(lbm_value addr) {
971  return &lbm_dec_heap(addr)[lbm_dec_cons_cell_ptr(addr)];
972  //return &lbm_heap_state.heap[lbm_dec_ptr(addr)];
973 }
974 
975 
976 // lbm_uint a = lbm_heaps[0];
977 // lbm_uint b = lbm_heaps[1];
978 // lbm_uint i = (addr & LBM_PTR_TO_CONSTANT_BIT) >> LBM_PTR_TO_CONSTANT_SHIFT) - 1;
979 // lbm_uint h = (a & i) | (b & ~i);
980 
981 #ifdef __cplusplus
982 }
983 #endif
984 #endif
lbm_enc_i
static lbm_value lbm_enc_i(lbm_int x)
Definition: heap.h:702
ERROR_SYMBOL_MASK
#define ERROR_SYMBOL_MASK
Definition: heap.h:957
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:746
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:902
LBM_PTR_BIT
#define LBM_PTR_BIT
Definition: lbm_defines.h:32
SPECIAL_SYMBOLS_END
#define SPECIAL_SYMBOLS_END
Definition: lbm_defines.h:375
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:891
lbm_allocate_const_raw
lbm_flash_status lbm_allocate_const_raw(lbm_uint nwords, lbm_uint *res)
Definition: heap.c:1401
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:1103
lbm_defines.h
lbm_dec_ptr
static lbm_uint lbm_dec_ptr(lbm_value p)
Definition: heap.h:678
ENC_SYM_CONT
#define ENC_SYM_CONT
Definition: lbm_defines.h:474
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:879
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:460
lbm_ref_cell
static lbm_cons_t * lbm_ref_cell(lbm_value addr)
Definition: heap.h:970
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:1002
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:899
lbm_dec_as_int
lbm_int lbm_dec_as_int(lbm_value val)
Definition: heap.c:407
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:81
lbm_is_quoted_list
static bool lbm_is_quoted_list(lbm_value x)
Definition: heap.h:948
lbm_dec_as_i32
int32_t lbm_dec_as_i32(lbm_value val)
Definition: heap.c:307
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:790
lbm_const_write
lbm_flash_status lbm_const_write(lbm_uint *tgt, lbm_uint val)
Definition: heap.c:1433
lbm_dec_sym
static lbm_uint lbm_dec_sym(lbm_value x)
Definition: heap.h:762
lbm_is_macro
static bool lbm_is_macro(lbm_value exp)
Definition: heap.h:905
lbm_is_cons_rw
static bool lbm_is_cons_rw(lbm_value x)
Definition: heap.h:821
lbm_is_lisp_array_r
static bool lbm_is_lisp_array_r(lbm_value x)
Definition: heap.h:869
lbm_list_length_pred
unsigned int lbm_list_length_pred(lbm_value c, bool *pres, bool(*pred)(lbm_value))
Definition: heap.c:1026
ENC_SYM_CHANNEL_TYPE
#define ENC_SYM_CHANNEL_TYPE
Definition: lbm_defines.h:416
lbm_cadr
lbm_value lbm_cadr(lbm_value c)
Definition: heap.c:939
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:76
lbm_heap_array_valid
static bool lbm_heap_array_valid(lbm_value arr)
Definition: heap.h:850
lbm_list_drop
lbm_value lbm_list_drop(unsigned int n, lbm_value ls)
Definition: heap.c:1119
lbm_dec_as_u32
uint32_t lbm_dec_as_u32(lbm_value val)
Definition: heap.c:283
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:220
lbm_is_symbol_nil
static bool lbm_is_symbol_nil(lbm_value exp)
Definition: heap.h:834
lbm_dec_as_double
double lbm_dec_as_double(lbm_value val)
Definition: heap.c:457
lbm_cdr
lbm_value lbm_cdr(lbm_value cons)
Definition: heap.c:957
lbm_channel.h
lbm_heap_allocate_lisp_array
int lbm_heap_allocate_lisp_array(lbm_value *res, lbm_uint size)
Definition: heap.c:1215
lbm_heap_allocate_list
lbm_value lbm_heap_allocate_list(lbm_uint n)
Definition: heap.c:573
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:806
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:936
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:1262
lbm_dec_str
char * lbm_dec_str(lbm_value val)
Definition: heap.c:231
lbm_is_error
static bool lbm_is_error(lbm_value v)
Definition: heap.h:963
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:1460
lbm_is_comma_qualified_symbol
static bool lbm_is_comma_qualified_symbol(lbm_value exp)
Definition: heap.h:917
lbm_heap_size
lbm_uint lbm_heap_size(void)
Definition: heap.c:632
lbm_write_const_raw
lbm_flash_status lbm_write_const_raw(lbm_uint *data, lbm_uint n, lbm_uint *res)
Definition: heap.c:1414
lbm_array_header_t
Definition: heap.h:246
lbm_dec_as_float
float lbm_dec_as_float(lbm_value val)
Definition: heap.c:432
lbm_nil_freelist
void lbm_nil_freelist(void)
Definition: heap.c:508
ENC_SYM_COMMA
#define ENC_SYM_COMMA
Definition: lbm_defines.h:447
lbm_stack_t
Definition: stack.h:33
lbm_is_special
static bool lbm_is_special(lbm_value symrep)
Definition: heap.h:888
lbm_const_heap_t
Definition: heap.h:235
lbm_list_destructive_reverse
lbm_value lbm_list_destructive_reverse(lbm_value list)
Definition: heap.c:1059
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:1351
lbm_dec_u64
uint64_t lbm_dec_u64(lbm_value x)
Definition: heap.c:209
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:491
lbm_is_array_r
static bool lbm_is_array_r(lbm_value x)
Definition: heap.h:858
lbm_index_list
lbm_value lbm_index_list(lbm_value l, int32_t n)
Definition: heap.c:1129
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:706
lbm_caar
lbm_value lbm_caar(lbm_value c)
Definition: heap.c:920
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:698
lbm_is_closure
static bool lbm_is_closure(lbm_value exp)
Definition: heap.h:893
lbm_char_channel_s
Definition: lbm_channel.h:68
lbm_heap_allocate_array
int lbm_heap_allocate_array(lbm_value *res, lbm_uint size)
Definition: heap.c:1211
lbm_is_match_binder
static bool lbm_is_match_binder(lbm_value exp)
Definition: heap.h:911
ENC_SYM_TRUE
#define ENC_SYM_TRUE
Definition: lbm_defines.h:394
ENC_SYM_CLOSURE
#define ENC_SYM_CLOSURE
Definition: lbm_defines.h:475
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:716
lbm_get_heap_state
void lbm_get_heap_state(lbm_heap_state_t *)
Definition: heap.c:640
write_const_car
lbm_flash_status write_const_car(lbm_value cell, lbm_value val)
Definition: heap.c:1453
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:668
lbm_list_length
lbm_uint lbm_list_length(lbm_value c)
Definition: heap.c:1014
lbm_allocate_const_cell
lbm_flash_status lbm_allocate_const_cell(lbm_value *res)
Definition: heap.c:1380
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:636
lbm_heap_explicit_free_array
int lbm_heap_explicit_free_array(lbm_value arr)
Definition: heap.c:1298
lbm_dec_char
static uint8_t lbm_dec_char(lbm_value x)
Definition: heap.h:758
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:842
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:827
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:644
lbm_dec_u
static lbm_uint lbm_dec_u(lbm_value x)
Definition: heap.h:754
lbm_size_of
lbm_uint lbm_size_of(lbm_type t)
Definition: heap.c:1318
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:981
lbm_dec_heap
static lbm_cons_t * lbm_dec_heap(lbm_value p)
Definition: heap.h:689
lbm_heap_array_get_data_rw
uint8_t * lbm_heap_array_get_data_rw(lbm_value arr)
Definition: heap.c:1271
lbm_is_lisp_array_rw
static bool lbm_is_lisp_array_rw(lbm_value x)
Definition: heap.h:874
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:694
lbm_is_ptr
static bool lbm_is_ptr(lbm_value x)
Definition: heap.h:812
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:898
lbm_dec_as_i64
int64_t lbm_dec_as_i64(lbm_value val)
Definition: heap.c:332
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:473
lbm_enc_cons_ptr
static lbm_value lbm_enc_cons_ptr(lbm_uint x)
Definition: heap.h:674
lbm_heap_init
int lbm_heap_init(lbm_cons_t *addr, lbm_uint num_cells, lbm_uint gc_stack_size)
Definition: heap.c:538
LBM_TYPE_I
#define LBM_TYPE_I
Definition: lbm_defines.h:79
lbm_enc_u64
lbm_value lbm_enc_u64(uint64_t x)
Definition: heap.c:155
symrepr.h
lbm_dec_i32
static int32_t lbm_dec_i32(lbm_value x)
Definition: heap.h:793
lbm_heap_num_allocated
lbm_uint lbm_heap_num_allocated(void)
Definition: heap.c:629
lbm_types.h
lbm_list_copy
lbm_value lbm_list_copy(int *m, lbm_value list)
Definition: heap.c:1076
lbm_dec_i
static lbm_int lbm_dec_i(lbm_value x)
Definition: heap.h:750
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:621
lbm_dec_channel
lbm_char_channel_t * lbm_dec_channel(lbm_value val)
Definition: heap.c:241
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:597
lbm_dec_u32
static uint32_t lbm_dec_u32(lbm_value x)
Definition: heap.h:779
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:992
lbm_heap_new_freelist_length
void lbm_heap_new_freelist_length(void)
Definition: heap.c:531
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:820
lbm_type_of
static lbm_type lbm_type_of(lbm_value x)
Definition: heap.h:663
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:357
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:424
lbm_is_symbol_true
static bool lbm_is_symbol_true(lbm_value exp)
Definition: heap.h:928
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:401
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:77
LBM_TYPE_U
#define LBM_TYPE_U
Definition: lbm_defines.h:80
lbm_list_reverse
lbm_value lbm_list_reverse(lbm_value list)
Definition: heap.c:1040
lbm_is_array_rw
static bool lbm_is_array_rw(lbm_value x)
Definition: heap.h:863
lbm_dec_as_uint
lbm_uint lbm_dec_as_uint(lbm_value val)
Definition: heap.c:382
lbm_is_symbol
static bool lbm_is_symbol(lbm_value exp)
Definition: heap.h:924
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:258
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:648
lbm_is_list_rw
static bool lbm_is_list_rw(lbm_value x)
Definition: heap.h:944
lbm_is_list
static bool lbm_is_list(lbm_value x)
Definition: heap.h:940
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:557
lbm_dec_custom
lbm_uint lbm_dec_custom(lbm_value val)
Definition: heap.c:250
lbm_is_cons
static bool lbm_is_cons(lbm_value x)
Definition: heap.h:830
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:684
lbm_heap_array_get_size
lbm_int lbm_heap_array_get_size(lbm_value arr)
Definition: heap.c:1249
lbm_is_symbol_eval
static bool lbm_is_symbol_eval(lbm_value exp)
Definition: heap.h:932
lbm_memory.h
lbm_cddr
lbm_value lbm_cddr(lbm_value c)
Definition: heap.c:968
stack.h
lbm_lift_array
int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt)
Definition: heap.c:1221
write_const_cdr
lbm_flash_status write_const_cdr(lbm_value cell, lbm_value val)
Definition: heap.c:1446
lbm_is_char
static bool lbm_is_char(lbm_value x)
Definition: heap.h:884