2009-10-07 12:59:59 -04:00
|
|
|
namespace factor
|
|
|
|
{
|
|
|
|
|
2009-10-20 23:20:49 -04:00
|
|
|
template<typename Block> struct bump_allocator {
|
2009-10-14 03:06:01 -04:00
|
|
|
/* offset of 'here' and 'end' is hardcoded in compiler backends */
|
2009-10-07 12:59:59 -04:00
|
|
|
cell here;
|
2009-10-14 03:06:01 -04:00
|
|
|
cell start;
|
2009-10-07 12:59:59 -04:00
|
|
|
cell end;
|
2009-10-14 03:06:01 -04:00
|
|
|
cell size;
|
2009-10-07 12:59:59 -04:00
|
|
|
|
2009-10-20 16:15:05 -04:00
|
|
|
bump_allocator(cell size_, cell start_) :
|
2009-10-20 23:20:49 -04:00
|
|
|
here(start_), start(start_), end(start_ + size_), size(size_) {}
|
2009-10-07 12:59:59 -04:00
|
|
|
|
2009-10-20 23:20:49 -04:00
|
|
|
inline bool contains_p(Block *block)
|
2009-10-07 12:59:59 -04:00
|
|
|
{
|
2009-10-20 23:20:49 -04:00
|
|
|
return ((cell)block - start) < size;
|
2009-10-07 12:59:59 -04:00
|
|
|
}
|
|
|
|
|
2009-10-20 23:20:49 -04:00
|
|
|
inline Block *allot(cell size)
|
2009-10-07 12:59:59 -04:00
|
|
|
{
|
|
|
|
cell h = here;
|
2009-10-20 13:45:00 -04:00
|
|
|
here = h + align(size,data_alignment);
|
2009-10-20 23:20:49 -04:00
|
|
|
return (Block *)h;
|
2009-10-20 14:47:04 -04:00
|
|
|
}
|
2009-10-07 12:59:59 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|