VM: Refactor bump_allocator.hpp to Factor style
parent
774326b2dc
commit
1e618e16ee
|
@ -1,5 +1,4 @@
|
||||||
namespace factor
|
namespace factor {
|
||||||
{
|
|
||||||
|
|
||||||
template <typename Block> struct bump_allocator {
|
template <typename Block> struct bump_allocator {
|
||||||
/* offset of 'here' and 'end' is hardcoded in compiler backends */
|
/* offset of 'here' and 'end' is hardcoded in compiler backends */
|
||||||
|
@ -8,33 +7,22 @@ template<typename Block> struct bump_allocator {
|
||||||
cell end;
|
cell end;
|
||||||
cell size;
|
cell size;
|
||||||
|
|
||||||
explicit bump_allocator(cell size_, cell start_) :
|
explicit bump_allocator(cell size_, cell start_)
|
||||||
here(start_), start(start_), end(start_ + size_), size(size_) {}
|
: here(start_), start(start_), end(start_ + size_), size(size_) {}
|
||||||
|
|
||||||
bool contains_p(Block *block)
|
bool contains_p(Block* block) { return ((cell) block - start) < size; }
|
||||||
{
|
|
||||||
return ((cell)block - start) < size;
|
|
||||||
}
|
|
||||||
|
|
||||||
Block *allot(cell size)
|
Block* allot(cell size) {
|
||||||
{
|
|
||||||
cell h = here;
|
cell h = here;
|
||||||
here = h + align(size, data_alignment);
|
here = h + align(size, data_alignment);
|
||||||
return (Block*)h;
|
return (Block*)h;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell occupied_space()
|
cell occupied_space() { return here - start; }
|
||||||
{
|
|
||||||
return here - start;
|
|
||||||
}
|
|
||||||
|
|
||||||
cell free_space()
|
cell free_space() { return end - here; }
|
||||||
{
|
|
||||||
return end - here;
|
|
||||||
}
|
|
||||||
|
|
||||||
cell next_object_after(cell scan)
|
cell next_object_after(cell scan) {
|
||||||
{
|
|
||||||
cell size = ((Block*)scan)->size();
|
cell size = ((Block*)scan)->size();
|
||||||
if (scan + size < here)
|
if (scan + size < here)
|
||||||
return scan + size;
|
return scan + size;
|
||||||
|
@ -42,8 +30,7 @@ template<typename Block> struct bump_allocator {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell first_object()
|
cell first_object() {
|
||||||
{
|
|
||||||
if (start != here)
|
if (start != here)
|
||||||
return start;
|
return start;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue