xo-type: + DFunctionType

This commit is contained in:
Roland Conybeare 2026-03-07 11:43:14 +11:00
commit 1d0054cd7f
15 changed files with 485 additions and 0 deletions

View file

@ -10,13 +10,16 @@ set(SELF_SRCS
DAtomicType.cpp
DListType.cpp
DArrayType.cpp
DFunctionType.cpp
IType_Any.cpp
IType_DAtomicType.cpp
IType_DListType.cpp
IType_DArrayType.cpp
IType_DFunctionType.cpp
IGCObject_DAtomicType.cpp
IGCObject_DListType.cpp
IGCObject_DArrayType.cpp
IGCObject_DFunctionType.cpp
)
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
@ -27,6 +30,7 @@ xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 $
# NOTE: dependency set here must be kept consistent with
# xo-type/cmake/xo_typeConfig.cmake.in
xo_dependency(${SELF_LIB} xo_object2)
xo_dependency(${SELF_LIB} xo_alloc2)
xo_dependency(${SELF_LIB} xo_facet)
xo_dependency(${SELF_LIB} subsys)

109
src/type/DFunctionType.cpp Normal file
View file

@ -0,0 +1,109 @@
/** @file DFunctionType.cpp
*
* @author Roland Conybeare, Mar 2026
**/
#include "FunctionType.hpp"
#include <xo/facet/FacetRegistry.hpp>
namespace xo {
using xo::facet::FacetRegistry;
namespace scm {
// ----- type facet -----
bool
DFunctionType::is_equal_to(obj<AType> y_arg) const noexcept
{
Metatype y_mtype = y_arg.metatype();
if (y_mtype != Metatype::function())
return false;
auto y = obj<AType,DFunctionType>::from(y_arg);
assert(y);
if (arg_types_->size() != y->arg_types_->size())
return false;
if (obj<AType>(return_type_).is_equal_to(y->return_type_))
return false;
for (size_t i = 0, n = arg_types_->size(); i < n; ++i) {
auto argtype1
= FacetRegistry::instance().variant<AType,AGCObject>((*arg_types_)[i]);
auto argtype2
= FacetRegistry::instance().variant<AType,AGCObject>((*(y->arg_types_))[i]);
if (argtype1.is_equal_to(argtype2))
return false;
}
return true;
}
bool
DFunctionType::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::function())
return false;
auto y = obj<AType,DFunctionType>::from(y_arg);
assert(y);
if (arg_types_->size() != y->arg_types_->size())
return false;
if (!obj<AType>(return_type_).is_subtype_of(y->return_type_))
return false;
for (size_t i = 0, n = arg_types_->size(); i < n; ++i) {
auto x_argtype
= FacetRegistry::instance().variant<AType,AGCObject>((*arg_types_)[i]);
auto y_argtype
= FacetRegistry::instance().variant<AType,AGCObject>((*(y->arg_types_))[i]);
if (!y_argtype.is_subtype_of(x_argtype))
return false;
}
return true;
}
// ----- gcobject facet -----
std::size_t
DFunctionType::shallow_size() const noexcept
{
return sizeof(*this);
}
DFunctionType *
DFunctionType::shallow_copy(obj<AAllocator> mm) const noexcept
{
return mm.std_copy_for(this);
}
std::size_t
DFunctionType::forward_children(obj<ACollector> gc) noexcept
{
{
auto e = FacetRegistry::instance().variant<AGCObject,AType>(return_type_);
gc.forward_inplace(e.iface(), (void **)&(e.data_));
}
gc.forward_inplace(&arg_types_);
return this->shallow_size();
}
} /*namespace scm*/
} /*namespace xo*/
/* end DFunctionType.cpp */

View file

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

View file

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

View file

@ -8,6 +8,7 @@
#include <xo/type/AtomicType.hpp>
#include <xo/type/ListType.hpp>
#include <xo/type/ArrayType.hpp>
#include <xo/type/FunctionType.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/indentlog/scope.hpp>
@ -32,9 +33,13 @@ namespace xo {
FacetRegistry::register_impl<AType, DArrayType>();
FacetRegistry::register_impl<AGCObject, DArrayType>();
FacetRegistry::register_impl<AType, DFunctionType>();
FacetRegistry::register_impl<AGCObject, DFunctionType>();
log && log(xtag("DAtomicType.tseq", typeseq::id<DAtomicType>()));
log && log(xtag("DListType.tseq", typeseq::id<DListType>()));
log && log(xtag("DArrayType.tseq", typeseq::id<DArrayType>()));
log && log(xtag("DFunctionType.tseq", typeseq::id<DFunctionType>()));
return true;
}

View file

@ -8,6 +8,7 @@
#include "AtomicType.hpp"
#include "ListType.hpp"
#include "ArrayType.hpp"
#include "FunctionType.hpp"
#include <xo/alloc2/Collector.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/indentlog/scope.hpp>
@ -29,6 +30,7 @@ namespace xo {
ok &= gc.install_type(impl_for<AGCObject, DAtomicType>());
ok &= gc.install_type(impl_for<AGCObject, DListType>());
ok &= gc.install_type(impl_for<AGCObject, DArrayType>());
ok &= gc.install_type(impl_for<AGCObject, DFunctionType>());
return ok;
}