From 1d0054cd7f222bd860f6f3aa72d79b51f3541e8b Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 7 Mar 2026 11:43:14 +1100 Subject: [PATCH] xo-type: + DFunctionType --- CMakeLists.txt | 20 ++++ cmake/xo_typeConfig.cmake.in | 1 + idl/IGCObject_DFunctionType.json5 | 16 +++ idl/IType_DFunctionType.json5 | 16 +++ include/xo/type/DFunctionType.hpp | 92 +++++++++++++++ include/xo/type/FunctionType.hpp | 12 ++ include/xo/type/Metatype.hpp | 1 + .../type/function/IGCObject_DFunctionType.hpp | 65 +++++++++++ .../xo/type/function/IType_DFunctionType.hpp | 63 ++++++++++ src/type/CMakeLists.txt | 4 + src/type/DFunctionType.cpp | 109 ++++++++++++++++++ src/type/IGCObject_DFunctionType.cpp | 39 +++++++ src/type/IType_DFunctionType.cpp | 40 +++++++ src/type/type_register_facets.cpp | 5 + src/type/type_register_types.cpp | 2 + 15 files changed, 485 insertions(+) create mode 100644 idl/IGCObject_DFunctionType.json5 create mode 100644 idl/IType_DFunctionType.json5 create mode 100644 include/xo/type/DFunctionType.hpp create mode 100644 include/xo/type/FunctionType.hpp create mode 100644 include/xo/type/function/IGCObject_DFunctionType.hpp create mode 100644 include/xo/type/function/IType_DFunctionType.hpp create mode 100644 src/type/DFunctionType.cpp create mode 100644 src/type/IGCObject_DFunctionType.cpp create mode 100644 src/type/IType_DFunctionType.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a31853..82cdc68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,26 @@ xo_add_genfacetimpl( # ---------------------------------------------------------------- +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-type-facetimpl-type-functiontype + FACET_PKG xo_type + FACET Type + REPR FunctionType + INPUT idl/IType_DFunctionType.json5 +) + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-type-facetimpl-gcobject-functiontype + FACET_PKG xo_alloc2 + FACET GCObject + REPR FunctionType + INPUT idl/IGCObject_DFunctionType.json5 +) + +# ---------------------------------------------------------------- + xo_add_genfacet_all(xo-type-genfacet-all) install(DIRECTORY idl/ diff --git a/cmake/xo_typeConfig.cmake.in b/cmake/xo_typeConfig.cmake.in index 186f181..e1618c2 100644 --- a/cmake/xo_typeConfig.cmake.in +++ b/cmake/xo_typeConfig.cmake.in @@ -1,6 +1,7 @@ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) +find_dependency(xo_object2) find_dependency(xo_alloc2) find_dependency(xo_facet) find_dependency(subsys) diff --git a/idl/IGCObject_DFunctionType.json5 b/idl/IGCObject_DFunctionType.json5 new file mode 100644 index 0000000..af1f3c9 --- /dev/null +++ b/idl/IGCObject_DFunctionType.json5 @@ -0,0 +1,16 @@ +{ + mode: "implementation", + output_cpp_dir: "src/type", + output_hpp_dir: "include/xo/type", + output_impl_subdir: "function", + includes: [ + ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/GCObject.json5", + brief: "provide AGCObject interface for DFunctionType", + using_doxygen: true, + repr: "DFunctionType", + doc: [ "implement AGCObject for DFunctionType" ], +} diff --git a/idl/IType_DFunctionType.json5 b/idl/IType_DFunctionType.json5 new file mode 100644 index 0000000..99dd82b --- /dev/null +++ b/idl/IType_DFunctionType.json5 @@ -0,0 +1,16 @@ +{ + mode: "implementation", + output_cpp_dir: "src/type", + output_hpp_dir: "include/xo/type", + output_impl_subdir: "function", + includes: [], + local_types: [], + namespace1: "xo", + namespace2: "scm", + + facet_idl: "idl/Type.json5", + brief: "provide AType interface for DFunctionType", + using_doxygen: true, + repr: "DFunctionType", + doc: [ "implement AType for DFunctionType" ], +} diff --git a/include/xo/type/DFunctionType.hpp b/include/xo/type/DFunctionType.hpp new file mode 100644 index 0000000..3ceafb7 --- /dev/null +++ b/include/xo/type/DFunctionType.hpp @@ -0,0 +1,92 @@ +/** @file DFunctionType.hpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#pragma once + +#include "Type.hpp" +#include "Metatype.hpp" +#include +#include +#include + +namespace xo { + namespace scm { + /** @brief A parameterized array type: array(T) + * + * Represents a fixed-size homogeneous collection. + **/ + class DFunctionType { + public: + using ACollector = xo::mm::ACollector; + using AAllocator = xo::mm::AAllocator; + using AGCObject = xo::mm::AGCObject; + + public: + /** @defgroup xo-scm-arraytype-ctors **/ + ///@{ + + /** create instance using memory from @p mm, + * for a function with return type @p ret_type and arguments @p args + **/ + template + requires (std::same_as> && ...) + explicit DFunctionType(obj mm, obj ret_type, Args... args); + + /** create instance using memory from @p mm, + * for a function with return type @p ret_type and arguments @p args + **/ + template + requires (std::same_as> && ...) + static DFunctionType * _make(obj mm, + obj ret_type, Args... args); + + ///@} + /** @defgroup xo-scm-arraytype-type-facet **/ + ///@{ + Metatype metatype() const noexcept { return Metatype::array(); } + bool is_equal_to(obj y) const noexcept; + bool is_subtype_of(const obj & y) const noexcept; + ///@} + /** @defgroup xo-scm-arraytype-gcobject-facet **/ + ///@{ + std::size_t shallow_size() const noexcept; + DFunctionType * shallow_copy(obj mm) const noexcept; + std::size_t forward_children(obj gc) noexcept; + ///@} + + private: + /** @defgroup xo-scm-arraytype-member-vars **/ + ///@{ + + /** function return type **/ + obj return_type_; + + /** argument types **/ + DArray * arg_types_ = nullptr; + + ///@} + }; + + template + requires (std::same_as> && ...) + DFunctionType::DFunctionType(obj mm, obj return_type, Args... args) + : return_type_{return_type}, + arg_types_{DArray::array(mm, args...)} + {} + + template + requires (std::same_as> && ...) + DFunctionType * + DFunctionType::_make(obj mm, obj ret_type, Args... args) + { + void * mem = mm.alloc_for(); + + return new (mem) DFunctionType(mm, ret_type, args...); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DFunctionType.hpp */ diff --git a/include/xo/type/FunctionType.hpp b/include/xo/type/FunctionType.hpp new file mode 100644 index 0000000..28cdc11 --- /dev/null +++ b/include/xo/type/FunctionType.hpp @@ -0,0 +1,12 @@ +/** @file FunctionType.hpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#pragma once + +#include "DFunctionType.hpp" +#include "function/IType_DFunctionType.hpp" +#include "function/IGCObject_DFunctionType.hpp" + +/* end FunctionType.hpp */ diff --git a/include/xo/type/Metatype.hpp b/include/xo/type/Metatype.hpp index e111980..b8a509e 100644 --- a/include/xo/type/Metatype.hpp +++ b/include/xo/type/Metatype.hpp @@ -47,6 +47,7 @@ namespace xo { static Metatype list() { return Metatype(code::t_list); } static Metatype array() { return Metatype(code::t_array); } + static Metatype function() { return Metatype(code::t_function); } /** description string for this type category **/ const char * _descr() const noexcept; diff --git a/include/xo/type/function/IGCObject_DFunctionType.hpp b/include/xo/type/function/IGCObject_DFunctionType.hpp new file mode 100644 index 0000000..431c19e --- /dev/null +++ b/include/xo/type/function/IGCObject_DFunctionType.hpp @@ -0,0 +1,65 @@ +/** @file IGCObject_DFunctionType.hpp + * + * 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_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DFunctionType.json5] + **/ + +#pragma once + +#include "GCObject.hpp" +#include "DFunctionType.hpp" + +namespace xo { namespace scm { class IGCObject_DFunctionType; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IGCObject_DFunctionType + **/ + class IGCObject_DFunctionType { + public: + /** @defgroup scm-gcobject-dfunctiontype-type-traits **/ + ///@{ + using size_type = xo::mm::AGCObject::size_type; + using AAllocator = xo::mm::AGCObject::AAllocator; + using ACollector = xo::mm::AGCObject::ACollector; + using Copaque = xo::mm::AGCObject::Copaque; + using Opaque = xo::mm::AGCObject::Opaque; + ///@} + /** @defgroup scm-gcobject-dfunctiontype-methods **/ + ///@{ + // const methods + /** memory consumption for this instance **/ + static size_type shallow_size(const DFunctionType & self) noexcept; + /** copy instance using allocator **/ + static Opaque shallow_copy(const DFunctionType & self, obj mm) noexcept; + + // non-const methods + /** during GC: forward immdiate children **/ + static size_type forward_children(DFunctionType & self, obj gc) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/include/xo/type/function/IType_DFunctionType.hpp b/include/xo/type/function/IType_DFunctionType.hpp new file mode 100644 index 0000000..b28050a --- /dev/null +++ b/include/xo/type/function/IType_DFunctionType.hpp @@ -0,0 +1,63 @@ +/** @file IType_DFunctionType.hpp + * + * 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_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IType_DFunctionType.json5] + **/ + +#pragma once + +#include "Type.hpp" +#include "DFunctionType.hpp" + +namespace xo { namespace scm { class IType_DFunctionType; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::scm::IType_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IType_DFunctionType + **/ + class IType_DFunctionType { + public: + /** @defgroup scm-type-dfunctiontype-type-traits **/ + ///@{ + using obj_AType = xo::scm::AType::obj_AType; + using Copaque = xo::scm::AType::Copaque; + using Opaque = xo::scm::AType::Opaque; + ///@} + /** @defgroup scm-type-dfunctiontype-methods **/ + ///@{ + // const methods + /** category for this type **/ + static Metatype metatype(const DFunctionType & self) noexcept; + /** true iff this type is equal to y **/ + static bool is_equal_to(const DFunctionType & self, const obj_AType & y); + /** true iff this is a subtype of y **/ + static bool is_subtype_of(const DFunctionType & self, const obj_AType & y); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/src/type/CMakeLists.txt b/src/type/CMakeLists.txt index d00c30b..3bc7b2e 100644 --- a/src/type/CMakeLists.txt +++ b/src/type/CMakeLists.txt @@ -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) diff --git a/src/type/DFunctionType.cpp b/src/type/DFunctionType.cpp new file mode 100644 index 0000000..5fdbbdf --- /dev/null +++ b/src/type/DFunctionType.cpp @@ -0,0 +1,109 @@ +/** @file DFunctionType.cpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#include "FunctionType.hpp" +#include + +namespace xo { + using xo::facet::FacetRegistry; + + namespace scm { + + // ----- type facet ----- + + bool + DFunctionType::is_equal_to(obj y_arg) const noexcept + { + Metatype y_mtype = y_arg.metatype(); + + if (y_mtype != Metatype::function()) + return false; + + auto y = obj::from(y_arg); + assert(y); + + if (arg_types_->size() != y->arg_types_->size()) + return false; + + if (obj(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((*arg_types_)[i]); + auto argtype2 + = FacetRegistry::instance().variant((*(y->arg_types_))[i]); + + if (argtype1.is_equal_to(argtype2)) + return false; + } + + return true; + } + + bool + DFunctionType::is_subtype_of(const obj & 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::from(y_arg); + assert(y); + + if (arg_types_->size() != y->arg_types_->size()) + return false; + + if (!obj(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((*arg_types_)[i]); + auto y_argtype + = FacetRegistry::instance().variant((*(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 mm) const noexcept + { + return mm.std_copy_for(this); + } + + std::size_t + DFunctionType::forward_children(obj gc) noexcept + { + { + auto e = FacetRegistry::instance().variant(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 */ diff --git a/src/type/IGCObject_DFunctionType.cpp b/src/type/IGCObject_DFunctionType.cpp new file mode 100644 index 0000000..45141b3 --- /dev/null +++ b/src/type/IGCObject_DFunctionType.cpp @@ -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 mm) noexcept -> Opaque + { + return self.shallow_copy(mm); + } + + auto + IGCObject_DFunctionType::forward_children(DFunctionType & self, obj gc) noexcept -> size_type + { + return self.forward_children(gc); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IGCObject_DFunctionType.cpp */ diff --git a/src/type/IType_DFunctionType.cpp b/src/type/IType_DFunctionType.cpp new file mode 100644 index 0000000..230cf67 --- /dev/null +++ b/src/type/IType_DFunctionType.cpp @@ -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 */ diff --git a/src/type/type_register_facets.cpp b/src/type/type_register_facets.cpp index 8cebc6f..9cada7e 100644 --- a/src/type/type_register_facets.cpp +++ b/src/type/type_register_facets.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -32,9 +33,13 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + log && log(xtag("DAtomicType.tseq", typeseq::id())); log && log(xtag("DListType.tseq", typeseq::id())); log && log(xtag("DArrayType.tseq", typeseq::id())); + log && log(xtag("DFunctionType.tseq", typeseq::id())); return true; } diff --git a/src/type/type_register_types.cpp b/src/type/type_register_types.cpp index 884de0c..e031ce5 100644 --- a/src/type/type_register_types.cpp +++ b/src/type/type_register_types.cpp @@ -8,6 +8,7 @@ #include "AtomicType.hpp" #include "ListType.hpp" #include "ArrayType.hpp" +#include "FunctionType.hpp" #include #include #include @@ -29,6 +30,7 @@ namespace xo { ok &= gc.install_type(impl_for()); ok &= gc.install_type(impl_for()); ok &= gc.install_type(impl_for()); + ok &= gc.install_type(impl_for()); return ok; }