From d241eaf1b209dcfb05656842dd6250067b704d99 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Tue, 19 Nov 2024 00:08:33 +0100 Subject: Add allocator, start work on box --- asl/tests/box_tests.cpp | 6 ++++++ asl/tests/format_tests.cpp | 23 +++++++++++------------ asl/tests/meta_tests.cpp | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 asl/tests/box_tests.cpp (limited to 'asl/tests') diff --git a/asl/tests/box_tests.cpp b/asl/tests/box_tests.cpp new file mode 100644 index 0000000..6c4d543 --- /dev/null +++ b/asl/tests/box_tests.cpp @@ -0,0 +1,6 @@ +#include "asl/box.hpp" + +#include "asl/testing/testing.hpp" + +static_assert(sizeof(asl::box) == sizeof(int*)); + diff --git a/asl/tests/format_tests.cpp b/asl/tests/format_tests.cpp index cb7a13f..a8c1ad6 100644 --- a/asl/tests/format_tests.cpp +++ b/asl/tests/format_tests.cpp @@ -1,26 +1,25 @@ #include "asl/format.hpp" #include "asl/testing/testing.hpp" -#include "asl/print.hpp" - -#include -#include -#include -#include - -// @Todo Improve this to use our utilities, not the C stdlib +#include "asl/allocator.hpp" static_assert(asl::formattable); -class StringSink : public asl::writer +class StringSink : public asl::Writer { + // @Todo Use string, once we have it, or a buffer isize_t m_current_len{}; char* m_data{}; public: void write(asl::span str) override { - m_data = (char*)realloc(m_data, (size_t)(m_current_len + str.size())); - memcpy(m_data + m_current_len, str.data(), (size_t)str.size()); + m_data = reinterpret_cast(asl::GlobalHeap::realloc( + m_data, + asl::layout::array(m_current_len), + asl::layout::array(m_current_len + str.size()))); + + asl::memcpy(m_data + m_current_len, str.data(), str.size()); + m_current_len += str.size(); } @@ -29,7 +28,7 @@ public: void reset() { m_current_len = 0; - free(m_data); + asl::GlobalHeap::dealloc(m_data, asl::layout::array(m_current_len)); m_data = nullptr; } }; diff --git a/asl/tests/meta_tests.cpp b/asl/tests/meta_tests.cpp index 40b9046..354cea6 100644 --- a/asl/tests/meta_tests.cpp +++ b/asl/tests/meta_tests.cpp @@ -35,6 +35,7 @@ static_assert(!asl::trivially_copy_constructible); static_assert(asl::move_constructible); static_assert(asl::move_constructible); static_assert(asl::move_constructible); +static_assert(asl::move_constructible); static_assert(!asl::move_constructible); static_assert(asl::trivially_move_constructible); -- cgit