diff --git a/include/xo/object2/DFloat.hpp b/include/xo/object2/DFloat.hpp index 52a3ba4..821e31d 100644 --- a/include/xo/object2/DFloat.hpp +++ b/include/xo/object2/DFloat.hpp @@ -5,10 +5,29 @@ #pragma once +#include + namespace xo { namespace scm { - using DFloat = double; - } /*nmaespace obj*/ + struct DFloat { + using AAllocator = xo::mm::AAllocator; + + explicit DFloat(double x) : value_{x} {} + + /** allocate boxed value @p x using memory from @p mm **/ + static DFloat * make(obj mm, + double x); + + double value() const noexcept { return value_; } + + operator double() const noexcept { return value_; } + + private: + + /** boxed floating-oint value **/ + double value_; + }; + } /*nmaespace scm*/ } /*namespace xo*/ /* end DFloat.hpp */ diff --git a/include/xo/object2/DList.hpp b/include/xo/object2/DList.hpp index 3f6a563..65ed0ad 100644 --- a/include/xo/object2/DList.hpp +++ b/include/xo/object2/DList.hpp @@ -3,9 +3,11 @@ * @author Roland Conybeare, Dec 2025 **/ -#include "xo/gc/GCObject.hpp" +#pragma once + +#include //#include "xo/alloc2/gcobject/RGCObject.hpp" -#include "xo/facet/obj.hpp" +#include namespace xo { namespace scm { diff --git a/src/object2/CMakeLists.txt b/src/object2/CMakeLists.txt index e2ffee2..fc66c97 100644 --- a/src/object2/CMakeLists.txt +++ b/src/object2/CMakeLists.txt @@ -8,6 +8,7 @@ set(SELF_SRCS ISequence_Any.cpp ISequence_DList.cpp DList.cpp + DFloat.cpp object2_register_types.cpp ) diff --git a/src/object2/DFloat.cpp b/src/object2/DFloat.cpp new file mode 100644 index 0000000..1ef8fa5 --- /dev/null +++ b/src/object2/DFloat.cpp @@ -0,0 +1,24 @@ +/** @file DFloat.cpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#include "DFloat.hpp" + +namespace xo { + using xo::facet::typeseq; + + namespace scm { + DFloat * + DFloat::make(obj mm, + double x) + { + void * mem = mm.alloc(typeseq::id(), + sizeof(DFloat)); + + return new (mem) DFloat(x); + } + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DFloat.cpp */ diff --git a/utest/X1Collector.test.cpp b/utest/X1Collector.test.cpp index 3857f0b..742e460 100644 --- a/utest/X1Collector.test.cpp +++ b/utest/X1Collector.test.cpp @@ -3,17 +3,35 @@ * @author Roland Conybeare, Dec 2025 **/ +#include "DFloat.hpp" +#include "DList.hpp" + +#include "IGCObject_DFloat.hpp" +#include "IGCObject_DList.hpp" + #include #include +#include +#include +#include + #include namespace ut { + using xo::scm::DList; + using xo::scm::DFloat; + using xo::mm::AAllocator; + using xo::mm::AllocInfo; + using xo::mm::AGCObject; using xo::mm::DX1Collector; using xo::mm::DArena; using xo::mm::CollectorConfig; using xo::mm::ArenaConfig; using xo::mm::generation; using xo::mm::role; + using xo::mm::padding; + using xo::facet::with_facet; + using xo::facet::typeseq; namespace { struct testcase_x1 { @@ -61,6 +79,7 @@ namespace ut { DX1Collector gc(cfg); + /* verify initial collector state */ { REQUIRE(gc.name() == "x1_test"); @@ -105,6 +124,43 @@ namespace ut { } /* attempt allocation */ + auto gc_o = with_facet::mkobj(&gc); + + DFloat * x0 = DFloat::make(gc_o, 3.1415927); + auto x0_o = with_facet::mkobj(x0); + + DList * l0 = DList::list(gc_o, x0_o); + auto l0_o = with_facet::mkobj(l0); + + { + { + REQUIRE(x0_o.iface() != nullptr); + REQUIRE(x0_o.data() != nullptr); + REQUIRE(gc.contains(role::to_space(), x0_o.data())); + + /* check alloc info for newly-allocated object */ + AllocInfo info = gc.alloc_info((std::byte *)x0_o.data()); + + REQUIRE(info.age() == 0); + REQUIRE(info.tseq() == typeseq::id().seqno()); + REQUIRE(info.size() >= sizeof(DFloat)); + REQUIRE(info.size() < sizeof(DFloat) + padding::c_alloc_alignment); + } + + { + REQUIRE(l0_o.iface() != nullptr); + REQUIRE(l0_o.data() != nullptr); + REQUIRE(gc.contains(role::to_space(), l0_o.data())); + + AllocInfo info = gc.alloc_info((std::byte *)l0_o.data()); + + REQUIRE(info.age() == 0); + REQUIRE(info.tseq() == typeseq::id().seqno()); + REQUIRE(info.size() >= sizeof(DList)); + REQUIRE(info.size() < sizeof(DList) + padding::c_alloc_alignment); + + } + } } catch (std::exception & ex) { std::cerr << "caught exception: " << ex.what() << std::endl;