LispBM
Loading...
Searching...
No Matches
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
33extern "C" {
34#endif
35
36/*
37Planning for a more space efficient heap representation.
38TODO: Need to find a good reference to read up on this.
39 - List based heap
40 - Easy to implement and somewhat efficient
41
420000 0000 Size Free bits
43003F FFFF 4MB 10
44007F FFFF 8MB 9
4500FF FFFF 16MB 8
4601FF FFFF 32MB 7
4703FF FFFF 64MB 6 * Kind of heap size I am looking for
4807FF FFFF 128MB 5
490FFF FFFF 256MB 4
501FFF FFFF 512MB 3
51
52
53--- May 9 2021 ---
54Actually now I am much more interested in way smaller memories ;)
55
560000 0000 Size Free bits
570000 0FFF 4KB 20 |
580000 1FFF 8KB 19 |
590000 3FFF 16KB 18 |
600000 7FFF 32KB 17 |
610000 FFFF 64KB 16 |
620001 FFFF 128KB 15 |
630003 FFFF 256KB 14 | - This range is very interesting.
640007 FFFF 512KB 13
65000F FFFF 1MB 12
66001F FFFF 2MB 11
67003F FFFF 4MB 10
68007F FFFF 8MB 9
6900FF FFFF 16MB 8
7001FF FFFF 32MB 7
7103FF FFFF 64MB 6
7207FF FFFF 128MB 5
730FFF FFFF 256MB 4
741FFF FFFF 512MB 3
75
76Those are the kind of platforms that are fun... so a bunch of
77wasted bits in heap pointers if we run on small MCUs.
78
79-----------------
80
81it is also the case that not all addresses will be used if all "cells" are
82of the same size, 8 bytes...
83
84value 0: 0000 0000
85value 1: 0000 0008
86value 3: 0000 0010
87value 4: 0000 0018
88
89Means bits 0,1,2 will always be empty in a valid address.
90
91Cons cells also need to be have room for 2 pointers. So each ted cell from
92memory should be 8bytes.
93
94Things 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
99Types I would want:
100 - Full 32bit integer. Does not leave room for identification of type
101 - Float values. Same problem
102
103
104Free bits in pointers 64MB heap:
10531 30 29 28 27 26 2 1 0
1060 0 0 0 0 0 XX XXXX XXXX XXXX XXXX XXXX X 0 0 0
107
108
109Information 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
116Types (unboxed):
117 - Symbols
118 - 28bit integer ( will need signed shift right functionality )
119 - 28bit unsigned integer
120 - Character
121
122If four types is all that should be possible (unboxed). then 2 bits are needed to differentiate.
1232 + 1 + 1 = 4 => 28bits for data.
124
125bit 0: ptr/!ptr
126bit 1: gc
127bit 2-3: type (if not ptr)
128bit 3 - 24 ptr (if ptr)
129bit 4 - 31 value (if value)
130
131An unboxed value can occupy a car or cdr field in a cons cell.
132
133types (boxed) extra information in pointer to cell can contain information
134 - 32 bit integer
135 - 32 bit unsigned integer
136 - 32 bit float
137
138boxed representation:
139 [ptr| cdr]
140 |
141 [Value | Aux + GC_MARK]
142
143Kinds 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
16113 pointer"types" -> needs 4 bits
162for 64MB heap there are 6 free bits. So with this scheme going to 128MB or 256MB heap
163is 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
173Aux 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
1900000 00XX XXXX XXXX XXXX XXXX XXXX X000 : 0x03FF FFF8
1911111 AA00 0000 0000 0000 0000 0000 0000 : 0xFC00 0000 (AA bits left unused for now, future heap growth?)
192 */
193
199
207
211typedef 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 w, lbm_uint ix);
234
235typedef struct {
237 lbm_uint next; // next free index.
238 lbm_uint size; // in lbm_uint words. (cons-cells = words / 2)
240
250
251typedef struct {
254 uint32_t index; // Limits arrays to max 2^32-1 elements.
256
261void lbm_gc_lock(void);
262/* Unlock GC mutex
263 */
264void lbm_gc_unlock(void);
265
272int lbm_heap_init(lbm_cons_t *addr, lbm_uint num_cells,
273 lbm_uint gc_stack_size);
274
292
327lbm_value lbm_heap_allocate_list_init_va(unsigned int n, va_list valist);
333lbm_value lbm_heap_allocate_list_init(unsigned int n, ...);
339char *lbm_dec_str(lbm_value val);
377uint8_t lbm_dec_as_char(lbm_value a);
383uint32_t lbm_dec_as_u32(lbm_value val);
389int32_t lbm_dec_as_i32(lbm_value val);
395float lbm_dec_as_float(lbm_value val);
401uint64_t lbm_dec_as_u64(lbm_value val);
407int64_t lbm_dec_as_i64(lbm_value val);
413double lbm_dec_as_double(lbm_value val);
414
421
428
438
496int lbm_set_car_and_cdr(lbm_value c, lbm_value car_val, lbm_value cdr_val);
497// List functions
506
515unsigned int lbm_list_length_pred(lbm_value c, bool *pres, bool (*pred)(lbm_value));
540lbm_value lbm_list_copy(int *m, lbm_value list);
541
549
555lbm_value lbm_list_drop(unsigned int n, lbm_value ls);
562
563// State and statistics
578// Garbage collection
582void lbm_gc_state_inc(void);
586void lbm_nil_freelist(void);
602void lbm_gc_mark_aux(lbm_uint *data, lbm_uint n);
607void lbm_gc_mark_roots(lbm_uint *roots, lbm_uint num_roots);
612int lbm_gc_sweep_phase(void);
613
614// Array functionality
637int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt);
647const uint8_t *lbm_heap_array_get_data_ro(lbm_value arr);
658
664
666 lbm_const_heap_t *heap,
667 lbm_uint *addr);
668
676
683 return (x & LBM_PTR_BIT) ? (x & LBM_PTR_TYPE_MASK) : (x & LBM_VAL_TYPE_MASK);
684}
685
686// type-of check that is safe in functional code
688 return (x & LBM_PTR_BIT) ?
690 (x & LBM_VAL_TYPE_MASK);
691}
692
694 return ((x << LBM_ADDRESS_SHIFT) | LBM_TYPE_CONS | LBM_PTR_BIT);
695}
696
698 return ((LBM_PTR_VAL_MASK & p) >> LBM_ADDRESS_SHIFT);
699}
700
701extern lbm_cons_t *lbm_heaps[2];
702
707
712
714 return ((LBM_PTR_VAL_MASK & p) | t | LBM_PTR_BIT);
715}
716
718 return (s << LBM_VAL_SHIFT) | LBM_TYPE_SYMBOL;
719}
720
721static inline lbm_value lbm_enc_i(lbm_int x) {
722 return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_I;
723}
724
725static inline lbm_value lbm_enc_u(lbm_uint x) {
726 return (x << LBM_VAL_SHIFT) | LBM_TYPE_U;
727}
728
733extern lbm_value lbm_enc_i32(int32_t x);
734
739extern lbm_value lbm_enc_u32(uint32_t x);
740
745extern lbm_value lbm_enc_float(float x);
746
751extern lbm_value lbm_enc_i64(int64_t x);
752
757extern lbm_value lbm_enc_u64(uint64_t x);
758
763extern lbm_value lbm_enc_double(double x);
764
765static inline lbm_value lbm_enc_char(uint8_t x) {
766 return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_CHAR;
767}
768
769static inline lbm_int lbm_dec_i(lbm_value x) {
770 return (lbm_int)x >> LBM_VAL_SHIFT;
771}
772
773static inline lbm_uint lbm_dec_u(lbm_value x) {
774 return x >> LBM_VAL_SHIFT;
775}
776
777static inline uint8_t lbm_dec_char(lbm_value x) {
778 return (uint8_t)(x >> LBM_VAL_SHIFT);
779}
780
782 return x >> LBM_VAL_SHIFT;
783}
784
789extern float lbm_dec_float(lbm_value x);
790
795extern double lbm_dec_double(lbm_value x);
796
797
798static inline uint32_t lbm_dec_u32(lbm_value x) {
799#ifndef LBM64
800 return (uint32_t)lbm_car(x);
801#else
802 return (uint32_t)(x >> LBM_VAL_SHIFT);
803#endif
804}
805
810extern uint64_t lbm_dec_u64(lbm_value x);
811
812static inline int32_t lbm_dec_i32(lbm_value x) {
813#ifndef LBM64
814 return (int32_t)lbm_car(x);
815#else
816 return (int32_t)(x >> LBM_VAL_SHIFT);
817#endif
818}
819
824extern int64_t lbm_dec_i64(lbm_value x);
825
831static inline bool lbm_is_ptr(lbm_value x) {
832 return (x & LBM_PTR_BIT);
833}
834
835static inline bool lbm_is_constant(lbm_value x) {
836 return ((x & LBM_PTR_BIT && x & LBM_PTR_TO_CONSTANT_BIT) ||
837 (!(x & LBM_PTR_BIT)));
838}
839
845static inline bool lbm_is_cons_rw(lbm_value x) {
846 return (lbm_type_of(x) == LBM_TYPE_CONS);
847}
848
854static inline bool lbm_is_cons(lbm_value x) {
855 return lbm_is_ptr(x) && ((x & LBM_CONS_TYPE_MASK) == LBM_TYPE_CONS);
856}
857
858static inline bool lbm_is_symbol_nil(lbm_value exp) {
859 return !exp;
860}
861
866static inline bool lbm_is_number(lbm_value x) {
867 return
868 (x & LBM_PTR_BIT) ?
870 (x & LBM_VAL_TYPE_MASK);
871}
872
873// Check if an array is valid (an invalid array has been freed by someone explicitly)
874static inline bool lbm_heap_array_valid(lbm_value arr) {
875 return !(lbm_is_symbol_nil(lbm_car(arr))); // this is an is_zero check similar to (a == NULL)
876}
877
882static inline bool lbm_is_array_r(lbm_value x) {
883 lbm_type t = lbm_type_of(x);
885}
886
887static inline bool lbm_is_array_rw(lbm_value x) {
888 return ((lbm_type_of(x) == LBM_TYPE_ARRAY) &&
891}
892
893static inline bool lbm_is_lisp_array_r(lbm_value x) {
894 lbm_type t = lbm_type_of(x);
896}
897
898static inline bool lbm_is_lisp_array_rw(lbm_value x) {
899 return( (lbm_type_of(x) == LBM_TYPE_LISPARRAY) && !(x & LBM_PTR_TO_CONSTANT_BIT));
900}
901
902
903static inline bool lbm_is_channel(lbm_value x) {
904 return (lbm_type_of(x) == LBM_TYPE_CHANNEL &&
907}
908static inline bool lbm_is_char(lbm_value x) {
909 return (lbm_type_of(x) == LBM_TYPE_CHAR);
910}
911
912static inline bool lbm_is_special(lbm_value symrep) {
913 return ((lbm_type_of(symrep) == LBM_TYPE_SYMBOL) &&
914 (lbm_dec_sym(symrep) < SPECIAL_SYMBOLS_END));
915}
916
917static inline bool lbm_is_closure(lbm_value exp) {
918 return ((lbm_is_cons(exp)) &&
920 (lbm_car(exp) == ENC_SYM_CLOSURE));
921}
922
923static inline bool lbm_is_continuation(lbm_value exp) {
924 return ((lbm_type_of(exp) == LBM_TYPE_CONS) &&
926 (lbm_car(exp) == ENC_SYM_CONT));
927}
928
929static inline bool lbm_is_macro(lbm_value exp) {
930 return ((lbm_type_of(exp) == LBM_TYPE_CONS) &&
932 (lbm_car(exp) == ENC_SYM_MACRO));
933}
934
935static inline bool lbm_is_match_binder(lbm_value exp) {
936 return (lbm_is_cons(exp) &&
938 (lbm_car(exp) == ENC_SYM_MATCH_ANY));
939}
940
942 return (lbm_is_cons(exp) &&
944 (lbm_car(exp) == ENC_SYM_COMMA) &&
946}
947
948static inline bool lbm_is_symbol(lbm_value exp) {
949 return !(exp & LBM_LOW_RESERVED_BITS);
950}
951
952static inline bool lbm_is_symbol_true(lbm_value exp) {
953 return (lbm_is_symbol(exp) && exp == ENC_SYM_TRUE);
954}
955
956static inline bool lbm_is_symbol_eval(lbm_value exp) {
957 return (lbm_is_symbol(exp) && exp == ENC_SYM_EVAL);
958}
959
960static inline bool lbm_is_symbol_merror(lbm_value exp) {
961 return lbm_is_symbol(exp) && (exp == ENC_SYM_MERROR);
962}
963
964static inline bool lbm_is_list(lbm_value x) {
965 return (lbm_is_cons(x) || lbm_is_symbol_nil(x));
966}
967
968static inline bool lbm_is_list_rw(lbm_value x) {
969 return (lbm_is_cons_rw(x) || lbm_is_symbol_nil(x));
970}
971
972static inline bool lbm_is_quoted_list(lbm_value x) {
973 return (lbm_is_cons(x) &&
975 (lbm_car(x) == ENC_SYM_QUOTE) &&
976 lbm_is_cons(lbm_cdr(x)) &&
978}
979
980#ifndef LBM64
981#define ERROR_SYMBOL_MASK 0xFFFFFFF0
982#else
983#define ERROR_SYMBOL_MASK 0xFFFFFFFFFFFFFFF0
984#endif
985
986/* all error signaling symbols are in the range 0x20 - 0x2F */
987static inline bool lbm_is_error(lbm_value v){
988 return (lbm_is_symbol(v) &&
989 ((lbm_dec_sym(v) & ERROR_SYMBOL_MASK) == 0x20));
990}
991
992// ref_cell: returns a reference to the cell addressed by bits 3 - 26
993// Assumes user has checked that is_ptr was set
994static inline lbm_cons_t* lbm_ref_cell(lbm_value addr) {
995 return &lbm_dec_heap(addr)[lbm_dec_cons_cell_ptr(addr)];
996 //return &lbm_heap_state.heap[lbm_dec_ptr(addr)];
997}
998
999
1000// lbm_uint a = lbm_heaps[0];
1001// lbm_uint b = lbm_heaps[1];
1002// lbm_uint i = (addr & LBM_PTR_TO_CONSTANT_BIT) >> LBM_PTR_TO_CONSTANT_SHIFT) - 1;
1003// lbm_uint h = (a & i) | (b & ~i);
1004
1005#ifdef __cplusplus
1006}
1007#endif
1008#endif
int32_t lbm_dec_as_i32(lbm_value val)
Definition heap.c:347
lbm_uint lbm_heap_size_bytes(void)
Definition heap.c:676
static bool lbm_is_error(lbm_value v)
Definition heap.h:987
lbm_flash_status write_const_cdr(lbm_value cell, lbm_value val)
Definition heap.c:1500
lbm_value lbm_enc_double(double x)
Definition heap.c:166
const uint8_t * lbm_heap_array_get_data_ro(lbm_value arr)
Definition heap.c:1318
lbm_value lbm_list_reverse(lbm_value list)
Definition heap.c:1109
int64_t lbm_dec_as_i64(lbm_value val)
Definition heap.c:372
void lbm_gc_mark_env(lbm_value)
Definition heap.c:888
static lbm_value lbm_enc_char(uint8_t x)
Definition heap.h:765
lbm_value lbm_list_append(lbm_value list1, lbm_value list2)
Definition heap.c:1172
lbm_flash_status write_const_car(lbm_value cell, lbm_value val)
Definition heap.c:1507
void lbm_heap_new_gc_time(lbm_uint dur)
lbm_flash_status
Definition heap.h:194
@ LBM_FLASH_FULL
Definition heap.h:196
@ LBM_FLASH_WRITE_ERROR
Definition heap.h:197
@ LBM_FLASH_WRITE_OK
Definition heap.h:195
int lbm_heap_allocate_lisp_array(lbm_value *res, lbm_uint size)
Definition heap.c:1276
lbm_value lbm_cddr(lbm_value c)
Definition heap.c:1040
static uint32_t lbm_dec_u32(lbm_value x)
Definition heap.h:798
lbm_uint lbm_dec_custom(lbm_value val)
Definition heap.c:290
#define ERROR_SYMBOL_MASK
Definition heap.h:981
static lbm_value lbm_set_ptr_type(lbm_value p, lbm_type t)
Definition heap.h:713
char * lbm_dec_str(lbm_value val)
Definition heap.c:238
static bool lbm_is_cons_rw(lbm_value x)
Definition heap.h:845
static lbm_uint lbm_dec_sym(lbm_value x)
Definition heap.h:781
static bool lbm_is_symbol_nil(lbm_value exp)
Definition heap.h:858
lbm_uint lbm_get_gc_stack_max(void)
Definition heap.c:684
lbm_array_header_t * lbm_dec_array_r(lbm_value val)
Definition heap.c:249
static bool lbm_is_list_rw(lbm_value x)
Definition heap.h:968
lbm_value lbm_enc_float(float x)
Definition heap.c:115
static lbm_uint lbm_dec_u(lbm_value x)
Definition heap.h:773
double lbm_dec_as_double(lbm_value val)
Definition heap.c:497
static bool lbm_is_array_r(lbm_value x)
Definition heap.h:882
void lbm_get_heap_state(lbm_heap_state_t *)
Definition heap.c:680
lbm_flash_status lbm_write_const_raw(lbm_uint *data, lbm_uint n, lbm_uint *res)
Definition heap.c:1468
static bool lbm_is_quoted_list(lbm_value x)
Definition heap.h:972
lbm_value lbm_index_list(lbm_value l, int32_t n)
Definition heap.c:1198
lbm_value lbm_cons(lbm_value car, lbm_value cdr)
Definition heap.c:993
void lbm_gc_lock(void)
Definition heap.c:86
lbm_int lbm_heap_array_get_size(lbm_value arr)
Definition heap.c:1308
lbm_value lbm_list_copy(int *m, lbm_value list)
Definition heap.c:1145
int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt)
Definition heap.c:1280
static bool lbm_is_symbol(lbm_value exp)
Definition heap.h:948
int lbm_set_car(lbm_value c, lbm_value v)
Definition heap.c:1050
lbm_value lbm_cdr(lbm_value cons)
Definition heap.c:1032
static bool lbm_is_closure(lbm_value exp)
Definition heap.h:917
static uint8_t lbm_dec_char(lbm_value x)
Definition heap.h:777
void lbm_gc_mark_aux(lbm_uint *data, lbm_uint n)
Definition heap.c:904
static lbm_cons_t * lbm_dec_heap(lbm_value p)
Definition heap.h:708
static bool lbm_is_symbol_merror(lbm_value exp)
Definition heap.h:960
static lbm_int lbm_dec_i(lbm_value x)
Definition heap.h:769
static lbm_value lbm_enc_i(lbm_int x)
Definition heap.h:721
lbm_uint lbm_dec_as_uint(lbm_value val)
Definition heap.c:422
void lbm_gc_state_inc(void)
Definition heap.c:986
lbm_value lbm_heap_allocate_list(lbm_uint n)
Definition heap.c:613
int lbm_const_heap_init(const_heap_write_fun w_fun, lbm_const_heap_t *heap, lbm_uint *addr)
Definition heap.c:1407
lbm_flash_status lbm_allocate_const_raw(lbm_uint nwords, lbm_uint *res)
Definition heap.c:1455
static bool lbm_is_lisp_array_rw(lbm_value x)
Definition heap.h:898
static lbm_type lbm_type_of_functional(lbm_value x)
Definition heap.h:687
static lbm_value lbm_enc_u(lbm_uint x)
Definition heap.h:725
static bool lbm_is_constant(lbm_value x)
Definition heap.h:835
static bool lbm_heap_array_valid(lbm_value arr)
Definition heap.h:874
lbm_value lbm_caar(lbm_value c)
Definition heap.c:1009
static bool lbm_is_channel(lbm_value x)
Definition heap.h:903
lbm_int lbm_dec_as_int(lbm_value val)
Definition heap.c:447
int lbm_heap_allocate_array(lbm_value *res, lbm_uint size)
Definition heap.c:1272
lbm_uint lbm_list_length(lbm_value c)
Definition heap.c:1083
lbm_uint lbm_size_of(lbm_type t)
Definition heap.c:1374
uint64_t lbm_dec_u64(lbm_value x)
Definition heap.c:212
bool(* const_heap_write_fun)(lbm_uint w, lbm_uint ix)
Definition heap.h:233
void lbm_gc_unlock(void)
Definition heap.c:88
static lbm_uint lbm_dec_cons_cell_ptr(lbm_value p)
Definition heap.h:703
lbm_value lbm_heap_allocate_list_init(unsigned int n,...)
Definition heap.c:661
static bool lbm_is_lisp_array_r(lbm_value x)
Definition heap.h:893
lbm_uint lbm_dec_raw(lbm_value v)
static lbm_uint lbm_heap_num_free(void)
Definition heap.h:289
lbm_uint lbm_heap_size(void)
Definition heap.c:672
static bool lbm_is_match_binder(lbm_value exp)
Definition heap.h:935
static lbm_type lbm_type_of(lbm_value x)
Definition heap.h:682
static int32_t lbm_dec_i32(lbm_value x)
Definition heap.h:812
static bool lbm_is_ptr(lbm_value x)
Definition heap.h:831
int lbm_set_cdr(lbm_value c, lbm_value v)
Definition heap.c:1061
int lbm_heap_init(lbm_cons_t *addr, lbm_uint num_cells, lbm_uint gc_stack_size)
Definition heap.c:578
static bool lbm_is_comma_qualified_symbol(lbm_value exp)
Definition heap.h:941
static lbm_cons_t * lbm_ref_cell(lbm_value addr)
Definition heap.h:994
uint64_t lbm_dec_as_u64(lbm_value val)
Definition heap.c:397
lbm_value lbm_car(lbm_value cons)
Definition heap.c:997
lbm_value lbm_cadr(lbm_value c)
Definition heap.c:1021
lbm_uint lbm_flash_memory_usage(void)
Definition heap.c:1514
static bool lbm_is_array_rw(lbm_value x)
Definition heap.h:887
lbm_value lbm_enc_u32(uint32_t x)
Definition heap.c:105
static bool lbm_is_symbol_true(lbm_value exp)
Definition heap.h:952
static bool lbm_is_continuation(lbm_value exp)
Definition heap.h:923
lbm_cons_t * lbm_heaps[2]
Definition heap.c:70
static bool lbm_is_symbol_eval(lbm_value exp)
Definition heap.h:956
lbm_array_header_t * lbm_dec_array_rw(lbm_value val)
Definition heap.c:257
int lbm_set_car_and_cdr(lbm_value c, lbm_value car_val, lbm_value cdr_val)
Definition heap.c:1071
lbm_value lbm_enc_i32(int32_t x)
Definition heap.c:95
lbm_flash_status lbm_const_write(lbm_uint *tgt, lbm_uint val)
Definition heap.c:1487
static lbm_uint lbm_dec_ptr(lbm_value p)
Definition heap.h:697
void lbm_heap_new_freelist_length(void)
Definition heap.c:571
lbm_value lbm_enc_i64(int64_t x)
Definition heap.c:146
lbm_value lbm_enc_u64(uint64_t x)
Definition heap.c:156
static bool lbm_is_char(lbm_value x)
Definition heap.h:908
int lbm_gc_sweep_phase(void)
Definition heap.c:925
float lbm_dec_as_float(lbm_value val)
Definition heap.c:472
static bool lbm_is_special(lbm_value symrep)
Definition heap.h:912
unsigned int lbm_list_length_pred(lbm_value c, bool *pres, bool(*pred)(lbm_value))
Definition heap.c:1095
static bool lbm_is_cons(lbm_value x)
Definition heap.h:854
void lbm_nil_freelist(void)
Definition heap.c:548
static lbm_value lbm_enc_cons_ptr(lbm_uint x)
Definition heap.h:693
int lbm_heap_explicit_free_array(lbm_value arr)
Definition heap.c:1354
lbm_uint lbm_get_gc_stack_size(void)
Definition heap.c:688
lbm_value lbm_list_drop(unsigned int n, lbm_value ls)
Definition heap.c:1188
uint8_t * lbm_heap_array_get_data_rw(lbm_value arr)
Definition heap.c:1327
lbm_uint lbm_heap_num_allocated(void)
Definition heap.c:669
void lbm_gc_mark_roots(lbm_uint *roots, lbm_uint num_roots)
Definition heap.c:918
lbm_value lbm_heap_allocate_list_init_va(unsigned int n, va_list valist)
Definition heap.c:637
static bool lbm_is_number(lbm_value x)
Definition heap.h:866
lbm_value lbm_heap_allocate_cell(lbm_type ptr_type, lbm_value car, lbm_value cdr)
Definition heap.c:597
static lbm_value lbm_enc_sym(lbm_uint s)
Definition heap.h:717
float lbm_dec_float(lbm_value x)
Definition heap.c:182
uint32_t lbm_dec_as_u32(lbm_value val)
Definition heap.c:323
lbm_value lbm_list_destructive_reverse(lbm_value list)
Definition heap.c:1128
lbm_flash_status lbm_allocate_const_cell(lbm_value *res)
Definition heap.c:1434
int64_t lbm_dec_i64(lbm_value x)
Definition heap.c:225
lbm_array_header_t * lbm_dec_lisp_array_rw(lbm_value val)
Definition heap.c:273
uint8_t lbm_dec_as_char(lbm_value a)
Definition heap.c:298
void lbm_gc_mark_phase(lbm_value root)
Definition heap.c:804
double lbm_dec_double(lbm_value x)
Definition heap.c:196
static bool lbm_is_list(lbm_value x)
Definition heap.h:964
static bool lbm_is_macro(lbm_value exp)
Definition heap.h:929
lbm_array_header_t * lbm_dec_lisp_array_r(lbm_value val)
Definition heap.c:265
lbm_heap_state_t lbm_heap_state
Definition heap.c:66
lbm_char_channel_t * lbm_dec_channel(lbm_value val)
Definition heap.c:281
#define ENC_SYM_CONT
Definition lbm_defines.h:489
#define LBM_TYPE_ARRAY
Definition lbm_defines.h:52
#define ENC_SYM_COMMA
Definition lbm_defines.h:460
#define LBM_PTR_BIT
Definition lbm_defines.h:32
#define LBM_LOW_RESERVED_BITS
Definition lbm_defines.h:82
#define LBM_CONS_TYPE_MASK
Definition lbm_defines.h:62
#define ENC_SYM_MERROR
Definition lbm_defines.h:412
#define LBM_PTR_TO_CONSTANT_BIT
Definition lbm_defines.h:38
#define LBM_TYPE_CONS
Definition lbm_defines.h:43
#define LBM_TYPE_CHANNEL
Definition lbm_defines.h:54
#define SPECIAL_SYMBOLS_END
Definition lbm_defines.h:386
#define LBM_TYPE_U
Definition lbm_defines.h:81
#define LBM_NUMBER_MASK
Definition lbm_defines.h:74
#define LBM_TYPE_I
Definition lbm_defines.h:80
#define ENC_SYM_EVAL
Definition lbm_defines.h:506
#define LBM_PTR_TO_CONSTANT_MASK
Definition lbm_defines.h:39
#define ENC_SYM_CLOSURE
Definition lbm_defines.h:490
#define LBM_PTR_VAL_MASK
Definition lbm_defines.h:33
#define ENC_SYM_CHANNEL_TYPE
Definition lbm_defines.h:428
#define LBM_PTR_TYPE_MASK
Definition lbm_defines.h:34
#define LBM_TYPE_LISPARRAY
Definition lbm_defines.h:56
#define LBM_TYPE_CHAR
Definition lbm_defines.h:78
#define ENC_SYM_QUOTE
Definition lbm_defines.h:475
#define ENC_SYM_MACRO
Definition lbm_defines.h:488
#define LBM_VAL_SHIFT
Definition lbm_defines.h:29
#define LBM_ADDRESS_SHIFT
Definition lbm_defines.h:28
#define LBM_VAL_TYPE_MASK
Definition lbm_defines.h:72
#define ENC_SYM_TRUE
Definition lbm_defines.h:405
#define LBM_PTR_TO_CONSTANT_SHIFT
Definition lbm_defines.h:40
#define LBM_TYPE_SYMBOL
Definition lbm_defines.h:77
#define ENC_SYM_MATCH_ANY
Definition lbm_defines.h:437
int32_t lbm_int
Definition lbm_types.h:49
uint32_t lbm_uint
Definition lbm_types.h:48
uint32_t lbm_type
Definition lbm_types.h:46
uint32_t lbm_value
Definition lbm_types.h:44
Definition heap.h:251
lbm_uint size
Definition heap.h:252
uint32_t index
Definition heap.h:254
lbm_uint * data
Definition heap.h:253
Definition heap.h:246
lbm_uint * data
Number of elements.
Definition heap.h:248
lbm_uint size
Definition heap.h:247
Definition lbm_channel.h:69
Definition heap.h:203
lbm_value cdr
Definition heap.h:205
lbm_value car
Definition heap.h:204
Definition heap.h:235
lbm_uint size
Definition heap.h:238
lbm_uint * heap
Definition heap.h:236
lbm_uint next
Definition heap.h:237
Definition heap.h:211
lbm_uint gc_least_free
Definition heap.h:226
lbm_uint heap_bytes
Definition heap.h:217
lbm_uint gc_recovered
Definition heap.h:224
lbm_uint gc_marked
Definition heap.h:223
lbm_uint num_alloc_arrays
Definition heap.h:220
lbm_uint num_alloc
Definition heap.h:219
lbm_uint gc_recovered_arrays
Definition heap.h:225
lbm_value freelist
Definition heap.h:213
lbm_stack_t gc_stack
Definition heap.h:214
lbm_uint heap_size
Definition heap.h:216
lbm_cons_t * heap
Definition heap.h:212
lbm_uint gc_last_free
Definition heap.h:227
lbm_uint gc_num
Definition heap.h:222
Definition stack.h:33