]> gitweb.factorcode.org Git - factor.git/blob - vm/gc_info.hpp
webapps: better style
[factor.git] / vm / gc_info.hpp
1 namespace factor {
2
3 // gc_info should be kept in sync with:
4 //   basis/compiler/codegen/gc-maps/gc-maps.factor
5 //   basis/vm/vm.factor
6 struct gc_info {
7   uint32_t gc_root_count;
8   uint32_t derived_root_count;
9   uint32_t return_address_count;
10
11   cell callsite_bitmap_size() {
12     return gc_root_count;
13   }
14
15   cell total_bitmap_size() {
16     return return_address_count * callsite_bitmap_size();
17   }
18
19   cell total_bitmap_bytes() { return ((total_bitmap_size() + 7) / 8); }
20
21   uint32_t* return_addresses() {
22     return (uint32_t*)this - return_address_count;
23   }
24
25   uint32_t* base_pointer_map() {
26     return return_addresses() - return_address_count * derived_root_count;
27   }
28
29   uint8_t* gc_info_bitmap() {
30     return (uint8_t*)base_pointer_map() - total_bitmap_bytes();
31   }
32
33
34   cell callsite_gc_roots(cell index) {
35     return index * gc_root_count;
36   }
37
38   uint32_t lookup_base_pointer(cell index, cell derived_root) {
39     return base_pointer_map()[index * derived_root_count + derived_root];
40   }
41
42   cell return_address_index(cell return_address) {
43     uint32_t* return_address_array = return_addresses();
44
45     for (cell i = 0; i < return_address_count; i++) {
46       if (return_address == return_address_array[i])
47         return i;
48     }
49
50     return (cell)-1;
51   }
52 };
53
54 }