+ xo-alloc + xo-object + xo-alloc docs + GC utests

This commit is contained in:
Roland Conybeare 2025-08-03 15:59:38 -05:00
commit 5f46b51f12
32 changed files with 2903 additions and 82 deletions

54
src/alloc/IAlloc.cpp Normal file
View file

@ -0,0 +1,54 @@
/* @file IAlloc.cpp
*
* author: Roland Conybeare, Aug 2025
*/
#include "IAlloc.hpp"
#include <cassert>
#include <cstddef>
namespace xo {
namespace gc {
std::uint32_t
IAlloc::alloc_padding(std::size_t z)
{
/* word size for alignment */
constexpr uint32_t c_bpw = sizeof(std::uintptr_t);
/* round up to multiple of c_bpw, but map 0 -> 0
* (table assuming c_bpw==8)
*
* z%c_bpw dz
* ------------
* 0 0
* 1 7
* 2 6
* .. ..
* 7 1
*/
std::uint32_t dz = (c_bpw - (z % c_bpw)) % c_bpw;
z += dz;
assert(z % c_bpw == 0ul);
return dz;
}
std::size_t
IAlloc::with_padding(std::size_t z)
{
return z + alloc_padding(z);
}
std::byte *
IAlloc::alloc_gc_copy(std::size_t /*z*/, const void * /*src*/)
{
assert(false);
return nullptr;
}
} /*namespace gc*/
} /*namespace xo*/
/* end IAlloc.cpp */