]> gitweb.factorcode.org Git - factor.git/blob - vm/bump_allocator.hpp
vm: rewrite 'become' primitive so that it uses a slot visitor instead of GC
[factor.git] / vm / bump_allocator.hpp
1 namespace factor
2 {
3
4 template<typename Block> struct bump_allocator {
5         /* offset of 'here' and 'end' is hardcoded in compiler backends */
6         cell here;
7         cell start;
8         cell end;
9         cell size;
10
11         explicit bump_allocator(cell size_, cell start_) :
12                 here(start_), start(start_), end(start_ + size_), size(size_) {}
13
14         bool contains_p(Block *block)
15         {
16                 return ((cell)block - start) < size;
17         }
18
19         Block *allot(cell size)
20         {
21                 cell h = here;
22                 here = h + align(size,data_alignment);
23                 return (Block *)h;
24         }
25
26         cell occupied_space()
27         {
28                 return here - start;
29         }
30
31         cell free_space()
32         {
33                 return end - here;
34         }
35
36         cell next_object_after(cell scan)
37         {
38                 cell size = ((Block *)scan)->size();
39                 if(scan + size < here)
40                         return scan + size;
41                 else
42                         return 0;
43         }
44
45         cell first_object()
46         {
47                 if(start != here)
48                         return start;
49                 else
50                         return 0;
51         }
52 };
53
54 }