From 79586af2faaa56d92ca006b0623d9346963c4c5a Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 5 Mar 2026 20:11:05 +1100 Subject: [PATCH] xo-object2 stack: refactor/tidy after GCObject -> alloc2 --- include/xo/gc/GCObjectConversion.hpp | 117 ------------------ .../xo/gc/detail/ICollector_DX1Collector.hpp | 2 + 2 files changed, 2 insertions(+), 117 deletions(-) delete mode 100644 include/xo/gc/GCObjectConversion.hpp diff --git a/include/xo/gc/GCObjectConversion.hpp b/include/xo/gc/GCObjectConversion.hpp deleted file mode 100644 index 59ec12f..0000000 --- a/include/xo/gc/GCObjectConversion.hpp +++ /dev/null @@ -1,117 +0,0 @@ -/** @file GCObjectConversion.hpp - * - * @author Roland Conybeare, Jan 2026 - **/ - -#pragma once - -#include -#include -#include -#include -#include - -namespace xo { - namespace scm { - /** @brief compile-time conversion obj <-> T - * - * Specialize for each T that participates in conversion. - * Methods here aren't implemented - **/ - template - struct GCObjectConversion { - using AGCObject = xo::mm::AGCObject; - using AAllocator = xo::mm::AAllocator; - - /** find gc-aware representation for @p x. - * If necessary allocate from @p mm, but may - * refer to @p x in-place - **/ - static obj to_gco(obj mm, const T & x); - /** convert to native representation @tparam T from gc-aware - * @p gco. If necessary allocate from @p mm, but - * may instead refer to @p x in-place - **/ - static T from_gco(obj mm, obj gco); - }; - - /** Motivating use-case for GCObjectConversion is to transform - * primitive function arguments and results to/from gc-aware - * representation. - * - * However: Schematika also supports runtime polymorphism - * which leads to primitives that expect obj arguments. - * - * Also, Schematika expression parser needs representation for - * expressions, before type unification. - * - * Consider a function like: - * def fact = lambda (n : i64) { if (n <= 0) then 1 else (n * fact(n - 1)); } - * During expression parsing the rhs argument to multiply has unknown type. - * To construct an expression for input to unification will use polymorphic - * binding for multiply primitive, relying on specialization here for - * its implementation. - **/ - template - struct GCObjectConversion> { - using AGCObject = xo::mm::AGCObject; - using AAllocator = xo::mm::AAllocator; - using FacetRegistry = xo::facet::FacetRegistry; - using DVariantPlaceholder = xo::facet::DVariantPlaceholder; - - static obj to_gco(obj, - obj gco) { - if constexpr (std::is_same_v) { - // trivial conversion! - return gco; - } else if constexpr (std::is_same_v) { - // runtime polymorphism - return FacetRegistry::instance().variant(gco); - } else /* DRepr != DVariantPlaceholder */ { - // known content w/ fat object pointer - return obj(gco.data()); - } - } - - static obj from_gco(obj, - obj gco) { - scope log(XO_DEBUG(false)); - - if constexpr (std::is_same_v) { - // Need accurate handling of DVariantPlaceholder. - // runtime type must be some concrete type. - // Only use obj::from when DRepr is a concrete type - - if constexpr (std::is_same_v) { - // At comptime gco has unknown repr. At runtime - // will have some known repr, which assignment here will transfer - return gco; - } else { - // Runtime conversion to concrete type DRepr - - auto retval = obj::from(gco); - - if (!retval) { - log.retroactively_enable(); - - log && log(xtag("gco.tseq", gco._typeseq())); - log && log(xtag("DRepr.tseq", reflect::typeseq::id())); - } - - assert(retval); - - return retval; - } - } else { - // both runtime and comptime polymorphism - // use same path here, since representation of @p gco - // is type-erased here - - return FacetRegistry::instance().variant(gco); - } - } - }; - } /*namespace scm */ -} /*namespace xo*/ - -/* end GCObjectConversion.hpp */ diff --git a/include/xo/gc/detail/ICollector_DX1Collector.hpp b/include/xo/gc/detail/ICollector_DX1Collector.hpp index 0475a53..1db50e2 100644 --- a/include/xo/gc/detail/ICollector_DX1Collector.hpp +++ b/include/xo/gc/detail/ICollector_DX1Collector.hpp @@ -3,6 +3,8 @@ * @author Roland Conybeare, Dec 2025 **/ +#pragma once + #include #include #include "DX1Collector.hpp"