GCC Code Coverage Report
Directory: ../src/ Exec Total Coverage
File: /home/joels/Current/lispbm/src/lbm_custom_type.c Lines: 14 17 82.4 %
Date: 2024-12-26 17:59:19 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
448
bool lbm_custom_type_create(lbm_uint value, custom_type_destructor fptr, const char *desc, lbm_value *result) {
24
25
448
  lbm_uint *t = lbm_memory_allocate(3);
26
27
✗✓
448
  if (t == NULL) return false;
28
29
448
  t[CUSTOM_TYPE_VALUE] = value;
30
448
  t[CUSTOM_TYPE_DESCRIPTOR] = (lbm_uint)desc;
31
448
  t[CUSTOM_TYPE_DESTRUCTOR] = (lbm_uint)fptr;
32
33
448
  lbm_value cell = lbm_heap_allocate_cell(LBM_TYPE_CUSTOM, (lbm_uint) t, ENC_SYM_CUSTOM_TYPE);
34
✗✓
448
  if (cell == ENC_SYM_MERROR) {
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
448
  *result = cell;
43
44
448
  return true;
45
}
46
47
28
bool lbm_custom_type_destroy(lbm_uint *lbm_mem_ptr) {
48
49
28
  lbm_uint value = lbm_mem_ptr[CUSTOM_TYPE_VALUE];
50
28
  custom_type_destructor destruct = (custom_type_destructor)lbm_mem_ptr[CUSTOM_TYPE_DESTRUCTOR];
51
28
  return destruct(value);
52
}