diff --git a/CMakeLists.txt b/CMakeLists.txt index e685b9b..5366daf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.96) +project(blt-gp VERSION 0.0.97) include(CTest) diff --git a/include/blt/gp/stack.h b/include/blt/gp/stack.h index 56cbbcb..f723bfb 100644 --- a/include/blt/gp/stack.h +++ b/include/blt/gp/stack.h @@ -117,6 +117,8 @@ namespace blt::gp reinterpret_cast(head->metadata.offset - TYPE_SIZE)->~NO_REF_T(); // move offset back head->metadata.offset -= TYPE_SIZE; + // moving back allows us to allocate with other data, if there is room. + while (head->used_bytes_in_block() == 0 && move_back()); return t; } @@ -189,6 +191,7 @@ namespace blt::gp break; } } + while (head->used_bytes_in_block() == 0 && move_back()); } /** @@ -212,6 +215,7 @@ namespace blt::gp to.head->metadata.offset = static_cast(ptr) + type_size; std::memcpy(ptr, head->metadata.offset - type_size, type_size); head->metadata.offset -= type_size; + while (head->used_bytes_in_block() == 0 && move_back()); } template diff --git a/tests/stack_tests.cpp b/tests/stack_tests.cpp index 54b1652..2fca4e4 100644 --- a/tests/stack_tests.cpp +++ b/tests/stack_tests.cpp @@ -52,9 +52,9 @@ large_##SIZE tertiary_##SIZE = make_data(large_##SIZE{}, [](auto index) { return static_cast(blt::random::murmur_random64c(SEED + index, 0, 256)); \ }) -#define RUN_TEST(FAILURE_COND, PASS, ...) do { if (FAILURE_COND) { BLT_ERROR(__VA_ARGS__); } else { BLT_DEBUG(PASS); } } while(false) -#define RUN_TEST_SIZE(VALUE, SIZE, STACK) RUN_TEST(auto index = compare(VALUE, STACK.pop()); index >= 0, #SIZE " Test PASSED.", "Failed to pop large value (" #SIZE "), failed at index %ld", index) -#define RUN_TEST_TYPE(TYPE, EXPECTED, STACK) RUN_TEST(auto val = STACK.pop(); val != EXPECTED, #TYPE " test PASSED", "Failed to pop correct " #TYPE " (" #EXPECTED ") found %lf", val); +#define RUN_TEST(FAILURE_COND, STACK, PASS, ...) do { if (FAILURE_COND) { BLT_ERROR(__VA_ARGS__); } else { BLT_DEBUG_STREAM << PASS << " | " << STACK.size() << "\n"; } } while(false) +#define RUN_TEST_SIZE(VALUE, SIZE, STACK) RUN_TEST(auto index = compare(VALUE, STACK.pop()); index >= 0, STACK, #SIZE " test PASSED.", "Failed to pop large value (" #SIZE "), failed at index %ld", index) +#define RUN_TEST_TYPE(TYPE, EXPECTED, STACK) RUN_TEST(auto val = STACK.pop(); val != EXPECTED, STACK, #TYPE " test PASSED", "Failed to pop correct " #TYPE " (" #EXPECTED ") found %lf", val); const blt::u64 SEED = std::random_device()(); @@ -189,14 +189,13 @@ void test_basic_types() BLT_TRACE_STREAM << stack.size() << "\n"; std::cout << std::endl; - BLT_INFO("Some fishy numbers in the last reported size. Let's try modifying the stack."); + BLT_INFO("Some fishy numbers in the last reported size. Let's try modifying the stack."); // fixed by moving back in pop stack.push(88.9f); BLT_TRACE_STREAM << "Pushed float: " << stack.size() << "\n"; { BLT_INFO("Popping a few values."); RUN_TEST_TYPE(float, 88.9f, stack); - BLT_TRACE_STREAM << "popped float: " << stack.size() << "\n"; RUN_TEST_SIZE(secondary_256, large_256, stack); } BLT_TRACE_STREAM << stack.size() << "\n";