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);
368bool lbm_dec_str_size(lbm_value val, char **data, size_t *size);
396uint8_t lbm_dec_as_char(lbm_value a);
402uint32_t lbm_dec_as_u32(lbm_value val);
408int32_t lbm_dec_as_i32(lbm_value val);
414float lbm_dec_as_float(lbm_value val);
420uint64_t lbm_dec_as_u64(lbm_value val);
426int64_t lbm_dec_as_i64(lbm_value val);
432double lbm_dec_as_double(lbm_value val);
433
440
447
457
494
495// List functions
523lbm_value lbm_list_copy(int *m, lbm_value list);
524
535
541lbm_value lbm_list_drop(unsigned int n, lbm_value ls);
548
549// State and statistics
564// Garbage collection
569void lbm_gc_state_inc(void);
575void lbm_nil_freelist(void);
609void lbm_gc_mark_roots(lbm_uint *roots, lbm_uint num_roots);
616int lbm_gc_sweep_phase(void);
617
618// Array functionality
641int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt);
651const uint8_t *lbm_heap_array_get_data_ro(lbm_value arr);
652
658
660 lbm_const_heap_t *heap,
661 lbm_uint *addr);
662
670
677 return (x & LBM_PTR_BIT) ? (x & LBM_PTR_TYPE_MASK) : (x & LBM_VAL_TYPE_MASK);
678}
679
687 return (x & LBM_PTR_BIT) ?
689 (x & LBM_VAL_TYPE_MASK);
690}
691
693 return ((x << LBM_ADDRESS_SHIFT) | LBM_TYPE_CONS | LBM_PTR_BIT);
694}
695
697 return ((LBM_PTR_VAL_MASK & p) >> LBM_ADDRESS_SHIFT);
698}
699
700#define LBM_RAM_HEAP 0
701#define LBM_CONST_HEAP 1
702
703extern lbm_cons_t *lbm_heaps[2];
704
709
711 return ((LBM_PTR_VAL_MASK & p) | t | LBM_PTR_BIT);
712}
713
715 return (s << LBM_VAL_SHIFT) | LBM_TYPE_SYMBOL;
716}
717
718static inline lbm_value lbm_enc_i(lbm_int x) {
719 return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_I;
720}
721
722static inline lbm_value lbm_enc_u(lbm_uint x) {
723 return (x << LBM_VAL_SHIFT) | LBM_TYPE_U;
724}
725
731extern lbm_value lbm_set_u32(lbm_value v, uint32_t x);
732
738extern lbm_value lbm_set_i32(lbm_value v, int32_t x);
739
745extern lbm_value lbm_set_float(lbm_value v, float x);
746
747
752extern lbm_value lbm_enc_i32(int32_t x);
753
758extern lbm_value lbm_enc_u32(uint32_t x);
759
764extern lbm_value lbm_enc_float(float x);
765
770extern lbm_value lbm_enc_i64(int64_t x);
771
776extern lbm_value lbm_enc_u64(uint64_t x);
777
782extern lbm_value lbm_enc_double(double x);
783
784static inline lbm_value lbm_enc_char(uint8_t x) {
785 return ((lbm_uint)x << LBM_VAL_SHIFT) | LBM_TYPE_CHAR;
786}
787
788static inline lbm_int lbm_dec_i(lbm_value x) {
789 return (lbm_int)x >> LBM_VAL_SHIFT;
790}
791
792static inline lbm_uint lbm_dec_u(lbm_value x) {
793 return x >> LBM_VAL_SHIFT;
794}
795
796static inline uint8_t lbm_dec_char(lbm_value x) {
797 return (uint8_t)(x >> LBM_VAL_SHIFT);
798}
799
801 return x >> LBM_VAL_SHIFT;
802}
803
808extern float lbm_dec_float(lbm_value x);
809
814extern double lbm_dec_double(lbm_value x);
815
816
817static inline uint32_t lbm_dec_u32(lbm_value x) {
818#ifndef LBM64
819 return (uint32_t)lbm_car(x);
820#else
821 return (uint32_t)(x >> LBM_VAL_SHIFT);
822#endif
823}
824
829extern uint64_t lbm_dec_u64(lbm_value x);
830
831static inline int32_t lbm_dec_i32(lbm_value x) {
832#ifndef LBM64
833 return (int32_t)lbm_car(x);
834#else
835 return (int32_t)(x >> LBM_VAL_SHIFT);
836#endif
837}
838
843extern int64_t lbm_dec_i64(lbm_value x);
844
850static inline bool lbm_is_ptr(lbm_value x) {
851 return (x & LBM_PTR_BIT);
852}
853
854static inline bool lbm_is_constant(lbm_value x) {
855 return ((x & LBM_PTR_BIT && x & LBM_PTR_TO_CONSTANT_BIT) ||
856 (!(x & LBM_PTR_BIT)));
857}
858
865static inline bool lbm_ptr_is_constant(lbm_value x) {
866 return (x & LBM_PTR_TO_CONSTANT_BIT);
867}
868
874static inline bool lbm_is_cons_rw(lbm_value x) {
876 //return !((x & (LBM_CONS_CONST_TYPE_MASK | LBM_PTR_BIT)) ^ LBM_EXACT_CONS_MASK);
877 //return (lbm_type_of(x) == LBM_TYPE_CONS);
878}
879
885static inline bool lbm_is_cons(lbm_value x) {
887 //return !((x & (LBM_CONS_TYPE_MASK | LBM_PTR_BIT)) ^ LBM_EXACT_CONS_MASK);
888 //return lbm_is_ptr(x) && ((x & LBM_CONS_TYPE_MASK) == LBM_TYPE_CONS);
889}
890
897static inline bool lbm_is_symbol(lbm_value exp) {
898 return !(exp & LBM_LOW_RESERVED_BITS);
899}
900
907static inline bool lbm_is_symbol_nil(lbm_value exp) {
908 return !exp;
909}
910
917static inline bool lbm_is_number(lbm_value x) {
918 return
919 (x & LBM_PTR_BIT) ?
921 (x & LBM_VAL_TYPE_MASK);
922}
923
924// Check if an array is valid (an invalid array has been freed by someone explicitly)
932static inline bool lbm_heap_array_valid(lbm_value arr) {
933 return !(lbm_is_symbol_nil(lbm_car(arr))); // this is an is_zero check similar to (a == NULL)
934}
935
940static inline bool lbm_is_array_r(lbm_value x) {
941 lbm_type t = lbm_type_of(x);
942 bool t_ok = ((t & LBM_PTR_TO_CONSTANT_MASK) == LBM_TYPE_ARRAY);
943 bool t_valid = lbm_heap_array_valid(x);
944 return ( t_ok && t_valid ) ;
945}
946
947static inline bool lbm_is_array_rw(lbm_value x) {
948 return ((lbm_type_of(x) == LBM_TYPE_ARRAY) &&
951}
952
953static inline bool lbm_is_lisp_array_r(lbm_value x) {
954 lbm_type t = lbm_type_of(x);
956}
957
958static inline bool lbm_is_lisp_array_rw(lbm_value x) {
959 return( (lbm_type_of(x) == LBM_TYPE_LISPARRAY) && !(x & LBM_PTR_TO_CONSTANT_BIT));
960}
961
962
963static inline bool lbm_is_channel(lbm_value x) {
964 return (lbm_type_of(x) == LBM_TYPE_CHANNEL &&
966}
967static inline bool lbm_is_char(lbm_value x) {
968 return (lbm_type_of(x) == LBM_TYPE_CHAR);
969}
970
971static inline bool lbm_is_special(lbm_value symrep) {
972 return (lbm_is_symbol(symrep) &&
973 (lbm_dec_sym(symrep) < SPECIAL_SYMBOLS_END));
974}
975
976static inline bool lbm_is_closure(lbm_value exp) {
977 return ((lbm_is_cons(exp)) && (lbm_car(exp) == ENC_SYM_CLOSURE));
978}
979
980static inline bool lbm_is_continuation(lbm_value exp) {
981 return ((lbm_type_of(exp) == LBM_TYPE_CONS) && (lbm_car(exp) == ENC_SYM_CONT));
982}
983
984static inline bool lbm_is_macro(lbm_value exp) {
985 return (lbm_is_cons(exp) && (lbm_car(exp) == ENC_SYM_MACRO));
986}
987
988static inline bool lbm_is_match_binder(lbm_value exp) {
989 return (lbm_is_cons(exp) && (lbm_car(exp) == ENC_SYM_MATCH_ANY));
990}
991
993 return (lbm_is_cons(exp) &&
994 (lbm_car(exp) == ENC_SYM_COMMA) &&
995 (lbm_is_symbol(lbm_cadr(exp))));
996}
997
998static inline bool lbm_is_symbol_true(lbm_value exp) {
999 return (exp == ENC_SYM_TRUE);
1000}
1001
1002static inline bool lbm_is_symbol_eval(lbm_value exp) {
1003 return (exp == ENC_SYM_EVAL);
1004}
1005
1006static inline bool lbm_is_symbol_merror(lbm_value exp) {
1007 return (exp == ENC_SYM_MERROR);
1008}
1009
1010static inline bool lbm_is_list(lbm_value x) {
1011 return (lbm_is_cons(x) || lbm_is_symbol_nil(x));
1012}
1013
1014static inline bool lbm_is_list_rw(lbm_value x) {
1015 return (lbm_is_cons_rw(x) || lbm_is_symbol_nil(x));
1016}
1017
1018static inline bool lbm_is_quoted_list(lbm_value x) {
1019 return (lbm_is_cons(x) &&
1020 (lbm_car(x) == ENC_SYM_QUOTE) &&
1021 lbm_is_cons(lbm_cdr(x)) &&
1022 lbm_is_cons(lbm_cadr(x)));
1023}
1024
1025#ifndef LBM64
1026#define ERROR_SYMBOL_MASK 0xFFFFFF0F
1027#else
1028#define ERROR_SYMBOL_MASK 0xFFFFFFFFFFFFF0FF
1029#endif
1030
1031// all error signaling symbols are in the range 0x20 - 0x2F
1032// encoded that is 0x200 - 0x2F0 on 32bit and
1033// 0x2000 - 0x2F00 on 64bit
1034static inline bool lbm_is_error(lbm_value v){
1035#ifndef LBM64
1036 return (v & ERROR_SYMBOL_MASK) == 0x200;
1037#else
1038 return (v & ERROR_SYMBOL_MASK) == 0x2000;
1039#endif
1040}
1041
1042// ref_cell: returns a reference to the cell addressed by bits 3 - 26
1043// Assumes user has checked that is_ptr was set
1044static inline lbm_cons_t* lbm_ref_cell(lbm_value addr) {
1045 return &lbm_dec_heap(addr)[lbm_dec_ptr(addr)];
1046 //return &lbm_heap_state.heap[lbm_dec_ptr(addr)];
1047}
1048
1055static inline int lbm_set_car(lbm_value c, lbm_value v) {
1056 int r = 0;
1057
1058 if (lbm_is_cons_rw(c)) {
1059 lbm_cons_t *cell = lbm_ref_cell(c);
1060 cell->car = v;
1061 r = 1;
1062 }
1063 return r;
1064}
1065
1072static inline int lbm_set_cdr(lbm_value c, lbm_value v) {
1073 int r = 0;
1074 if (lbm_is_cons_rw(c)){
1075 lbm_cons_t *cell = lbm_ref_cell(c);
1076 cell->cdr = v;
1077 r = 1;
1078 }
1079 return r;
1080}
1081
1089static inline int lbm_set_car_and_cdr(lbm_value c, lbm_value car_val, lbm_value cdr_val) {
1090 int r = 0;
1091 if (lbm_is_cons_rw(c)) {
1092 lbm_cons_t *cell = lbm_ref_cell(c);
1093 cell->car = car_val;
1094 cell->cdr = cdr_val;
1095 r = 1;
1096 }
1097 return r;
1098}
1099
1100#define TRAV_FUN_SUBTREE_DONE 0
1101#define TRAV_FUN_SUBTREE_CONTINUE 1
1102#define TRAV_FUN_SUBTREE_PROCEED 2
1103
1104typedef int (*trav_fun)(lbm_value, bool, void*);
1105
1111void lbm_ptr_rev_trav(trav_fun f, lbm_value v, void* arg);
1112
1113// lbm_uint a = lbm_heaps[0];
1114// lbm_uint b = lbm_heaps[1];
1115// lbm_uint i = (addr & LBM_PTR_TO_CONSTANT_BIT) >> LBM_PTR_TO_CONSTANT_SHIFT) - 1;
1116// lbm_uint h = (a & i) | (b & ~i);
1117
1118#ifdef LBM64
1119#define lbm_dec_as_int lbm_dec_as_i64
1120#define lbm_dec_as_uint lbm_dec_as_u64
1121#else
1122#define lbm_dec_as_int lbm_dec_as_i32
1123#define lbm_dec_as_uint lbm_dec_as_u32
1124#endif
1125
1126#ifdef __cplusplus
1127}
1128#endif
1129#endif
int32_t lbm_dec_as_i32(lbm_value val)
Definition heap.c:396
void lbm_gc_mark_continuation_stack(lbm_uint *data, lbm_uint n)
Definition heap.c:878
lbm_uint lbm_heap_size_bytes(void)
Definition heap.c:670
static bool lbm_is_error(lbm_value v)
Definition heap.h:1034
lbm_flash_status write_const_cdr(lbm_value cell, lbm_value val)
Definition heap.c:1373
static int lbm_set_car(lbm_value c, lbm_value v)
Definition heap.h:1055
lbm_value lbm_enc_double(double x)
Definition heap.c:221
const uint8_t * lbm_heap_array_get_data_ro(lbm_value arr)
Definition heap.c:1226
int64_t lbm_dec_as_i64(lbm_value val)
Definition heap.c:421
void lbm_gc_mark_env(lbm_value)
Definition heap.c:857
lbm_value lbm_set_float(lbm_value v, float x)
Definition heap.c:155
static lbm_value lbm_enc_char(uint8_t x)
Definition heap.h:784
lbm_value lbm_list_append(lbm_value list1, lbm_value list2)
Definition heap.c:1080
lbm_flash_status write_const_car(lbm_value cell, lbm_value val)
Definition heap.c:1380
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:1184
lbm_value lbm_cddr(lbm_value c)
Definition heap.c:1016
static uint32_t lbm_dec_u32(lbm_value x)
Definition heap.h:817
lbm_uint lbm_dec_custom(lbm_value val)
Definition heap.c:339
#define ERROR_SYMBOL_MASK
Definition heap.h:1026
#define lbm_dec_as_uint
Definition heap.h:1123
static lbm_value lbm_set_ptr_type(lbm_value p, lbm_type t)
Definition heap.h:710
char * lbm_dec_str(lbm_value val)
Definition heap.c:293
static bool lbm_is_cons_rw(lbm_value x)
Definition heap.h:874
static lbm_uint lbm_dec_sym(lbm_value x)
Definition heap.h:800
static bool lbm_is_symbol_nil(lbm_value exp)
Definition heap.h:907
lbm_uint lbm_get_gc_stack_max(void)
Definition heap.c:678
lbm_array_header_t * lbm_dec_array_r(lbm_value val)
Definition heap.c:314
static bool lbm_is_list_rw(lbm_value x)
Definition heap.h:1014
lbm_value lbm_enc_float(float x)
Definition heap.c:170
static lbm_uint lbm_dec_u(lbm_value x)
Definition heap.h:792
double lbm_dec_as_double(lbm_value val)
Definition heap.c:496
static bool lbm_is_array_r(lbm_value x)
Definition heap.h:940
void lbm_get_heap_state(lbm_heap_state_t *)
Definition heap.c:674
lbm_flash_status lbm_write_const_raw(lbm_uint *data, lbm_uint n, lbm_uint *res)
Definition heap.c:1341
static bool lbm_is_quoted_list(lbm_value x)
Definition heap.h:1018
#define lbm_dec_as_int
Definition heap.h:1122
lbm_value lbm_index_list(lbm_value l, int32_t n)
Definition heap.c:1107
static int lbm_set_cdr(lbm_value c, lbm_value v)
Definition heap.h:1072
lbm_value lbm_cons(lbm_value car, lbm_value cdr)
Definition heap.c:969
void lbm_gc_lock(void)
Definition heap.c:98
lbm_int lbm_heap_array_get_size(lbm_value arr)
Definition heap.c:1216
lbm_value lbm_list_copy(int *m, lbm_value list)
Definition heap.c:1053
int lbm_lift_array(lbm_value *value, char *data, lbm_uint num_elt)
Definition heap.c:1188
static bool lbm_is_symbol(lbm_value exp)
Definition heap.h:897
int(* trav_fun)(lbm_value, bool, void *)
Definition heap.h:1104
lbm_value lbm_cdr(lbm_value cons)
Definition heap.c:1008
static bool lbm_is_closure(lbm_value exp)
Definition heap.h:976
static uint8_t lbm_dec_char(lbm_value x)
Definition heap.h:796
void lbm_ptr_rev_trav(trav_fun f, lbm_value v, void *arg)
Definition heap.c:1418
static lbm_cons_t * lbm_dec_heap(lbm_value p)
Definition heap.h:705
static bool lbm_is_symbol_merror(lbm_value exp)
Definition heap.h:1006
static lbm_int lbm_dec_i(lbm_value x)
Definition heap.h:788
static lbm_value lbm_enc_i(lbm_int x)
Definition heap.h:718
void lbm_gc_state_inc(void)
Definition heap.c:962
lbm_value lbm_heap_allocate_list(lbm_uint n)
Definition heap.c:612
bool lbm_dec_str_size(lbm_value val, char **data, size_t *size)
Definition heap.c:304
int lbm_const_heap_init(const_heap_write_fun w_fun, lbm_const_heap_t *heap, lbm_uint *addr)
Definition heap.c:1280
lbm_flash_status lbm_allocate_const_raw(lbm_uint nwords, lbm_uint *res)
Definition heap.c:1328
static bool lbm_is_lisp_array_rw(lbm_value x)
Definition heap.h:958
static lbm_type lbm_type_of_functional(lbm_value x)
Definition heap.h:686
static lbm_value lbm_enc_u(lbm_uint x)
Definition heap.h:722
static bool lbm_is_constant(lbm_value x)
Definition heap.h:854
static bool lbm_heap_array_valid(lbm_value arr)
Definition heap.h:932
lbm_value lbm_caar(lbm_value c)
Definition heap.c:985
static bool lbm_is_channel(lbm_value x)
Definition heap.h:963
int lbm_heap_allocate_array(lbm_value *res, lbm_uint size)
Definition heap.c:1180
lbm_uint lbm_list_length(lbm_value c)
Definition heap.c:1027
lbm_value lbm_set_i32(lbm_value v, int32_t x)
Definition heap.c:145
uint64_t lbm_dec_u64(lbm_value x)
Definition heap.c:267
bool(* const_heap_write_fun)(lbm_uint w, lbm_uint ix)
Definition heap.h:234
void lbm_gc_unlock(void)
Definition heap.c:100
static int lbm_set_car_and_cdr(lbm_value c, lbm_value car_val, lbm_value cdr_val)
Definition heap.h:1089
lbm_value lbm_heap_allocate_list_init(unsigned int n,...)
Definition heap.c:655
static bool lbm_is_lisp_array_r(lbm_value x)
Definition heap.h:953
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:666
bool lbm_heap_init(lbm_cons_t *addr, lbm_uint num_cells, lbm_uint gc_stack_size)
Definition heap.c:577
static bool lbm_is_match_binder(lbm_value exp)
Definition heap.h:988
static bool lbm_ptr_is_constant(lbm_value x)
Definition heap.h:865
static lbm_type lbm_type_of(lbm_value x)
Definition heap.h:676
static int32_t lbm_dec_i32(lbm_value x)
Definition heap.h:831
static bool lbm_is_ptr(lbm_value x)
Definition heap.h:850
static bool lbm_is_comma_qualified_symbol(lbm_value exp)
Definition heap.h:992
static lbm_cons_t * lbm_ref_cell(lbm_value addr)
Definition heap.h:1044
uint64_t lbm_dec_as_u64(lbm_value val)
Definition heap.c:446
lbm_value lbm_car(lbm_value cons)
Definition heap.c:973
lbm_value lbm_cadr(lbm_value c)
Definition heap.c:997
lbm_uint lbm_flash_memory_usage(void)
Definition heap.c:1387
lbm_value lbm_set_u32(lbm_value v, uint32_t x)
Definition heap.c:135
static bool lbm_is_array_rw(lbm_value x)
Definition heap.h:947
lbm_value lbm_enc_u32(uint32_t x)
Definition heap.c:118
static bool lbm_is_symbol_true(lbm_value exp)
Definition heap.h:998
static bool lbm_is_continuation(lbm_value exp)
Definition heap.h:980
lbm_cons_t * lbm_heaps[2]
Definition heap.c:82
static bool lbm_is_symbol_eval(lbm_value exp)
Definition heap.h:1002
lbm_array_header_t * lbm_dec_array_rw(lbm_value val)
Definition heap.c:322
lbm_value lbm_enc_i32(int32_t x)
Definition heap.c:108
lbm_flash_status lbm_const_write(lbm_uint *tgt, lbm_uint val)
Definition heap.c:1360
static lbm_uint lbm_dec_ptr(lbm_value p)
Definition heap.h:696
void lbm_heap_new_freelist_length(void)
Definition heap.c:571
lbm_value lbm_enc_i64(int64_t x)
Definition heap.c:201
lbm_value lbm_enc_u64(uint64_t x)
Definition heap.c:211
static bool lbm_is_char(lbm_value x)
Definition heap.h:967
int lbm_gc_sweep_phase(void)
Definition heap.c:901
float lbm_dec_as_float(lbm_value val)
Definition heap.c:471
static bool lbm_is_special(lbm_value symrep)
Definition heap.h:971
static bool lbm_is_cons(lbm_value x)
Definition heap.h:885
void lbm_nil_freelist(void)
Definition heap.c:548
static lbm_value lbm_enc_cons_ptr(lbm_uint x)
Definition heap.h:692
int lbm_heap_explicit_free_array(lbm_value arr)
Definition heap.c:1252
lbm_uint lbm_get_gc_stack_size(void)
Definition heap.c:682
lbm_value lbm_list_drop(unsigned int n, lbm_value ls)
Definition heap.c:1098
lbm_uint lbm_heap_num_allocated(void)
Definition heap.c:663
void lbm_gc_mark_roots(lbm_uint *roots, lbm_uint num_roots)
Definition heap.c:892
lbm_value lbm_heap_allocate_list_init_va(unsigned int n, va_list valist)
Definition heap.c:634
static bool lbm_is_number(lbm_value x)
Definition heap.h:917
lbm_value lbm_heap_allocate_cell(lbm_type ptr_type, lbm_value car, lbm_value cdr)
Definition heap.c:596
static lbm_value lbm_enc_sym(lbm_uint s)
Definition heap.h:714
float lbm_dec_float(lbm_value x)
Definition heap.c:237
uint32_t lbm_dec_as_u32(lbm_value val)
Definition heap.c:372
lbm_value lbm_list_destructive_reverse(lbm_value list)
Definition heap.c:1037
lbm_flash_status lbm_allocate_const_cell(lbm_value *res)
Definition heap.c:1307
int64_t lbm_dec_i64(lbm_value x)
Definition heap.c:280
uint8_t lbm_dec_as_char(lbm_value a)
Definition heap.c:347
void lbm_gc_mark_phase(lbm_value root)
Definition heap.c:756
double lbm_dec_double(lbm_value x)
Definition heap.c:251
static bool lbm_is_list(lbm_value x)
Definition heap.h:1010
static bool lbm_is_macro(lbm_value exp)
Definition heap.h:984
lbm_heap_state_t lbm_heap_state
Definition heap.c:78
lbm_char_channel_t * lbm_dec_channel(lbm_value val)
Definition heap.c:330
#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