[16cfd8c] | 1 | extern "C" { |
---|
| 2 | #include <stdbool.h> |
---|
| 3 | #include <stdint.h> |
---|
| 4 | } |
---|
| 5 | |
---|
[73abe95] | 6 | #include <stdlib.hfa> |
---|
[16cfd8c] | 7 | |
---|
| 8 | //------------------------------------------------------------------------------ |
---|
| 9 | //Declaration |
---|
| 10 | trait allocator_c(otype T, otype allocator_t) |
---|
| 11 | { |
---|
| 12 | void ctor(allocator_t* const); |
---|
| 13 | void dtor(allocator_t* const); |
---|
| 14 | void realloc(allocator_t* const, size_t); |
---|
| 15 | T* data(allocator_t* const); |
---|
| 16 | }; |
---|
| 17 | |
---|
| 18 | forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) |
---|
| 19 | struct vector |
---|
| 20 | { |
---|
| 21 | allocator_t storage; |
---|
| 22 | size_t size; |
---|
| 23 | }; |
---|
| 24 | |
---|
| 25 | int global = 3; |
---|
| 26 | |
---|
| 27 | struct card_table_t |
---|
| 28 | { |
---|
| 29 | size_t count; |
---|
| 30 | void* cards_start[100]; |
---|
| 31 | }; |
---|
| 32 | |
---|
| 33 | static inline void ctor(card_table_t* const this) |
---|
| 34 | { |
---|
| 35 | this->count = 0; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | struct gc_memory_pool |
---|
| 39 | { |
---|
| 40 | struct memory_pool* mirror; |
---|
| 41 | struct memory_pool* next; |
---|
| 42 | |
---|
| 43 | uint8_t type_code; |
---|
| 44 | |
---|
| 45 | card_table_t* cards; |
---|
| 46 | |
---|
| 47 | uint8_t* end_p; |
---|
| 48 | uint8_t* free_p; |
---|
| 49 | uint8_t start_p[1]; |
---|
| 50 | }; |
---|
| 51 | |
---|
| 52 | void ctor( gc_memory_pool *const this, |
---|
| 53 | size_t size, |
---|
| 54 | gc_memory_pool* next, |
---|
| 55 | gc_memory_pool* mirror, |
---|
| 56 | uint8_t type |
---|
| 57 | ); |
---|
| 58 | |
---|
| 59 | void dtor(gc_memory_pool *const this); |
---|
| 60 | |
---|
| 61 | struct gc_pool_object_iterator |
---|
| 62 | { |
---|
| 63 | struct gc_object_header* object; |
---|
[46f1d20] | 64 | #ifndef NDEBUG |
---|
[16cfd8c] | 65 | intptr_t lower_limit; |
---|
| 66 | intptr_t upper_limit; |
---|
| 67 | #endif |
---|
| 68 | }; |
---|
| 69 | |
---|
| 70 | void ctor( |
---|
| 71 | gc_pool_object_iterator* const this, |
---|
| 72 | void* start_object |
---|
[46f1d20] | 73 | #ifndef NDEBUG |
---|
[16cfd8c] | 74 | , intptr_t pool_start |
---|
| 75 | , intptr_t pool_end |
---|
| 76 | #endif |
---|
| 77 | ); |
---|
| 78 | |
---|
| 79 | bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs); |
---|
| 80 | |
---|
| 81 | gc_pool_object_iterator begin(gc_memory_pool* const this); |
---|
| 82 | gc_pool_object_iterator end(gc_memory_pool* const); |
---|
| 83 | |
---|
| 84 | gc_pool_object_iterator* ++?(gc_pool_object_iterator* it); |
---|
| 85 | |
---|
| 86 | const void* *?(const gc_pool_object_iterator it); |
---|
| 87 | void* *?(gc_pool_object_iterator it); |
---|
| 88 | |
---|
| 89 | static inline bool gc_pool_is_from_space(const gc_memory_pool* pool) |
---|
| 90 | { |
---|
| 91 | return false; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | void gc_reset_pool(gc_memory_pool* const pool); |
---|
| 95 | |
---|
| 96 | static inline size_t gc_pool_size_used(const gc_memory_pool* pool) |
---|
| 97 | { |
---|
| 98 | return pool->free_p - pool->start_p; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | static inline size_t gc_pool_size_total(const gc_memory_pool* pool) |
---|
| 102 | { |
---|
| 103 | return pool->end_p - pool->start_p; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | static inline size_t gc_pool_size_left(const gc_memory_pool* pool) |
---|
| 107 | { |
---|
| 108 | return pool->end_p - pool->free_p; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | void* gc_pool_allocate(gc_memory_pool* const pool, size_t size, bool zero); |
---|
| 112 | |
---|
| 113 | gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const pool, void* member); |
---|
| 114 | |
---|
| 115 | void ctor(gc_memory_pool *const this, size_t size, gc_memory_pool* next, gc_memory_pool* mirror, uint8_t type) |
---|
| 116 | { |
---|
| 117 | this->mirror = mirror; |
---|
| 118 | this->next = next; |
---|
| 119 | this->type_code = type; |
---|
| 120 | |
---|
| 121 | this->cards = malloc(); |
---|
| 122 | ctor(this->cards); |
---|
| 123 | |
---|
| 124 | this->end_p = ((uint8_t*)this) + size; |
---|
| 125 | this->free_p = this->start_p; |
---|
| 126 | |
---|
| 127 | // check(gc_pool_of(this) == this); |
---|
| 128 | // check(this->cards); |
---|
| 129 | // gc_reset_pool(this); |
---|
| 130 | } |
---|