blob: 7cd9e199ac09cfaf0081fbfe330609376f0b14aa (
plain)
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
|
#include "../../../patio/patio.h"
#include "../../gc.h"
#include "../../memory.h"
#define MAX(a,b) (((a)>(b))?(a):(b))
void* ptr = NULL;
intptr_t remaining = 0;
// == Initialization ==
void shed__runtime__gc_init(void) {
ptr = shed__runtime__memory_init(sizeof(PatioInt));
}
// == Allocation ==
void* shed__runtime__gc_alloc(size_t size, uint32_t runtime_type_tag) {
if (size % sizeof(PatioInt) != 0) {
size = size + (sizeof(PatioInt) - size % sizeof(PatioInt));
}
if (remaining < size) {
// TODO: what should we grow by?
intptr_t increment = MAX(1024 * 1024, size);
// TODO: check for -1 from shed__runtime__memory_grow
// TODO: shed__runtime__memory_grow may grow by more than requested amount.
// Return the amount of allocated memory?
shed__runtime__memory_grow(increment);
remaining += increment;
}
struct ShedGcObjectHeader* object = ptr;
ptr += size;
remaining -= size;
object->runtime_type_tag = runtime_type_tag;
return object;
}
// == Collection ==
void shed__runtime__gc_collect(void) {
}
// == Clearing ==
void shed__runtime__gc_clear(void) {
shed__runtime__gc_clear_roots();
}
|