diff --git a/CMakeLists.txt b/CMakeLists.txt index abbfd4d..a82f75c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.88) +project(blt-gp VERSION 0.0.89) include(CTest) diff --git a/include/blt/gp/program.h b/include/blt/gp/program.h index 738471a..6bbdeaf 100644 --- a/include/blt/gp/program.h +++ b/include/blt/gp/program.h @@ -414,7 +414,7 @@ namespace blt::gp [[nodiscard]] bool should_thread_terminate() const { - return should_terminate() || thread_helper.lifetime_over; + return thread_helper.lifetime_over; } [[nodiscard]] random_t& get_random() const; diff --git a/include/blt/gp/stack.h b/include/blt/gp/stack.h index e4896d0..9121f96 100644 --- a/include/blt/gp/stack.h +++ b/include/blt/gp/stack.h @@ -227,19 +227,22 @@ namespace blt::gp T& from(blt::size_t bytes) { using NO_REF_T = std::remove_cv_t>; + constexpr static auto TYPE_SIZE = aligned_size(); - auto remaining_bytes = static_cast(bytes); - blt::i64 bytes_into_block = 0; + + auto remaining_bytes = static_cast(bytes + TYPE_SIZE); + block* blk = head; while (remaining_bytes > 0) { if (blk == nullptr) throw std::runtime_error("Requested size is beyond the scope of this stack!"); + auto bytes_available = blk->used_bytes_in_block() - remaining_bytes; - bytes_into_block = remaining_bytes; + if (bytes_available < 0) { - remaining_bytes = -bytes_available; + remaining_bytes -= blk->used_bytes_in_block(); blk = head->metadata.prev; } else break; @@ -249,7 +252,7 @@ namespace blt::gp if (blk->used_bytes_in_block() < static_cast(TYPE_SIZE)) 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(NO_REF_T))).c_str()); - return *reinterpret_cast((blk->metadata.offset - bytes_into_block) - TYPE_SIZE); + return *reinterpret_cast(blk->metadata.offset - remaining_bytes); } void pop_bytes(blt::ptrdiff_t bytes)