this repo has no description

Deduplicate space functions a bit

authored by bernsteinbear.com and committed by

Max Bernstein 786a151f d235b060

+12 -15
+12 -15
runtime.c
··· 131 131 } 132 132 133 133 #ifdef STATIC_HEAP 134 - #define make_space(mem, sz) \ 135 - (struct space) { .start = (uintptr_t)mem, .size = sz } 136 - void init_heap(struct gc_heap* heap, struct space space) { 137 - if (align(space.size, kPageSize) != space.size) { 138 - fprintf(stderr, "static heap size (%lu) must be a multiple of %lu\n", 139 - space.size, kPageSize); 140 - abort(); 141 - } 142 - heap->size = space.size; 143 - heap->to_space = heap->hp = space.start; 144 - heap->from_space = heap->limit = heap->hp + space.size / 2; 134 + struct space make_space(void* mem, uintptr_t size) { 135 + return (struct space){(uintptr_t)mem, size}; 145 136 } 146 137 void destroy_space(struct space space) {} 147 138 #else ··· 155 146 } 156 147 return (struct space){(uintptr_t)mem, size}; 157 148 } 149 + void destroy_space(struct space space) { 150 + munmap((void*)space.start, space.size); 151 + } 152 + #endif 153 + 158 154 void init_heap(struct gc_heap* heap, struct space space) { 155 + if (align(space.size, kPageSize) != space.size) { 156 + fprintf(stderr, "heap size (%lu) must be a multiple of %lu\n", 157 + space.size, kPageSize); 158 + abort(); 159 + } 159 160 heap->size = space.size; 160 161 heap->to_space = heap->hp = space.start; 161 162 heap->from_space = heap->limit = heap->hp + space.size / 2; 162 163 } 163 - void destroy_space(struct space space) { 164 - munmap((void*)space.start, space.size); 165 - } 166 - #endif 167 164 168 165 struct gc_obj* copy(struct gc_heap* heap, struct gc_obj* obj) { 169 166 size_t size = heap_object_size(obj);