xo-type: + gcobject facet + DListType

This commit is contained in:
Roland Conybeare 2026-03-07 00:01:57 +11:00
commit 0e3e0d8751
29 changed files with 749 additions and 6 deletions

View file

@ -5,10 +5,15 @@ set(SELF_SRCS
init_type.cpp
type_register_facets.cpp
type_register_types.cpp
TypeOps.cpp
Metatype.cpp
DAtomicType.cpp
DListType.cpp
IType_Any.cpp
IType_DAtomicType.cpp
IType_DListType.cpp
IGCObject_DAtomicType.cpp
IGCObject_DListType.cpp
)
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})

View file

@ -16,6 +16,26 @@ namespace xo {
return new (mem) DAtomicType(mtype);
}
// ----- Type facet -----
bool
DAtomicType::is_equal_to(const obj<AType> & y) const noexcept
{
return (metatype_.code() == y.metatype().code());
}
bool
DAtomicType::is_subtype_of(const obj<AType> & y) const noexcept
{
Metatype x_mtype = metatype_;
Metatype y_mtype = y.metatype();
if (y_mtype.code() == Metatype::code::t_any)
return true;
return (x_mtype.code() == y_mtype.code());
}
// ----- GCObject facet -----
std::size_t

92
src/type/DListType.cpp Normal file
View file

@ -0,0 +1,92 @@
/** @file DListType.cpp
*
* @author Roland Conybeare, Mar 2026
**/
#include "Type.hpp"
#include "ListType.hpp"
#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/facet/FacetRegistry.hpp>
namespace xo {
using xo::mm::AGCObject;
using xo::mm::AAllocator;
using xo::facet::FacetRegistry;
namespace scm {
DListType::DListType(obj<AType> elt) : elt_type_{elt} {}
DListType *
DListType::_make(obj<AAllocator> mm,
obj<AType> elt_type)
{
void * mem = mm.alloc_for<DListType>();
return new (mem) DListType(elt_type);
}
// ----- type facet -----
bool
DListType::is_equal_to(const obj<AType> & y_arg) const noexcept
{
Metatype y_mtype = y_arg.metatype();
if (y_mtype != Metatype::list())
return false;
auto y = obj<AType,DListType>::from(y_arg);
obj<AType> e = elt_type_;
return (e.is_equal_to(y->elt_type_));
}
bool
DListType::is_subtype_of(const obj<AType> & y_arg) const noexcept
{
Metatype y_mtype = y_arg.metatype();
if (y_mtype == Metatype::any())
return true;
if (y_mtype != Metatype::list())
return false;
auto y = obj<AType,DListType>::from(y_arg);
obj<AType> e = elt_type_;
return (e.is_subtype_of(y->elt_type_));
}
// ----- gcobject facet -----
std::size_t
DListType::shallow_size() const noexcept
{
return sizeof(*this);
}
DListType *
DListType::shallow_copy(obj<AAllocator> mm) const noexcept
{
return mm.std_copy_for(this);
}
std::size_t
DListType::forward_children(obj<ACollector> gc) noexcept
{
{
auto e = FacetRegistry::instance().variant<AGCObject,AType>(elt_type_);
gc.forward_inplace(e.iface(), (void **)&(e.data_));
}
return this->shallow_size();
}
}
}
/* end DListType.cpp */

View file

@ -0,0 +1,39 @@
/** @file IGCObject_DListType.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObject_DListType.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObject_DListType.json5]
**/
#include "list/IGCObject_DListType.hpp"
namespace xo {
namespace scm {
auto
IGCObject_DListType::shallow_size(const DListType & self) noexcept -> size_type
{
return self.shallow_size();
}
auto
IGCObject_DListType::shallow_copy(const DListType & self, obj<AAllocator> mm) noexcept -> Opaque
{
return self.shallow_copy(mm);
}
auto
IGCObject_DListType::forward_children(DListType & self, obj<ACollector> gc) noexcept -> size_type
{
return self.forward_children(gc);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IGCObject_DListType.cpp */

View file

@ -21,6 +21,18 @@ namespace xo {
return self.metatype();
}
auto
IType_DAtomicType::is_equal_to(const DAtomicType & self, const obj_AType & y) -> bool
{
return self.is_equal_to(y);
}
auto
IType_DAtomicType::is_subtype_of(const DAtomicType & self, const obj_AType & y) -> bool
{
return self.is_subtype_of(y);
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -0,0 +1,40 @@
/** @file IType_DListType.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IType_DListType.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IType_DListType.json5]
**/
#include "list/IType_DListType.hpp"
namespace xo {
namespace scm {
auto
IType_DListType::metatype(const DListType & self) noexcept -> Metatype
{
return self.metatype();
}
auto
IType_DListType::is_equal_to(const DListType & self, const obj_AType & y) -> bool
{
return self.is_equal_to(y);
}
auto
IType_DListType::is_subtype_of(const DListType & self, const obj_AType & y) -> bool
{
return self.is_subtype_of(y);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IType_DListType.cpp */

View file

@ -26,6 +26,35 @@ namespace xo {
}
}
bool
Metatype::is_atomic() const noexcept
{
switch (code_) {
case code::t_any:
return true;
case code::t_bool:
return true;
case code::t_i64:
return true;
case code::t_f64:
return true;
case code::t_str:
return true;
case code::t_sum:
return false;
case code::t_list:
return false;
case code::t_array:
return false;
case code::t_function:
return false;
case code::t_struct:
return false;
case code::t_unit:
return false;
}
}
} /*namespace scm*/
} /*namespace xo*/

15
src/type/TypeOps.cpp Normal file
View file

@ -0,0 +1,15 @@
/** @file TypeOps.cpp
*
* @author Roland Conybeare, Mar 2026
**/
#include "TypeOps.hpp"
namespace xo {
namespace scm {
} /*namespace scm*/
} /*namespace xo*/
/* end TypeOps.cpp */

View file

@ -6,13 +6,13 @@
#include "type_register_facets.hpp"
#include <xo/type/AtomicType.hpp>
#include <xo/type/ListType.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/indentlog/scope.hpp>
namespace xo {
using xo::mm::AGCObject;
using xo::facet::FacetRegistry;
//using xo::facet::TypeRegistry;
using xo::reflect::typeseq;
namespace scm {
@ -22,9 +22,14 @@ namespace xo {
{
scope log(XO_DEBUG(true));
FacetRegistry::register_impl<AType, DAtomicType>();
FacetRegistry::register_impl<AGCObject, DAtomicType>();
FacetRegistry::register_impl<AType, DListType>();
FacetRegistry::register_impl<AGCObject, DListType>();
log && log(xtag("DAtomicType.tseq", typeseq::id<DAtomicType>()));
log && log(xtag("DListType.tseq", typeseq::id<DListType>()));
return true;
}

View file

@ -6,6 +6,7 @@
#include "type_register_types.hpp"
#include "AtomicType.hpp"
#include "ListType.hpp"
#include <xo/alloc2/Collector.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/indentlog/scope.hpp>
@ -25,6 +26,7 @@ namespace xo {
bool ok = true;
ok &= gc.install_type(impl_for<AGCObject, DAtomicType>());
ok &= gc.install_type(impl_for<AGCObject, DListType>());
return ok;
}