GCC Code Coverage Report


Directory: ../src/
File: /home/joels/Current/lispbm/src/lbm_custom_type.c
Date: 2024-08-06 17:32:21
Exec Total Coverage
Lines: 10 17 58.8%
Functions: 1 2 50.0%
Branches: 2 4 50.0%

Line Branch Exec Source
1 /*
2 Copyright 2022 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 #include <lbm_custom_type.h>
19 #include <heap.h>
20 #include <lbm_memory.h>
21
22
23 364 bool lbm_custom_type_create(lbm_uint value, custom_type_destructor fptr, const char *desc, lbm_value *result) {
24
25 364 lbm_uint *t = lbm_memory_allocate(3);
26
27
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 364 times.
364 if (t == NULL) return false;
28
29 364 t[CUSTOM_TYPE_VALUE] = value;
30 364 t[CUSTOM_TYPE_DESCRIPTOR] = (lbm_uint)desc;
31 364 t[CUSTOM_TYPE_DESTRUCTOR] = (lbm_uint)fptr;
32
33 364 lbm_value cell = lbm_heap_allocate_cell(LBM_TYPE_CUSTOM, (lbm_uint) t, ENC_SYM_CUSTOM_TYPE);
34
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 364 times.
364 if (lbm_type_of(cell) == LBM_TYPE_SYMBOL) {
35 *result = cell;
36 lbm_memory_free(t);
37 return false;
38 }
39 // lbm_set_car(cell, (lbm_uint)t);
40 //lbm_set_cdr(cell, lbm_enc_sym(SYM_CUSTOM_TYPE));
41 //cell = lbm_set_ptr_type(cell, LBM_TYPE_CUSTOM);
42 364 *result = cell;
43
44 364 return true;
45 }
46
47 bool lbm_custom_type_destroy(lbm_uint *lbm_mem_ptr) {
48
49 lbm_uint value = lbm_mem_ptr[CUSTOM_TYPE_VALUE];
50 custom_type_destructor destruct = (custom_type_destructor)lbm_mem_ptr[CUSTOM_TYPE_DESTRUCTOR];
51 return destruct(value);
52 }
53