LispBM
lbm_flat_value.h
Go to the documentation of this file.
1 /*
2  Copyright 2023, 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 */
17 
18 #ifndef LBM_FLAT_VALUE_H_
19 #define LBM_FLAT_VALUE_H_
20 
21 #include <heap.h>
22 #include <symrepr.h>
23 #include <lbm_memory.h>
24 
25 typedef struct {
26  uint8_t *buf;
30  // Arity
31 #define S_CONS 0x01 // 2 car, cdr
32 #define S_SYM_VALUE 0x02 // 1 value
33 #define S_SYM_STRING 0x03
34 #define S_BYTE_VALUE 0x04
35 #define S_I28_VALUE 0x05
36 #define S_U28_VALUE 0x06
37 #define S_I32_VALUE 0x07
38 #define S_U32_VALUE 0x08
39 #define S_FLOAT_VALUE 0x09
40 #define S_I64_VALUE 0x0A
41 #define S_U64_VALUE 0x0B
42 #define S_DOUBLE_VALUE 0x0C
43 #define S_LBM_ARRAY 0x0D
44 #define S_I56_VALUE 0x0E
45 #define S_U56_VALUE 0x0F
46 #define S_LBM_LISP_ARRAY 0x1F
47 
48 // Maximum number of recursive calls
49 #define FLATTEN_VALUE_MAXIMUM_DEPTH 2000
50 
51 #define FLATTEN_VALUE_OK 0
52 #define FLATTEN_VALUE_ERROR_CANNOT_BE_FLATTENED -1
53 #define FLATTEN_VALUE_ERROR_BUFFER_TOO_SMALL -2
54 #define FLATTEN_VALUE_ERROR_ARRAY -3
55 #define FLATTEN_VALUE_ERROR_CIRCULAR -4
56 #define FLATTEN_VALUE_ERROR_MAXIMUM_DEPTH -5
57 #define FLATTEN_VALUE_ERROR_NOT_ENOUGH_MEMORY -6
58 #define FLATTEN_VALUE_ERROR_FATAL -7
59 
60 #define UNFLATTEN_MALFORMED -2
61 #define UNFLATTEN_GC_RETRY -1
62 #define UNFLATTEN_OK 0
63 
64 
65 bool lbm_start_flatten(lbm_flat_value_t *v, size_t buffer_size);
67 bool f_cons(lbm_flat_value_t *v);
68 bool f_lisp_array(lbm_flat_value_t *v, uint32_t num_elt);
69 bool f_sym(lbm_flat_value_t *v, lbm_uint sym_id);
70 bool f_sym_string(lbm_flat_value_t *v, char *str);
71 bool f_i(lbm_flat_value_t *v, lbm_int i);
72 bool f_u(lbm_flat_value_t *v, lbm_uint u);
73 bool f_b(lbm_flat_value_t *v, uint8_t b);
74 bool f_i32(lbm_flat_value_t *v, int32_t w);
75 bool f_u32(lbm_flat_value_t *v, uint32_t w);
76 bool f_float(lbm_flat_value_t *v, float f);
77 bool f_i64(lbm_flat_value_t *v, int64_t w);
78 bool f_u64(lbm_flat_value_t *v, uint64_t w);
79 bool f_lbm_array(lbm_flat_value_t *v, uint32_t num_bytes, uint8_t *data);
82 int flatten_value_size(lbm_value v, int depth);
83 void lbm_set_max_flatten_depth(int depth);
84 
92 #endif
lbm_unflatten_value
bool lbm_unflatten_value(lbm_flat_value_t *v, lbm_value *res)
Definition: lbm_flat_value.c:773
f_i
bool f_i(lbm_flat_value_t *v, lbm_int i)
Definition: lbm_flat_value.c:162
lbm_uint
uint32_t lbm_uint
Definition: lbm_types.h:48
flatten_value_size
int flatten_value_size(lbm_value v, int depth)
Definition: lbm_flat_value.c:326
f_u
bool f_u(lbm_flat_value_t *v, lbm_uint u)
Definition: lbm_flat_value.c:174
f_u64
bool f_u64(lbm_flat_value_t *v, uint64_t w)
Definition: lbm_flat_value.c:232
lbm_flat_value_t::buf
uint8_t * buf
Definition: lbm_flat_value.h:26
flatten_value_c
int flatten_value_c(lbm_flat_value_t *fv, lbm_value v)
Definition: lbm_flat_value.c:335
f_i64
bool f_i64(lbm_flat_value_t *v, int64_t w)
Definition: lbm_flat_value.c:225
f_cons
bool f_cons(lbm_flat_value_t *v)
Definition: lbm_flat_value.c:106
f_lisp_array
bool f_lisp_array(lbm_flat_value_t *v, uint32_t num_elt)
Definition: lbm_flat_value.c:115
lbm_start_flatten
bool lbm_start_flatten(lbm_flat_value_t *v, size_t buffer_size)
Definition: lbm_flat_value.c:33
lbm_flat_value_t
Definition: lbm_flat_value.h:25
lbm_flat_value_t::buf_pos
lbm_uint buf_pos
Definition: lbm_flat_value.h:28
f_sym_string
bool f_sym_string(lbm_flat_value_t *v, char *str)
Definition: lbm_flat_value.c:134
lbm_flat_value_t::buf_size
lbm_uint buf_size
Definition: lbm_flat_value.h:27
symrepr.h
lbm_set_max_flatten_depth
void lbm_set_max_flatten_depth(int depth)
Definition: lbm_flat_value.c:249
lbm_value
uint32_t lbm_value
Definition: lbm_types.h:44
lbm_int
int32_t lbm_int
Definition: lbm_types.h:49
f_sym
bool f_sym(lbm_flat_value_t *v, lbm_uint sym_id)
Definition: lbm_flat_value.c:123
lbm_finish_flatten
bool lbm_finish_flatten(lbm_flat_value_t *v)
Definition: lbm_flat_value.c:45
f_lbm_array
bool f_lbm_array(lbm_flat_value_t *v, uint32_t num_bytes, uint8_t *data)
Definition: lbm_flat_value.c:240
flatten_value
lbm_value flatten_value(lbm_value v)
Definition: lbm_flat_value.c:454
f_b
bool f_b(lbm_flat_value_t *v, uint8_t b)
Definition: lbm_flat_value.c:186
f_i32
bool f_i32(lbm_flat_value_t *v, int32_t w)
Definition: lbm_flat_value.c:193
f_u32
bool f_u32(lbm_flat_value_t *v, uint32_t w)
Definition: lbm_flat_value.c:200
heap.h
lbm_memory.h
f_float
bool f_float(lbm_flat_value_t *v, float f)
Definition: lbm_flat_value.c:207