xo-gc: + CollectorTypeRegistry for streamlined init
This commit is contained in:
parent
87ddccd717
commit
013c1a4896
7 changed files with 109 additions and 3 deletions
|
|
@ -3,6 +3,7 @@
|
|||
include(CMakeFindDependencyMacro)
|
||||
find_dependency(xo_gc)
|
||||
find_dependency(xo_printable2)
|
||||
find_dependency(subsys)
|
||||
find_dependency(indentlog)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
check_required_components("@PROJECT_NAME@")
|
||||
|
|
|
|||
21
include/xo/object2/init_object2.hpp
Normal file
21
include/xo/object2/init_object2.hpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/** @file init_object2.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/subsys/Subsystem.hpp>
|
||||
|
||||
namespace xo {
|
||||
/* tag to represent the xo-expression2/ subsystem within ordered initialization */
|
||||
enum S_object2_tag {};
|
||||
|
||||
template <>
|
||||
struct InitSubsys<S_object2_tag> {
|
||||
static void init();
|
||||
static InitEvidence require();
|
||||
};
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end init_object2.hpp */
|
||||
|
|
@ -19,6 +19,7 @@ set(SELF_SRCS
|
|||
DFloat.cpp
|
||||
DInteger.cpp
|
||||
DString.cpp
|
||||
init_object2.cpp
|
||||
object2_register_types.cpp
|
||||
object2_register_facets.cpp
|
||||
)
|
||||
|
|
@ -27,4 +28,5 @@ xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 $
|
|||
# note: deps here must also appear in cmake/xo_object2Config.cmake.in
|
||||
xo_dependency(${SELF_LIB} xo_gc)
|
||||
xo_dependency(${SELF_LIB} xo_printable2)
|
||||
xo_dependency(${SELF_LIB} subsys)
|
||||
xo_dependency(${SELF_LIB} indentlog)
|
||||
|
|
|
|||
39
src/object2/init_object2.cpp
Normal file
39
src/object2/init_object2.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/** @file init_object2.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include "init_object2.hpp"
|
||||
#include "object2_register_facets.hpp"
|
||||
#include "object2_register_types.hpp"
|
||||
#include <xo/gc/CollectorTypeRegistry.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::scm::object2_register_facets;
|
||||
using xo::scm::object2_register_types;
|
||||
using xo::mm::CollectorTypeRegistry;
|
||||
|
||||
void
|
||||
InitSubsys<S_object2_tag>::init()
|
||||
{
|
||||
object2_register_facets();
|
||||
|
||||
CollectorTypeRegistry::instance().register_types(&object2_register_types);
|
||||
}
|
||||
|
||||
InitEvidence
|
||||
InitSubsys<S_object2_tag>::require()
|
||||
{
|
||||
InitEvidence retval;
|
||||
|
||||
/* direct subsystem deps for xo-object2/ */
|
||||
// retval ^= InitSubsys<S_somedep_tag>::require();
|
||||
|
||||
/* xo-expression2/'s own initialization code */
|
||||
retval ^= Subsystem::provide<S_object2_tag>("object2", &init);
|
||||
|
||||
return retval;
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end init_object2.cpp */
|
||||
|
|
@ -3,7 +3,8 @@
|
|||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include <xo/object2/StringOps.hpp>
|
||||
#include "init_object2.hpp"
|
||||
#include "StringOps.hpp"
|
||||
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
#include <cctype>
|
||||
|
|
@ -19,6 +20,14 @@ namespace xo {
|
|||
using xo::facet::obj;
|
||||
|
||||
namespace ut {
|
||||
static InitEvidence s_init = (InitSubsys<S_object2_tag>::require());
|
||||
|
||||
TEST_CASE("DString-init", "[object2][DString]")
|
||||
{
|
||||
// real purpose: ensure s_init survives static linking
|
||||
REQUIRE(s_init.evidence());
|
||||
}
|
||||
|
||||
TEST_CASE("DString-empty", "[object2][DString]")
|
||||
{
|
||||
ArenaConfig cfg { .name_ = "testarena",
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "init_object2.hpp"
|
||||
#include "ListOps.hpp"
|
||||
#include "DFloat.hpp"
|
||||
#include "DInteger.hpp"
|
||||
|
|
@ -14,6 +15,7 @@
|
|||
#include "number/IGCObject_DInteger.hpp"
|
||||
#include "list/IGCObject_DList.hpp"
|
||||
|
||||
#include <xo/gc/CollectorTypeRegistry.hpp>
|
||||
#include <xo/gc/Collector.hpp>
|
||||
#include <xo/gc/DX1Collector.hpp>
|
||||
|
||||
|
|
@ -23,18 +25,22 @@
|
|||
#include <xo/arena/AllocInfo.hpp>
|
||||
#include <xo/arena/padding.hpp>
|
||||
|
||||
#include <xo/subsys/Subsystem.hpp>
|
||||
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
#include <xo/indentlog/print/tag.hpp>
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
namespace ut {
|
||||
using xo::S_object2_tag;
|
||||
using xo::scm::object2_register_types;
|
||||
using xo::scm::ListOps;
|
||||
using xo::scm::DList;
|
||||
using xo::scm::DArray;
|
||||
using xo::scm::DFloat;
|
||||
using xo::scm::DInteger;
|
||||
using xo::mm::CollectorTypeRegistry;
|
||||
using xo::mm::AAllocator;
|
||||
using xo::mm::ACollector;
|
||||
using xo::mm::AllocHeader;
|
||||
|
|
@ -49,6 +55,9 @@ namespace ut {
|
|||
using xo::mm::padding;
|
||||
using xo::facet::with_facet;
|
||||
using xo::facet::typeseq;
|
||||
using xo::Subsystem;
|
||||
using xo::InitEvidence;
|
||||
using xo::InitSubsys;
|
||||
using xo::scope;
|
||||
using xo::xtag;
|
||||
|
||||
|
|
@ -79,8 +88,13 @@ namespace ut {
|
|||
};
|
||||
}
|
||||
|
||||
static InitEvidence s_init = (InitSubsys<S_object2_tag>::require());
|
||||
|
||||
TEST_CASE("x1", "[gc][x1]")
|
||||
{
|
||||
// real purpose: ensure s_init survives static linking
|
||||
REQUIRE(s_init.evidence());
|
||||
|
||||
/**
|
||||
* This is a basic Collector test for xo-object2 data types
|
||||
**/
|
||||
|
|
@ -89,6 +103,8 @@ namespace ut {
|
|||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
for (std::size_t i_tc = 0, n_tc = s_testcase_v.size(); i_tc < n_tc; ++i_tc) {
|
||||
scope log(XO_DEBUG(true), xtag("i_tc", i_tc));
|
||||
|
||||
try {
|
||||
const testcase_x1 & tc = s_testcase_v[i_tc];
|
||||
|
||||
|
|
@ -169,7 +185,7 @@ namespace ut {
|
|||
auto c_o = with_facet<ACollector>::mkobj(&gc);
|
||||
|
||||
/* register object types */
|
||||
bool ok = object2_register_types(c_o);
|
||||
bool ok = CollectorTypeRegistry::instance().install_types(c_o);
|
||||
|
||||
REQUIRE(ok);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,24 @@
|
|||
/* file object2_utest_main.cpp */
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <xo/subsys/Subsystem.hpp>
|
||||
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
using xo::Subsystem;
|
||||
|
||||
// Your custom initialization code here
|
||||
Subsystem::initialize_all();
|
||||
|
||||
// Run Catch2's test session
|
||||
int result = Catch::Session().run(argc, argv);
|
||||
|
||||
// cleanup here, if any
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* end object2_utest_main.cpp */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue