i really should run a test
parent
9ff86161bb
commit
c7bb4a434b
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.25)
|
cmake_minimum_required(VERSION 3.25)
|
||||||
project(blt-gp VERSION 0.0.83)
|
project(blt-gp VERSION 0.0.84)
|
||||||
|
|
||||||
include(CTest)
|
include(CTest)
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace blt::gp
|
||||||
{
|
{
|
||||||
blt::size_t offset = 0;
|
blt::size_t offset = 0;
|
||||||
blt::size_t current_index = 0;
|
blt::size_t current_index = 0;
|
||||||
((offset += (current_index++ > index ? stack_allocator::aligned_size<Args>() : 0)), ...);
|
((offset += (current_index++ > index ? stack_allocator::aligned_size<detail::remove_cv_ref<Args>>() : 0)), ...);
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,8 @@ namespace blt::gp
|
||||||
ExtraArgs&& ... args)
|
ExtraArgs&& ... args)
|
||||||
{
|
{
|
||||||
// expands Args and indices, providing each argument with its index calculating the current argument byte offset
|
// expands Args and indices, providing each argument with its index calculating the current argument byte offset
|
||||||
return std::forward<Func>(func)(std::forward<ExtraArgs>(args)..., allocator.from<Args>(getByteOffset<indices>())...);
|
return std::forward<Func>(func)(std::forward<ExtraArgs>(args)...,
|
||||||
|
allocator.from<detail::remove_cv_ref<Args>>(getByteOffset<indices>())...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Func, typename... ExtraArgs>
|
template<typename Func, typename... ExtraArgs>
|
||||||
|
@ -95,8 +96,8 @@ namespace blt::gp
|
||||||
{
|
{
|
||||||
constexpr auto seq = std::make_integer_sequence<blt::u64, sizeof...(Args)>();
|
constexpr auto seq = std::make_integer_sequence<blt::u64, sizeof...(Args)>();
|
||||||
Return ret = exec_sequence_to_indices(std::forward<Func>(func), read_allocator, seq, std::forward<ExtraArgs>(args)...);
|
Return ret = exec_sequence_to_indices(std::forward<Func>(func), read_allocator, seq, std::forward<ExtraArgs>(args)...);
|
||||||
read_allocator.call_destructors<Args...>();
|
read_allocator.call_destructors<detail::remove_cv_ref<Args>...>();
|
||||||
read_allocator.pop_bytes((stack_allocator::aligned_size<Args>() + ...));
|
read_allocator.pop_bytes((stack_allocator::aligned_size<detail::remove_cv_ref<Args>>() + ...));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -114,7 +114,7 @@ namespace blt::gp
|
||||||
|
|
||||||
if constexpr (sizeof...(Args) > 0)
|
if constexpr (sizeof...(Args) > 0)
|
||||||
{
|
{
|
||||||
(add_non_context_argument<Args>(info.argument_types), ...);
|
(add_non_context_argument<detail::remove_cv_ref<Args>>(info.argument_types), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
info.argc.argc_context = info.argc.argc = sizeof...(Args);
|
info.argc.argc_context = info.argc.argc = sizeof...(Args);
|
||||||
|
|
|
@ -52,8 +52,8 @@ namespace blt::gp
|
||||||
{
|
{
|
||||||
for (blt::size_t i = 0; i < config.elites; i++)
|
for (blt::size_t i = 0; i < config.elites; i++)
|
||||||
{
|
{
|
||||||
BLT_INFO("%lf >= %lf? // %lf (indexes: %ld %ld)", ind.second.fitness.adjusted_fitness, values[i].second,
|
// BLT_INFO("%lf >= %lf? // %lf (indexes: %ld %ld)", ind.second.fitness.adjusted_fitness, values[i].second,
|
||||||
ind.second.fitness.raw_fitness, ind.first, values[i].first);
|
// ind.second.fitness.raw_fitness, ind.first, values[i].first);
|
||||||
if (ind.second.fitness.adjusted_fitness >= values[i].second)
|
if (ind.second.fitness.adjusted_fitness >= values[i].second)
|
||||||
{
|
{
|
||||||
bool doesnt_contain = true;
|
bool doesnt_contain = true;
|
||||||
|
|
|
@ -108,7 +108,7 @@ namespace blt::gp
|
||||||
|
|
||||||
void push_block()
|
void push_block()
|
||||||
{
|
{
|
||||||
block * block;
|
block* block;
|
||||||
if (deallocated_blocks.empty())
|
if (deallocated_blocks.empty())
|
||||||
block = allocate_block();
|
block = allocate_block();
|
||||||
else
|
else
|
||||||
|
@ -141,6 +141,8 @@ namespace blt::gp
|
||||||
{
|
{
|
||||||
constexpr static blt::size_t PAGE_SIZE = 0x1000;
|
constexpr static blt::size_t PAGE_SIZE = 0x1000;
|
||||||
constexpr static blt::size_t MAX_ALIGNMENT = 8;
|
constexpr static blt::size_t MAX_ALIGNMENT = 8;
|
||||||
|
template<typename T>
|
||||||
|
using NO_REF_T = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||||
public:
|
public:
|
||||||
struct size_data_t
|
struct size_data_t
|
||||||
{
|
{
|
||||||
|
@ -160,30 +162,30 @@ namespace blt::gp
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void push(T&& value)
|
void push(T&& value)
|
||||||
{
|
{
|
||||||
using NO_REF_T = std::remove_reference_t<T>;
|
using NO_REF_T = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||||
static_assert(std::is_trivially_copyable_v<NO_REF_T> && "Type must be bitwise copyable!");
|
static_assert(std::is_trivially_copyable_v<NO_REF_T> && "Type must be bitwise copyable!");
|
||||||
auto ptr = allocate_bytes<T>();
|
auto ptr = allocate_bytes<NO_REF_T>();
|
||||||
head->metadata.offset = static_cast<blt::u8*>(ptr) + aligned_size<T>();
|
head->metadata.offset = static_cast<blt::u8*>(ptr) + aligned_size<NO_REF_T>();
|
||||||
new(ptr) NO_REF_T(std::forward<T>(value));
|
new(ptr) NO_REF_T(std::forward<T>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T pop()
|
T pop()
|
||||||
{
|
{
|
||||||
using NO_REF_T = std::remove_reference_t<T>;
|
using NO_REF_T = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||||
static_assert(std::is_trivially_copyable_v<NO_REF_T> && "Type must be bitwise copyable!");
|
static_assert(std::is_trivially_copyable_v<NO_REF_T> && "Type must be bitwise copyable!");
|
||||||
constexpr static auto TYPE_SIZE = aligned_size<T>();
|
constexpr static auto TYPE_SIZE = aligned_size<NO_REF_T>();
|
||||||
if (head == nullptr)
|
if (head == nullptr)
|
||||||
throw std::runtime_error("Silly boi the stack is empty!");
|
throw std::runtime_error("Silly boi the stack is empty!");
|
||||||
if (head->used_bytes_in_block() < static_cast<blt::ptrdiff_t>(aligned_size<T>()))
|
if (head->used_bytes_in_block() < static_cast<blt::ptrdiff_t>(aligned_size<T>()))
|
||||||
throw std::runtime_error((std::string("Mismatched Types! Not enough space left in block! Bytes: ") += std::to_string(
|
throw std::runtime_error((std::string("Mismatched Types! Not enough space left in block! Bytes: ") += std::to_string(
|
||||||
head->used_bytes_in_block()) += " Size: " + std::to_string(sizeof(T))).c_str());
|
head->used_bytes_in_block()) += " Size: " + std::to_string(sizeof(NO_REF_T))).c_str());
|
||||||
if (head->used_bytes_in_block() == 0)
|
if (head->used_bytes_in_block() == 0)
|
||||||
move_back();
|
move_back();
|
||||||
// make copy
|
// make copy
|
||||||
T t = *reinterpret_cast<T*>(head->metadata.offset - TYPE_SIZE);
|
NO_REF_T t = *reinterpret_cast<NO_REF_T*>(head->metadata.offset - TYPE_SIZE);
|
||||||
// call destructor
|
// call destructor
|
||||||
reinterpret_cast<T*>(head->metadata.offset - TYPE_SIZE)->~T();
|
reinterpret_cast<NO_REF_T*>(head->metadata.offset - TYPE_SIZE)->~NO_REF_T();
|
||||||
// move offset back
|
// move offset back
|
||||||
head->metadata.offset -= TYPE_SIZE;
|
head->metadata.offset -= TYPE_SIZE;
|
||||||
return t;
|
return t;
|
||||||
|
@ -192,7 +194,8 @@ namespace blt::gp
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& from(blt::size_t bytes)
|
T& from(blt::size_t bytes)
|
||||||
{
|
{
|
||||||
constexpr static auto TYPE_SIZE = aligned_size<T>();
|
using NO_REF_T = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||||
|
constexpr static auto TYPE_SIZE = aligned_size<NO_REF_T>();
|
||||||
auto remaining_bytes = static_cast<blt::i64>(bytes);
|
auto remaining_bytes = static_cast<blt::i64>(bytes);
|
||||||
blt::i64 bytes_into_block = 0;
|
blt::i64 bytes_into_block = 0;
|
||||||
block* blk = head;
|
block* blk = head;
|
||||||
|
@ -211,10 +214,10 @@ namespace blt::gp
|
||||||
}
|
}
|
||||||
if (blk == nullptr)
|
if (blk == nullptr)
|
||||||
throw std::runtime_error("Some nonsense is going on. This function already smells");
|
throw std::runtime_error("Some nonsense is going on. This function already smells");
|
||||||
if (blk->used_bytes_in_block() < static_cast<blt::ptrdiff_t>(aligned_size<T>()))
|
if (blk->used_bytes_in_block() < static_cast<blt::ptrdiff_t>(TYPE_SIZE))
|
||||||
throw std::runtime_error((std::string("Mismatched Types! Not enough space left in block! Bytes: ") += std::to_string(
|
throw std::runtime_error((std::string("Mismatched Types! Not enough space left in block! Bytes: ") += std::to_string(
|
||||||
blk->used_bytes_in_block()) += " Size: " + std::to_string(sizeof(T))).c_str());
|
blk->used_bytes_in_block()) += " Size: " + std::to_string(sizeof(NO_REF_T))).c_str());
|
||||||
return *reinterpret_cast<T*>((blk->metadata.offset - bytes_into_block) - TYPE_SIZE);
|
return *reinterpret_cast<NO_REF_T*>((blk->metadata.offset - bytes_into_block) - TYPE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop_bytes(blt::ptrdiff_t bytes)
|
void pop_bytes(blt::ptrdiff_t bytes)
|
||||||
|
@ -264,13 +267,13 @@ namespace blt::gp
|
||||||
*/
|
*/
|
||||||
void transfer_bytes(stack_allocator& to, blt::size_t bytes)
|
void transfer_bytes(stack_allocator& to, blt::size_t bytes)
|
||||||
{
|
{
|
||||||
|
while (!empty() && head->used_bytes_in_block() == 0)
|
||||||
|
move_back();
|
||||||
if (empty())
|
if (empty())
|
||||||
throw std::runtime_error("This stack is empty!");
|
throw std::runtime_error("This stack is empty!");
|
||||||
if (head->used_bytes_in_block() < static_cast<blt::ptrdiff_t>(bytes))
|
if (head->used_bytes_in_block() < static_cast<blt::ptrdiff_t>(bytes))
|
||||||
BLT_ABORT("This stack doesn't contain enough data for this type! This is an invalid runtime state!");
|
BLT_ABORT(("This stack doesn't contain enough data for this type! " + std::to_string(head->used_bytes_in_block()) + " / " +
|
||||||
|
std::to_string(bytes) + " This is an invalid runtime state!").c_str());
|
||||||
if (head->used_bytes_in_block() == 0)
|
|
||||||
move_back();
|
|
||||||
|
|
||||||
auto type_size = aligned_size(bytes);
|
auto type_size = aligned_size(bytes);
|
||||||
auto ptr = to.allocate_bytes(bytes);
|
auto ptr = to.allocate_bytes(bytes);
|
||||||
|
@ -283,7 +286,8 @@ namespace blt::gp
|
||||||
void call_destructors()
|
void call_destructors()
|
||||||
{
|
{
|
||||||
blt::size_t offset = 0;
|
blt::size_t offset = 0;
|
||||||
((from<Args>(offset).~Args(), offset += stack_allocator::aligned_size<Args>()), ...);
|
|
||||||
|
((from<NO_REF_T<Args>>(offset).~NO_REF_T<Args>(), offset += stack_allocator::aligned_size<NO_REF_T<Args>>()), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool empty() const
|
[[nodiscard]] bool empty() const
|
||||||
|
@ -374,7 +378,7 @@ namespace blt::gp
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline constexpr blt::size_t aligned_size() noexcept
|
static inline constexpr blt::size_t aligned_size() noexcept
|
||||||
{
|
{
|
||||||
return aligned_size(sizeof(T));
|
return aligned_size(sizeof(NO_REF_T<T>));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline constexpr blt::size_t aligned_size(blt::size_t size) noexcept
|
static inline constexpr blt::size_t aligned_size(blt::size_t size) noexcept
|
||||||
|
@ -431,7 +435,7 @@ namespace blt::gp
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void* allocate_bytes()
|
void* allocate_bytes()
|
||||||
{
|
{
|
||||||
return allocate_bytes(sizeof(T));
|
return allocate_bytes(sizeof(NO_REF_T<T>));
|
||||||
}
|
}
|
||||||
|
|
||||||
void* allocate_bytes(blt::size_t size)
|
void* allocate_bytes(blt::size_t size)
|
||||||
|
@ -506,10 +510,7 @@ namespace blt::gp
|
||||||
auto old = head;
|
auto old = head;
|
||||||
head = head->metadata.prev;
|
head = head->metadata.prev;
|
||||||
if (head == nullptr)
|
if (head == nullptr)
|
||||||
{
|
|
||||||
head = old;
|
head = old;
|
||||||
head->reset();
|
|
||||||
}
|
|
||||||
//free_chain(old);
|
//free_chain(old);
|
||||||
// required to prevent silly memory :3
|
// required to prevent silly memory :3
|
||||||
// if (head != nullptr)
|
// if (head != nullptr)
|
||||||
|
|
Loading…
Reference in New Issue