aboutsummaryrefslogtreecommitdiffstats
path: root/include/cheney_c89.h
blob: c6caa66821658a89c198673f6654b423912dcb47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* Copyright (C) 2024 Peter McGoron
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program. If not, see
 * <https://www.gnu.org/licenses/>.
*/

#ifndef UNS_CHENEY_C89_H
#define UNS_CHENEY_C89_H

#include "uns.h"

/* Cheney copying collector in pure portable C89.
 *
 * The copying collector does not support weak references or mixed
 * records. Every collection calls malloc() to obtain a new heap.
 *
 * This collector is useful for hosted implementations that want a 
 * resizable heap.
 */

struct uns_cheney_c89_statistics {
	size_t usage_before;
	size_t usage_after;
	size_t collection_number;
};

typedef void (*uns_cheney_c89_collect_callback)
	(Uns_GC, struct uns_cheney_c89_statistics *)
;

void uns_cheney_c89_set_new_heap_size(Uns_GC gc, size_t siz);
size_t uns_cheney_c89_get_new_heap_size(Uns_GC gc);
void uns_cheney_c89_set_collect_callback(
	Uns_GC gc,
	uns_cheney_c89_collect_callback cb
);

void *uns_cheney_c89_get(Uns_ptr p, size_t loc,
                         enum uns_fld_type *typ);
void uns_cheney_c89_set(Uns_ptr p, size_t loc,
                        enum uns_fld_type typ, void *newp);

void uns_cheney_c89_deinit(Uns_GC gc);
int uns_cheney_c89_collect(Uns_GC gc);
void *uns_cheney_c89_alloc(Uns_GC gc, size_t elems,
                           enum uns_bytes_type typ);
void *uns_cheney_c89_alloc_rec(Uns_GC gc, size_t elems,
                               enum uns_record_type typ);
int uns_cheney_c89_init(Uns_GC gc, size_t heap_size);

const extern size_t uns_cheney_c89_ctx_size;

#endif