LispBM
Loading...
Searching...
No Matches
heap.h
Go to the documentation of this file.
1/*
2 Copyright 2018, 2024, 2025 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#include "lbm_image.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/*
38Planning for a more space efficient heap representation.
39TODO: Need to find a good reference to read up on this.
40 - List based heap
41 - Easy to implement and somewhat efficient
42
430000 0000 Size Free bits
44003F FFFF 4MB 10
45007F FFFF 8MB 9
4600FF FFFF 16MB 8
4701FF FFFF 32MB 7
4803FF FFFF 64MB 6 * Kind of heap size I am looking for
4907FF FFFF 128MB 5
500FFF FFFF 256MB 4
511FFF FFFF 512MB 3
52
53
54--- May 9 2021 ---
55Actually now I am much more interested in way smaller memories ;)
56
570000 0000 Size Free bits
580000 0FFF 4KB 20 |
590000 1FFF 8KB 19 |
600000 3FFF 16KB 18 |
610000 7FFF 32KB 17 |
620000 FFFF 64KB 16 |
630001 FFFF 128KB 15 |
640003 FFFF 256KB 14 | - This range is very interesting.
650007 FFFF 512KB 13
66000F FFFF 1MB 12
67001F FFFF 2MB 11
68003F FFFF 4MB 10
69007F FFFF 8MB 9
7000FF FFFF 16MB 8
7101FF FFFF 32MB 7
7203FF FFFF 64MB 6
7307FF FFFF 128MB 5
740FFF FFFF 256MB 4
751FFF FFFF 512MB 3
76
77Those are the kind of platforms that are fun... so a bunch of
78wasted bits in heap pointers if we run on small MCUs.
79
80-----------------
81
82it is also the case that not all addresses will be used if all "cells" are
83of the same size, 8 bytes...
84
85value 0: 0000 0000
86value 1: 0000 0008
87value 3: 0000 0010
88value 4: 0000 0018
89
90Means bits 0,1,2 will always be empty in a valid address.
91
92Cons cells also need to be have room for 2 pointers. So each ted cell from
93memory should be 8bytes.
94
95Things that needs to be represented within these bits:
96
97 - GC MARK one per cell
98 - TYPE: type of CAR and type of cons
99
100Types I would want:
101 - Full 32bit integer. Does not leave room for identification of type
102 - Float values. Same problem
103
104
105Free bits in pointers 64MB heap:
10631 30 29 28 27 26 2 1 0
1070 0 0 0 0 0 XX XXXX XXXX XXXX XXXX XXXX X 0 0 0
108
109
110Information needed for each cell:
111 Meaning | bits total | bits per car | bits per cdr
112 GC mark | 2 | 1 | 1 - only one of them will be used (the other is wasted)
113 Type | 2x | x | x
114 Ptr/!ptr | 2 | 1 | 1
115
116
117Types (unboxed):
118 - Symbols
119 - 28bit integer ( will need signed shift right functionality )
120 - 28bit unsigned integer
121 - Character
122
123If four types is all that should be possible (unboxed). then 2 bits are needed to differentiate.
1242 + 1 + 1 = 4 => 28bits for data.
125
126bit 0: ptr/!ptr
127bit 1: gc
128bit 2-3: type (if not ptr)
129bit 3 - 24 ptr (if ptr)
130bit 4 - 31 value (if value)
131
132An unboxed value can occupy a car or cdr field in a cons cell.
133
134types (boxed) extra information in pointer to cell can contain information
135 - 32 bit integer
136 - 32 bit unsigned integer
137 - 32 bit float
138
139boxed representation:
140 [ptr| cdr]
141 |
142 [Value | Aux + GC_MARK]
143
144Kinds of pointers:
145 - Pointer to cons cell.
146 - Pointer to unboxed value (fixnums not in a list, I hope this is so rare that it can be removed )
147 - integer
148 - unsigned integer
149 - symbol
150 - float
151 - Pointer to boxed value.
152 - 32 bit integer
153 - 32 bit unsigned integer
154 - 32 bit float
155 - (Maybe something else ? Vectors/strings allocated in memory not occupied by heap?)
156 - vector of int
157 - vector of uint
158 - vector of float
159 - vector of double
160 - String
161
16213 pointer"types" -> needs 4 bits
163for 64MB heap there are 6 free bits. So with this scheme going to 128MB or 256MB heap
164is also possible
165
166 a pointer to some off heap vector/string could be represented by
167
168 [ptr | cdr]
169 |
170 [full pointer | Aux + GC_MARK]
171 |
172 [VECTOR]
173
174Aux bits could be used for storing vector size. Up to 30bits should be available there
175>> This is problematic. Now the information that something is a vector is split up
176>> between 2 cons cells. This means GC needs both of these intact to be able to make
177>> proper decision.
178>> Will try to resolve this by adding some special symbols. But these must be symbols
179>> that cannot occur normally in programs. Then an array could be:
180
181 [Full pointer | ARRAY_SYM + GC_MARK]
182 |
183 [VECTOR]
184
185>> Boxed values same treatment as above.
186>> TODO: Could this be simpler?
187
188[ VALUE | TYPE_SYM + GC_MARK]
189
190
1910000 00XX XXXX XXXX XXXX XXXX XXXX X000 : 0x03FF FFF8
1921111 AA00 0000 0000 0000 0000 0000 0000 : 0xFC00 0000 (AA bits left unused for now, future heap growth?)
193 */
194
200
208
212typedef struct {
214 lbm_value freelist; // list of free cons cells.
216
217 lbm_uint heap_size; // In number of cells.
218 lbm_uint heap_bytes; // In bytes.
219
220 lbm_uint num_free; // Number of free cells.
221 lbm_uint num_alloc_arrays; // Number of arrays allocated.
222
223 lbm_uint gc_num; // Number of times gc has been performed.
224 lbm_uint gc_marked; // Number of cells marked by mark phase.
225 lbm_uint gc_recovered; // Number of cells recovered by sweep phase.
226 lbm_uint gc_recovered_arrays;// Number of arrays recovered by sweep.
227 lbm_uint gc_least_free; // The smallest length of the freelist.
228 lbm_uint gc_last_free; // Number of elements on the freelist
229 // after most recent GC.
231
233
235
236typedef struct {
238 lbm_uint next; // next free index.
239 lbm_uint size; // in lbm_uint words. (cons-cells = words / 2)
241
251
252typedef struct {
255 uint32_t index; // Limits arrays to max 2^32-1 elements.
257
262void lbm_gc_lock(void);
263/* Unlock GC mutex
264 */
265void lbm_gc_unlock(void);
266
273bool lbm_heap_init(lbm_cons_t *addr, lbm_uint num_cells,
274 lbm_uint gc_stack_size);
275
295static inline lbm_uint lbm_heap_num_free(void) {
297}
298
324
333
343lbm_value lbm_heap_allocate_list_init_va(unsigned int n, va_list valist);
344
353lbm_value lbm_heap_allocate_list_init(unsigned int n, ...);
359char *lbm_dec_str(lbm_value val);
387uint8_t lbm_dec_as_char(lbm_value a);
393uint32_t lbm_dec_as_u32(lbm_value val);
399int32_t lbm_dec_as_i32(lbm_value val);
405float lbm_dec_as_float(lbm_value val);
411uint64_t lbm_dec_as_u64(lbm_value val);
417int64_t lbm_dec_as_i64(lbm_value val);
423double lbm_dec_as_double(lbm_value val);
424
431
438
448
485
486// List functions
514lbm_value lbm_list_copy(int *m, lbm_value list);
515
526
532lbm_value lbm_list_drop(unsigned int n, lbm_value ls);
539
540// State and statistics
555// Garbage collection
560void lbm_gc_state_inc(void);
566void lbm_nil_freelist(void);
591void lbm_gc_mark_aux(lbm_uint *data, lbm_uint n);
599void lbm_gc_mark_roots(lbm_uint *roots, lbm_uint num_roots);
606int lbm_gc_sweep_phase(void);
607
608// Array functionality
631int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt);
641const uint8_t *lbm_heap_array_get_data_ro(lbm_value arr);
642
648
650 lbm_const_heap_t *heap,
651 lbm_uint *addr);
652
660
667 return (x & LBM_PTR_BIT) ? (x & LBM_PTR_TYPE_MASK) : (x & LBM_VAL_TYPE_MASK);
668}
669
677 return (x & LBM_PTR_BIT) ?
679 (x & LBM_VAL_TYPE_MASK);
680}
681
683 return ((x << LBM_ADDRESS_SHIFT) | LBM_TYPE_CONS | LBM_PTR_BIT);
684}
685
687 return ((LBM_PTR_VAL_MASK & p) >> LBM_ADDRESS_SHIFT);
688}
689
690extern lbm_cons_t *lbm_heaps[2];
691
696
701
703 return ((LBM_PTR_VAL_MASK & p) | t | LBM_PTR_BIT);
704}
705
707 return (s << LBM_VAL_SHIFT) | LBM_TYPE_SYMBOL;
708}
709
710static inline lbm_value lbm_enc_i(lbm_int x) {
711 return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_I;
712}
713
714static inline lbm_value lbm_enc_u(lbm_uint x) {
715 return (x << LBM_VAL_SHIFT) | LBM_TYPE_U;
716}
717
723extern lbm_value lbm_set_u32(lbm_value v, uint32_t x);
724
730extern lbm_value lbm_set_i32(lbm_value v, int32_t x);
731
737extern lbm_value lbm_set_float(lbm_value v, float x);
738
739
744extern lbm_value lbm_enc_i32(int32_t x);
745
750extern lbm_value lbm_enc_u32(uint32_t x);
751
756extern lbm_value lbm_enc_float(float x);
757
762extern lbm_value lbm_enc_i64(int64_t x);
763
768extern lbm_value lbm_enc_u64(uint64_t x);
769
774extern lbm_value lbm_enc_double(double x);
775
776static inline lbm_value lbm_enc_char(uint8_t x) {
777 return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_CHAR;
778}
779
780static inline lbm_int lbm_dec_i(lbm_value x) {
781 return (lbm_int)x >> LBM_VAL_SHIFT;
782}
783
784static inline lbm_uint lbm_dec_u(lbm_value x) {
785 return x >> LBM_VAL_SHIFT;
786}
787
788static inline uint8_t lbm_dec_char(lbm_value x) {
789 return (uint8_t)(x >> LBM_VAL_SHIFT);
790}
791
793 return x >> LBM_VAL_SHIFT;
794}
795
800extern float lbm_dec_float(lbm_value x);
801
806extern double lbm_dec_double(lbm_value x);
807
808
809static inline uint32_t lbm_dec_u32(lbm_value x) {
810#ifndef LBM64
811 return (uint32_t)lbm_car(x);
812#else
813 return (uint32_t)(x >> LBM_VAL_SHIFT);
814#endif
815}
816
821extern uint64_t lbm_dec_u64(lbm_value x);
822
823static inline int32_t lbm_dec_i32(lbm_value x) {
824#ifndef LBM64
825 return (int32_t)lbm_car(x);
826#else
827 return (int32_t)(x >> LBM_VAL_SHIFT);
828#endif
829}
830
835extern int64_t lbm_dec_i64(lbm_value x);
836
842static inline bool lbm_is_ptr(lbm_value x) {
843 return (x & LBM_PTR_BIT);
844}
845
846static inline bool lbm_is_constant(lbm_value x) {
847 return ((x & LBM_PTR_BIT && x & LBM_PTR_TO_CONSTANT_BIT) ||
848 (!(x & LBM_PTR_BIT)));
849}
850
856static inline bool lbm_is_cons_rw(lbm_value x) {
858 //return (lbm_type_of(x) == LBM_TYPE_CONS);
859}
860
866static inline bool lbm_is_cons(lbm_value x) {
868 //return lbm_is_ptr(x) && ((x & LBM_CONS_TYPE_MASK) == LBM_TYPE_CONS);
869}
870
877static inline bool lbm_is_symbol(lbm_value exp) {
878 return !(exp & LBM_LOW_RESERVED_BITS);
879}
880
887static inline bool lbm_is_symbol_nil(lbm_value exp) {
888 return !exp;
889}
890
897static inline bool lbm_is_number(lbm_value x) {
898 return
899 (x & LBM_PTR_BIT) ?
901 (x & LBM_VAL_TYPE_MASK);
902}
903
904// Check if an array is valid (an invalid array has been freed by someone explicitly)
912static inline bool lbm_heap_array_valid(lbm_value arr) {
913 return !(lbm_is_symbol_nil(lbm_car(arr))); // this is an is_zero check similar to (a == NULL)
914}
915
920static inline bool lbm_is_array_r(lbm_value x) {
921 lbm_type t = lbm_type_of(x);
922 bool t_ok = ((t & LBM_PTR_TO_CONSTANT_MASK) == LBM_TYPE_ARRAY);
923 bool t_valid = lbm_heap_array_valid(x);
924 return ( t_ok && t_valid ) ;
925}
926
927static inline bool lbm_is_array_rw(lbm_value x) {
928 return ((lbm_type_of(x) == LBM_TYPE_ARRAY) &&
931}
932
933static inline bool lbm_is_lisp_array_r(lbm_value x) {
934 lbm_type t = lbm_type_of(x);
936}
937
938static inline bool lbm_is_lisp_array_rw(lbm_value x) {
939 return( (lbm_type_of(x) == LBM_TYPE_LISPARRAY) && !(x & LBM_PTR_TO_CONSTANT_BIT));
940}
941
942
943static inline bool lbm_is_channel(lbm_value x) {
944 return (lbm_type_of(x) == LBM_TYPE_CHANNEL &&
946}
947static inline bool lbm_is_char(lbm_value x) {
948 return (lbm_type_of(x) == LBM_TYPE_CHAR);
949}
950
951static inline bool lbm_is_special(lbm_value symrep) {
952 return (lbm_is_symbol(symrep) &&
953 (lbm_dec_sym(symrep) < SPECIAL_SYMBOLS_END));
954}
955
956static inline bool lbm_is_closure(lbm_value exp) {
957 return ((lbm_is_cons(exp)) && (lbm_car(exp) == ENC_SYM_CLOSURE));
958}
959
960static inline bool lbm_is_continuation(lbm_value exp) {
961 return ((lbm_type_of(exp) == LBM_TYPE_CONS) && (lbm_car(exp) == ENC_SYM_CONT));
962}
963
964static inline bool lbm_is_macro(lbm_value exp) {
965 return (lbm_is_cons(exp) && (lbm_car(exp) == ENC_SYM_MACRO));
966}
967
968static inline bool lbm_is_match_binder(lbm_value exp) {
969 return (lbm_is_cons(exp) && (lbm_car(exp) == ENC_SYM_MATCH_ANY));
970}
971
973 return (lbm_is_cons(exp) &&
974 (lbm_car(exp) == ENC_SYM_COMMA) &&
975 (lbm_is_symbol(lbm_cadr(exp))));
976}
977
978static inline bool lbm_is_symbol_true(lbm_value exp) {
979 return (exp == ENC_SYM_TRUE);
980}
981
982static inline bool lbm_is_symbol_eval(lbm_value exp) {
983 return (exp == ENC_SYM_EVAL);
984}
985
986static inline bool lbm_is_symbol_merror(lbm_value exp) {
987 return (exp == ENC_SYM_MERROR);
988}
989
990static inline bool lbm_is_list(lbm_value x) {
991 return (lbm_is_cons(x) || lbm_is_symbol_nil(x));
992}
993
994static inline bool lbm_is_list_rw(lbm_value x) {
995 return (lbm_is_cons_rw(x) || lbm_is_symbol_nil(x));
996}
997
998static inline bool lbm_is_quoted_list(lbm_value x) {
999 return (lbm_is_cons(x) &&
1000 (lbm_car(x) == ENC_SYM_QUOTE) &&
1001 lbm_is_cons(lbm_cdr(x)) &&
1002 lbm_is_cons(lbm_cadr(x)));
1003}
1004
1005#ifndef LBM64
1006#define ERROR_SYMBOL_MASK 0xFFFFFF0F
1007#else
1008#define ERROR_SYMBOL_MASK 0xFFFFFFFFFFFFF0FF
1009#endif
1010
1011// all error signaling symbols are in the range 0x20 - 0x2F
1012// encoded that is 0x200 - 0x2F0 on 32bit and
1013// 0x2000 - 0x2F00 on 32bit
1014static inline bool lbm_is_error(lbm_value v){
1015#ifndef LBM64
1016 return (v & ERROR_SYMBOL_MASK) == 0x200;
1017#else
1018 return (v & ERROR_SYMBOL_MASK) == 0x2000;
1019#endif
1020}
1021
1022// ref_cell: returns a reference to the cell addressed by bits 3 - 26
1023// Assumes user has checked that is_ptr was set
1024static inline lbm_cons_t* lbm_ref_cell(lbm_value addr) {
1025 return &lbm_dec_heap(addr)[lbm_dec_cons_cell_ptr(addr)];
1026 //return &lbm_heap_state.heap[lbm_dec_ptr(addr)];
1027}
1028
1035static inline int lbm_set_car(lbm_value c, lbm_value v) {
1036 int r = 0;
1037
1038 if (lbm_is_cons_rw(c)) {
1039 lbm_cons_t *cell = lbm_ref_cell(c);
1040 cell->car = v;
1041 r = 1;
1042 }
1043 return r;
1044}
1045
1052static inline int lbm_set_cdr(lbm_value c, lbm_value v) {
1053 int r = 0;
1054 if (lbm_is_cons_rw(c)){
1055 lbm_cons_t *cell = lbm_ref_cell(c);
1056 cell->cdr = v;
1057 r = 1;
1058 }
1059 return r;
1060}
1061
1069static inline int lbm_set_car_and_cdr(lbm_value c, lbm_value car_val, lbm_value cdr_val) {
1070 int r = 0;
1071 if (lbm_is_cons_rw(c)) {
1072 lbm_cons_t *cell = lbm_ref_cell(c);
1073 cell->car = car_val;
1074 cell->cdr = cdr_val;
1075 r = 1;
1076 }
1077 return r;
1078}
1079
1080#define TRAV_FUN_SUBTREE_DONE 0
1081#define TRAV_FUN_SUBTREE_CONTINUE 1
1082#define TRAV_FUN_SUBTREE_PROCEED 2
1083
1084typedef int (*trav_fun)(lbm_value, bool, void*);
1085
1091void lbm_ptr_rev_trav(trav_fun f, lbm_value v, void* arg);
1092
1093// lbm_uint a = lbm_heaps[0];
1094// lbm_uint b = lbm_heaps[1];
1095// lbm_uint i = (addr & LBM_PTR_TO_CONSTANT_BIT) >> LBM_PTR_TO_CONSTANT_SHIFT) - 1;
1096// lbm_uint h = (a & i) | (b & ~i);
1097
1098#ifdef LBM64
1099#define lbm_dec_as_int lbm_dec_as_i64
1100#define lbm_dec_as_uint lbm_dec_as_u64
1101#else
1102#define lbm_dec_as_int lbm_dec_as_i32
1103#define lbm_dec_as_uint lbm_dec_as_u32
1104#endif
1105
1106#ifdef __cplusplus
1107}
1108#endif
1109#endif
int32_t lbm_dec_as_i32(lbm_value val)
Definition heap.c:388
lbm_uint lbm_heap_size_bytes(void)
Definition heap.c:661
static bool lbm_is_error(lbm_value v)
Definition heap.h:1014
lbm_flash_status write_const_cdr(lbm_value cell, lbm_value val)
Definition heap.c:1347
static int lbm_set_car(lbm_value c, lbm_value v)
Definition heap.h:1035
lbm_value lbm_enc_double(double x)
Definition heap.c:223
const uint8_t * lbm_heap_array_get_data_ro(lbm_value arr)
Definition heap.c:1200
int64_t lbm_dec_as_i64(lbm_value val)
Definition heap.c:413
void lbm_gc_mark_env(lbm_value)
Definition heap.c:838
lbm_value lbm_set_float(lbm_value v, float x)
Definition heap.c:157
static lbm_value lbm_enc_char(uint8_t x)
Definition heap.h:776
lbm_value lbm_list_append(lbm_value list1, lbm_value list2)
Definition heap.c:1054
lbm_flash_status write_const_car(lbm_value cell, lbm_value val)
Definition heap.c:1354
void lbm_heap_new_gc_time(lbm_uint dur)
lbm_flash_status
Definition heap.h:195
@ LBM_FLASH_FULL
Definition heap.h:197
@ LBM_FLASH_WRITE_ERROR
Definition heap.h:198
@ LBM_FLASH_WRITE_OK
Definition heap.h:196
int lbm_heap_allocate_lisp_array(lbm_value *res, lbm_uint size)
Definition heap.c:1158
lbm_value lbm_cddr(lbm_value c)
Definition heap.c:990
static uint32_t lbm_dec_u32(lbm_value x)
Definition heap.h:809
lbm_uint lbm_dec_custom(lbm_value val)
Definition heap.c:331
#define ERROR_SYMBOL_MASK
Definition heap.h:1006
#define lbm_dec_as_uint
Definition heap.h:1103
static lbm_value lbm_set_ptr_type(lbm_value p, lbm_type t)
Definition heap.h:702
char * lbm_dec_str(lbm_value val)
Definition heap.c:295
static bool lbm_is_cons_rw(lbm_value x)
Definition heap.h:856
static lbm_uint lbm_dec_sym(lbm_value x)
Definition heap.h:792
static bool lbm_is_symbol_nil(lbm_value exp)
Definition heap.h:887
lbm_uint lbm_get_gc_stack_max(void)
Definition heap.c:669
lbm_array_header_t * lbm_dec_array_r(lbm_value val)
Definition heap.c:306
static bool lbm_is_list_rw(lbm_value x)
Definition heap.h:994
lbm_value lbm_enc_float(float x)
Definition heap.c:172
static lbm_uint lbm_dec_u(lbm_value x)
Definition heap.h:784
double lbm_dec_as_double(lbm_value val)
Definition heap.c:488
static bool lbm_is_array_r(lbm_value x)
Definition heap.h:920
void lbm_get_heap_state(lbm_heap_state_t *)
Definition heap.c:665
lbm_flash_status lbm_write_const_raw(lbm_uint *data, lbm_uint n, lbm_uint *res)
Definition heap.c:1315
static bool lbm_is_quoted_list(lbm_value x)
Definition heap.h:998
#define lbm_dec_as_int
Definition heap.h:1102
lbm_value lbm_index_list(lbm_value l, int32_t n)
Definition heap.c:1081
static int lbm_set_cdr(lbm_value c, lbm_value v)
Definition heap.h:1052
lbm_value lbm_cons(lbm_value car, lbm_value cdr)
Definition heap.c:943
void lbm_gc_lock(void)
Definition heap.c:101
lbm_int lbm_heap_array_get_size(lbm_value arr)
Definition heap.c:1190
lbm_value lbm_list_copy(int *m, lbm_value list)
Definition heap.c:1027
int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt)
Definition heap.c:1162
static bool lbm_is_symbol(lbm_value exp)
Definition heap.h:877
int(* trav_fun)(lbm_value, bool, void *)
Definition heap.h:1084
lbm_value lbm_cdr(lbm_value cons)
Definition heap.c:982
static bool lbm_is_closure(lbm_value exp)
Definition heap.h:956
static uint8_t lbm_dec_char(lbm_value x)
Definition heap.h:788
void lbm_ptr_rev_trav(trav_fun f, lbm_value v, void *arg)
Definition heap.c:1392
void lbm_gc_mark_aux(lbm_uint *data, lbm_uint n)
Definition heap.c:854
static lbm_cons_t * lbm_dec_heap(lbm_value p)
Definition heap.h:697
static bool lbm_is_symbol_merror(lbm_value exp)
Definition heap.h:986
static lbm_int lbm_dec_i(lbm_value x)
Definition heap.h:780
static lbm_value lbm_enc_i(lbm_int x)
Definition heap.h:710
void lbm_gc_state_inc(void)
Definition heap.c:936
lbm_value lbm_heap_allocate_list(lbm_uint n)
Definition heap.c:603
int lbm_const_heap_init(const_heap_write_fun w_fun, lbm_const_heap_t *heap, lbm_uint *addr)
Definition heap.c:1254
lbm_flash_status lbm_allocate_const_raw(lbm_uint nwords, lbm_uint *res)
Definition heap.c:1302
static bool lbm_is_lisp_array_rw(lbm_value x)
Definition heap.h:938
static lbm_type lbm_type_of_functional(lbm_value x)
Definition heap.h:676
static lbm_value lbm_enc_u(lbm_uint x)
Definition heap.h:714
static bool lbm_is_constant(lbm_value x)
Definition heap.h:846
static bool lbm_heap_array_valid(lbm_value arr)
Definition heap.h:912
lbm_value lbm_caar(lbm_value c)
Definition heap.c:959
static bool lbm_is_channel(lbm_value x)
Definition heap.h:943
int lbm_heap_allocate_array(lbm_value *res, lbm_uint size)
Definition heap.c:1154
lbm_uint lbm_list_length(lbm_value c)
Definition heap.c:1001
lbm_value lbm_set_i32(lbm_value v, int32_t x)
Definition heap.c:147
uint64_t lbm_dec_u64(lbm_value x)
Definition heap.c:269
bool(* const_heap_write_fun)(lbm_uint w, lbm_uint ix)
Definition heap.h:234
void lbm_gc_unlock(void)
Definition heap.c:103
static lbm_uint lbm_dec_cons_cell_ptr(lbm_value p)
Definition heap.h:692
static int lbm_set_car_and_cdr(lbm_value c, lbm_value car_val, lbm_value cdr_val)
Definition heap.h:1069
lbm_value lbm_heap_allocate_list_init(unsigned int n,...)
Definition heap.c:646
static bool lbm_is_lisp_array_r(lbm_value x)
Definition heap.h:933
lbm_uint lbm_dec_raw(lbm_value v)
static lbm_uint lbm_heap_num_free(void)
Definition heap.h:295
lbm_uint lbm_heap_size(void)
Definition heap.c:657
bool lbm_heap_init(lbm_cons_t *addr, lbm_uint num_cells, lbm_uint gc_stack_size)
Definition heap.c:568
static bool lbm_is_match_binder(lbm_value exp)
Definition heap.h:968
static lbm_type lbm_type_of(lbm_value x)
Definition heap.h:666
static int32_t lbm_dec_i32(lbm_value x)
Definition heap.h:823
static bool lbm_is_ptr(lbm_value x)
Definition heap.h:842
static bool lbm_is_comma_qualified_symbol(lbm_value exp)
Definition heap.h:972
static lbm_cons_t * lbm_ref_cell(lbm_value addr)
Definition heap.h:1024
uint64_t lbm_dec_as_u64(lbm_value val)
Definition heap.c:438
lbm_value lbm_car(lbm_value cons)
Definition heap.c:947
lbm_value lbm_cadr(lbm_value c)
Definition heap.c:971
lbm_uint lbm_flash_memory_usage(void)
Definition heap.c:1361
lbm_value lbm_set_u32(lbm_value v, uint32_t x)
Definition heap.c:137
static bool lbm_is_array_rw(lbm_value x)
Definition heap.h:927
lbm_value lbm_enc_u32(uint32_t x)
Definition heap.c:120
static bool lbm_is_symbol_true(lbm_value exp)
Definition heap.h:978
static bool lbm_is_continuation(lbm_value exp)
Definition heap.h:960
lbm_cons_t * lbm_heaps[2]
Definition heap.c:85
static bool lbm_is_symbol_eval(lbm_value exp)
Definition heap.h:982
lbm_array_header_t * lbm_dec_array_rw(lbm_value val)
Definition heap.c:314
lbm_value lbm_enc_i32(int32_t x)
Definition heap.c:110
lbm_flash_status lbm_const_write(lbm_uint *tgt, lbm_uint val)
Definition heap.c:1334
static lbm_uint lbm_dec_ptr(lbm_value p)
Definition heap.h:686
void lbm_heap_new_freelist_length(void)
Definition heap.c:562
lbm_value lbm_enc_i64(int64_t x)
Definition heap.c:203
lbm_value lbm_enc_u64(uint64_t x)
Definition heap.c:213
static bool lbm_is_char(lbm_value x)
Definition heap.h:947
int lbm_gc_sweep_phase(void)
Definition heap.c:875
float lbm_dec_as_float(lbm_value val)
Definition heap.c:463
static bool lbm_is_special(lbm_value symrep)
Definition heap.h:951
static bool lbm_is_cons(lbm_value x)
Definition heap.h:866
void lbm_nil_freelist(void)
Definition heap.c:539
static lbm_value lbm_enc_cons_ptr(lbm_uint x)
Definition heap.h:682
int lbm_heap_explicit_free_array(lbm_value arr)
Definition heap.c:1226
lbm_uint lbm_get_gc_stack_size(void)
Definition heap.c:673
lbm_value lbm_list_drop(unsigned int n, lbm_value ls)
Definition heap.c:1072
lbm_uint lbm_heap_num_allocated(void)
Definition heap.c:654
void lbm_gc_mark_roots(lbm_uint *roots, lbm_uint num_roots)
Definition heap.c:868
lbm_value lbm_heap_allocate_list_init_va(unsigned int n, va_list valist)
Definition heap.c:625
static bool lbm_is_number(lbm_value x)
Definition heap.h:897
lbm_value lbm_heap_allocate_cell(lbm_type ptr_type, lbm_value car, lbm_value cdr)
Definition heap.c:587
static lbm_value lbm_enc_sym(lbm_uint s)
Definition heap.h:706
float lbm_dec_float(lbm_value x)
Definition heap.c:239
uint32_t lbm_dec_as_u32(lbm_value val)
Definition heap.c:364
lbm_value lbm_list_destructive_reverse(lbm_value list)
Definition heap.c:1011
lbm_flash_status lbm_allocate_const_cell(lbm_value *res)
Definition heap.c:1281
int64_t lbm_dec_i64(lbm_value x)
Definition heap.c:282
uint8_t lbm_dec_as_char(lbm_value a)
Definition heap.c:339
void lbm_gc_mark_phase(lbm_value root)
Definition heap.c:748
double lbm_dec_double(lbm_value x)
Definition heap.c:253
static bool lbm_is_list(lbm_value x)
Definition heap.h:990
static bool lbm_is_macro(lbm_value exp)
Definition heap.h:964
lbm_heap_state_t lbm_heap_state
Definition heap.c:81
lbm_char_channel_t * lbm_dec_channel(lbm_value val)
Definition heap.c:322
#define ENC_SYM_CONT
Definition lbm_defines.h:498
#define LBM_TYPE_ARRAY
Definition lbm_defines.h:54
#define LBM_EXACT_CONS_MASK
Definition lbm_defines.h:64
#define ENC_SYM_COMMA
Definition lbm_defines.h:469
#define LBM_PTR_BIT
Definition lbm_defines.h:33
#define LBM_LOW_RESERVED_BITS
Definition lbm_defines.h:87
#define LBM_CONS_TYPE_MASK
Definition lbm_defines.h:67
#define ENC_SYM_MERROR
Definition lbm_defines.h:421
#define LBM_PTR_TO_CONSTANT_BIT
Definition lbm_defines.h:40
#define LBM_TYPE_CONS
Definition lbm_defines.h:45
#define LBM_TYPE_CHANNEL
Definition lbm_defines.h:56
#define SPECIAL_SYMBOLS_END
Definition lbm_defines.h:395
#define LBM_TYPE_U
Definition lbm_defines.h:86
#define LBM_NUMBER_MASK
Definition lbm_defines.h:79
#define LBM_TYPE_I
Definition lbm_defines.h:85
#define ENC_SYM_EVAL
Definition lbm_defines.h:515
#define LBM_PTR_TO_CONSTANT_MASK
Definition lbm_defines.h:41
#define ENC_SYM_CLOSURE
Definition lbm_defines.h:499
#define LBM_PTR_VAL_MASK
Definition lbm_defines.h:34
#define ENC_SYM_CHANNEL_TYPE
Definition lbm_defines.h:437
#define LBM_PTR_TYPE_MASK
Definition lbm_defines.h:35
#define LBM_TYPE_LISPARRAY
Definition lbm_defines.h:58
#define LBM_TYPE_CHAR
Definition lbm_defines.h:83
#define ENC_SYM_QUOTE
Definition lbm_defines.h:484
#define ENC_SYM_MACRO
Definition lbm_defines.h:497
#define LBM_CONS_CONST_TYPE_MASK
Definition lbm_defines.h:68
#define LBM_VAL_SHIFT
Definition lbm_defines.h:30
#define LBM_ADDRESS_SHIFT
Definition lbm_defines.h:29
#define LBM_VAL_TYPE_MASK
Definition lbm_defines.h:77
#define ENC_SYM_TRUE
Definition lbm_defines.h:414
#define LBM_PTR_TO_CONSTANT_SHIFT
Definition lbm_defines.h:42
#define LBM_TYPE_SYMBOL
Definition lbm_defines.h:82
#define ENC_SYM_MATCH_ANY
Definition lbm_defines.h:446
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:252
lbm_uint size
Definition heap.h:253
uint32_t index
Definition heap.h:255
lbm_uint * data
Definition heap.h:254
Definition heap.h:247
lbm_uint * data
Number of elements.
Definition heap.h:249
lbm_uint size
Definition heap.h:248
Definition lbm_channel.h:69
Definition heap.h:204
lbm_value cdr
Definition heap.h:206
lbm_value car
Definition heap.h:205
Definition heap.h:236
lbm_uint size
Definition heap.h:239
lbm_uint * heap
Definition heap.h:237
lbm_uint next
Definition heap.h:238
Definition heap.h:212
lbm_uint gc_least_free
Definition heap.h:227
lbm_uint heap_bytes
Definition heap.h:218
lbm_uint gc_recovered
Definition heap.h:225
lbm_uint num_free
Definition heap.h:220
lbm_uint gc_marked
Definition heap.h:224
lbm_uint num_alloc_arrays
Definition heap.h:221
lbm_uint gc_recovered_arrays
Definition heap.h:226
lbm_value freelist
Definition heap.h:214
lbm_stack_t gc_stack
Definition heap.h:215
lbm_uint heap_size
Definition heap.h:217
lbm_cons_t * heap
Definition heap.h:213
lbm_uint gc_last_free
Definition heap.h:228
lbm_uint gc_num
Definition heap.h:223
Definition stack.h:33