diff --git a/cmake/xo_typeConfig.cmake.in b/cmake/xo_typeConfig.cmake.in index e1618c2..2d7841a 100644 --- a/cmake/xo_typeConfig.cmake.in +++ b/cmake/xo_typeConfig.cmake.in @@ -2,6 +2,7 @@ include(CMakeFindDependencyMacro) find_dependency(xo_object2) +find_dependnecy(reflect) find_dependency(xo_alloc2) find_dependency(xo_facet) find_dependency(subsys) diff --git a/idl/Type.json5 b/idl/Type.json5 index 1ddac82..06fa2dc 100644 --- a/idl/Type.json5 +++ b/idl/Type.json5 @@ -4,7 +4,8 @@ output_hpp_dir: "include/xo/type", output_impl_subdir: "type", includes: [ - "" + "", + "", ], user_hpp_includes: [ ], @@ -26,6 +27,11 @@ name: "obj_AType", doc: [], definition: "xo::facet::obj", + }, + { + name: "TypeDescr", + doc: [], + definition: "xo::reflect::TypeDescr", } ], const_methods: [ @@ -37,13 +43,22 @@ const: true, noexcept: true, }, + { + name: "repr_td", + doc: ["reflected representation for instances of this type"], + return_type: "TypeDescr", + args: [], + const: true, + noexcept: true, + }, { name: "is_equal_to", doc: ["true iff this type is equal to y"], return_type: "bool", args: [ {type: "const obj_AType &", name: "y"}, - ] + ], + const: true, }, { name: "is_subtype_of", @@ -51,18 +66,9 @@ return_type: "bool", args: [ {type: "const obj_AType &", name: "y"}, - ] + ], + const: true, }, - - // TODO: define methods, e.g.: - // { - // name: "my_method", - // doc: ["description"], - // return_type: "bool", - // args: [], - // const: true, - // noexcept: true, - // }, ], nonconst_methods: [], router_facet_explicit_content: [ diff --git a/include/xo/type/DArrayType.hpp b/include/xo/type/DArrayType.hpp index 945f7f0..a8efe32 100644 --- a/include/xo/type/DArrayType.hpp +++ b/include/xo/type/DArrayType.hpp @@ -20,6 +20,7 @@ namespace xo { public: using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; + using TypeDescr = xo::reflect::TypeDescr; public: /** @defgroup xo-scm-arraytype-ctors **/ @@ -33,7 +34,8 @@ namespace xo { ///@} /** @defgroup xo-scm-arraytype-type-facet **/ ///@{ - Metatype metatype() const noexcept { return Metatype::array(); } + Metatype metatype() const noexcept { return Metatype::t_array(); } + TypeDescr repr_td() const noexcept; bool is_equal_to(const obj & y) const noexcept; bool is_subtype_of(const obj & y) const noexcept; ///@} diff --git a/include/xo/type/DAtomicType.hpp b/include/xo/type/DAtomicType.hpp index 074e0c6..6cd11ba 100644 --- a/include/xo/type/DAtomicType.hpp +++ b/include/xo/type/DAtomicType.hpp @@ -23,16 +23,20 @@ namespace xo { public: using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; + using TypeDescr = xo::reflect::TypeDescr; public: explicit DAtomicType(Metatype m) : metatype_{m} {} /** create instance using memory from @p mm with metatype @p mtype **/ static DAtomicType * _make(obj mm, Metatype mtype); + /** create instance **/ + static obj make(obj mm, Metatype mtype); /** @defgroup xo-scm-atomictype-type-facet **/ ///@{ Metatype metatype() const noexcept { return metatype_; } + TypeDescr repr_td() const noexcept; bool is_equal_to(const obj & y) const noexcept; bool is_subtype_of(const obj & y) const noexcept; ///@} diff --git a/include/xo/type/DFunctionType.hpp b/include/xo/type/DFunctionType.hpp index 3ceafb7..7090a60 100644 --- a/include/xo/type/DFunctionType.hpp +++ b/include/xo/type/DFunctionType.hpp @@ -22,6 +22,7 @@ namespace xo { using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; using AGCObject = xo::mm::AGCObject; + using TypeDescr = xo::reflect::TypeDescr; public: /** @defgroup xo-scm-arraytype-ctors **/ @@ -45,7 +46,8 @@ namespace xo { ///@} /** @defgroup xo-scm-arraytype-type-facet **/ ///@{ - Metatype metatype() const noexcept { return Metatype::array(); } + Metatype metatype() const noexcept { return Metatype::t_array(); } + TypeDescr repr_td() const noexcept; bool is_equal_to(obj y) const noexcept; bool is_subtype_of(const obj & y) const noexcept; ///@} diff --git a/include/xo/type/DListType.hpp b/include/xo/type/DListType.hpp index 41808ce..51db941 100644 --- a/include/xo/type/DListType.hpp +++ b/include/xo/type/DListType.hpp @@ -7,6 +7,7 @@ #include "Type.hpp" #include "Metatype.hpp" +#include #include #include @@ -21,6 +22,7 @@ namespace xo { **/ class DListType { public: + using TypeDescr = xo::reflect::TypeDescr; using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; @@ -31,12 +33,14 @@ namespace xo { explicit DListType(obj elt); /** create instance using memory from @p mm with metatype @p mtype **/ - static DListType * _make(obj mm, obj elt_type); + static DListType * _make(obj mm, + obj elt_type); ///@} /** @defgroup xo-scm-listtype-type-facet **/ ///@{ - Metatype metatype() const noexcept { return Metatype::list(); } + Metatype metatype() const noexcept { return Metatype::t_list(); } + TypeDescr repr_td() const noexcept; bool is_equal_to(const obj & y) const noexcept; bool is_subtype_of(const obj & y) const noexcept; ///@} diff --git a/include/xo/type/Metatype.hpp b/include/xo/type/Metatype.hpp index b8a509e..6fc193a 100644 --- a/include/xo/type/Metatype.hpp +++ b/include/xo/type/Metatype.hpp @@ -14,12 +14,21 @@ namespace xo { enum class code { /* void */ t_unit, - t_bool, - t_i64, - t_f64, t_str, + /* int16_t */ + t_i16, + /* int32_t */ + t_i32, + /* int64_t */ + t_i64, + + /* float */ + t_f32, + /* double */ + t_f64, + /* discriminated union */ t_sum, /* list */ @@ -38,16 +47,24 @@ namespace xo { public: explicit Metatype(code x) : code_{x} {} - static Metatype unit() { return Metatype(code::t_unit); } - static Metatype t_bool() { return Metatype(code::t_bool); } - static Metatype i64() { return Metatype(code::t_i64); } - static Metatype f64() { return Metatype(code::t_f64); } - static Metatype str() { return Metatype(code::t_str); } - static Metatype any() { return Metatype(code::t_any); } + static Metatype t_unit() { return Metatype(code::t_unit); } + static Metatype t_bool() { return Metatype(code::t_bool); } + static Metatype t_str() { return Metatype(code::t_str); } - static Metatype list() { return Metatype(code::t_list); } - static Metatype array() { return Metatype(code::t_array); } - static Metatype function() { return Metatype(code::t_function); } + static Metatype t_i16() { return Metatype(code::t_i16); } + static Metatype t_i32() { return Metatype(code::t_i32); } + static Metatype t_i64() { return Metatype(code::t_i64); } + + static Metatype t_f32() { return Metatype(code::t_f32); } + static Metatype t_f64() { return Metatype(code::t_f64); } + + static Metatype t_sum() { return Metatype(code::t_sum); } + static Metatype t_list() { return Metatype(code::t_list); } + static Metatype t_array() { return Metatype(code::t_array); } + static Metatype t_function() { return Metatype(code::t_function); } + static Metatype t_struct() { return Metatype(code::t_struct); } + + static Metatype t_any() { return Metatype(code::t_any); } /** description string for this type category **/ const char * _descr() const noexcept; diff --git a/include/xo/type/array/IType_DArrayType.hpp b/include/xo/type/array/IType_DArrayType.hpp index e323931..afeb63f 100644 --- a/include/xo/type/array/IType_DArrayType.hpp +++ b/include/xo/type/array/IType_DArrayType.hpp @@ -40,6 +40,7 @@ namespace xo { /** @defgroup scm-type-darraytype-type-traits **/ ///@{ using obj_AType = xo::scm::AType::obj_AType; + using TypeDescr = xo::scm::AType::TypeDescr; using Copaque = xo::scm::AType::Copaque; using Opaque = xo::scm::AType::Opaque; ///@} @@ -48,6 +49,8 @@ namespace xo { // const methods /** category for this type **/ static Metatype metatype(const DArrayType & self) noexcept; + /** reflected representation for instances of this type **/ + static TypeDescr repr_td(const DArrayType & self) noexcept; /** true iff this type is equal to y **/ static bool is_equal_to(const DArrayType & self, const obj_AType & y); /** true iff this is a subtype of y **/ diff --git a/include/xo/type/atomic/IType_DAtomicType.hpp b/include/xo/type/atomic/IType_DAtomicType.hpp index fc73539..5421094 100644 --- a/include/xo/type/atomic/IType_DAtomicType.hpp +++ b/include/xo/type/atomic/IType_DAtomicType.hpp @@ -40,6 +40,7 @@ namespace xo { /** @defgroup scm-type-datomictype-type-traits **/ ///@{ using obj_AType = xo::scm::AType::obj_AType; + using TypeDescr = xo::scm::AType::TypeDescr; using Copaque = xo::scm::AType::Copaque; using Opaque = xo::scm::AType::Opaque; ///@} @@ -48,6 +49,8 @@ namespace xo { // const methods /** category for this type **/ static Metatype metatype(const DAtomicType & self) noexcept; + /** reflected representation for instances of this type **/ + static TypeDescr repr_td(const DAtomicType & self) noexcept; /** true iff this type is equal to y **/ static bool is_equal_to(const DAtomicType & self, const obj_AType & y); /** true iff this is a subtype of y **/ diff --git a/include/xo/type/function/IType_DFunctionType.hpp b/include/xo/type/function/IType_DFunctionType.hpp index b28050a..3dba457 100644 --- a/include/xo/type/function/IType_DFunctionType.hpp +++ b/include/xo/type/function/IType_DFunctionType.hpp @@ -40,6 +40,7 @@ namespace xo { /** @defgroup scm-type-dfunctiontype-type-traits **/ ///@{ using obj_AType = xo::scm::AType::obj_AType; + using TypeDescr = xo::scm::AType::TypeDescr; using Copaque = xo::scm::AType::Copaque; using Opaque = xo::scm::AType::Opaque; ///@} @@ -48,6 +49,8 @@ namespace xo { // const methods /** category for this type **/ static Metatype metatype(const DFunctionType & self) noexcept; + /** reflected representation for instances of this type **/ + static TypeDescr repr_td(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 **/ diff --git a/include/xo/type/list/IType_DListType.hpp b/include/xo/type/list/IType_DListType.hpp index 546b9cb..658348f 100644 --- a/include/xo/type/list/IType_DListType.hpp +++ b/include/xo/type/list/IType_DListType.hpp @@ -40,6 +40,7 @@ namespace xo { /** @defgroup scm-type-dlisttype-type-traits **/ ///@{ using obj_AType = xo::scm::AType::obj_AType; + using TypeDescr = xo::scm::AType::TypeDescr; using Copaque = xo::scm::AType::Copaque; using Opaque = xo::scm::AType::Opaque; ///@} @@ -48,6 +49,8 @@ namespace xo { // const methods /** category for this type **/ static Metatype metatype(const DListType & self) noexcept; + /** reflected representation for instances of this type **/ + static TypeDescr repr_td(const DListType & self) noexcept; /** true iff this type is equal to y **/ static bool is_equal_to(const DListType & self, const obj_AType & y); /** true iff this is a subtype of y **/ diff --git a/include/xo/type/type/AType.hpp b/include/xo/type/type/AType.hpp index dde1480..d0e8361 100644 --- a/include/xo/type/type/AType.hpp +++ b/include/xo/type/type/AType.hpp @@ -15,6 +15,7 @@ // includes (via {facet_includes}) #include +#include #include #include #include @@ -42,6 +43,8 @@ public: using Opaque = void *; /** **/ using obj_AType = xo::facet::obj; + /** **/ + using TypeDescr = xo::reflect::TypeDescr; ///@} /** @defgroup scm-type-methods **/ @@ -53,10 +56,12 @@ public: virtual void _drop(Opaque d) const noexcept = 0; /** category for this type **/ virtual Metatype metatype(Copaque data) const noexcept = 0; + /** reflected representation for instances of this type **/ + virtual TypeDescr repr_td(Copaque data) const noexcept = 0; /** true iff this type is equal to y **/ - virtual bool is_equal_to(Copaque data, const obj_AType & y) = 0; + virtual bool is_equal_to(Copaque data, const obj_AType & y) const = 0; /** true iff this is a subtype of y **/ - virtual bool is_subtype_of(Copaque data, const obj_AType & y) = 0; + virtual bool is_subtype_of(Copaque data, const obj_AType & y) const = 0; // nonconst methods ///@} diff --git a/include/xo/type/type/IType_Any.hpp b/include/xo/type/type/IType_Any.hpp index b8bdb58..624db20 100644 --- a/include/xo/type/type/IType_Any.hpp +++ b/include/xo/type/type/IType_Any.hpp @@ -45,6 +45,7 @@ namespace scm { /** integer identifying a type **/ using typeseq = xo::facet::typeseq; using obj_AType = AType::obj_AType; + using TypeDescr = AType::TypeDescr; ///@} /** @defgroup scm-type-any-methods **/ @@ -60,8 +61,9 @@ namespace scm { // const methods [[noreturn]] Metatype metatype(Copaque) const noexcept override { _fatal(); } - [[noreturn]] bool is_equal_to(Copaque, const obj_AType &) override { _fatal(); } - [[noreturn]] bool is_subtype_of(Copaque, const obj_AType &) override { _fatal(); } + [[noreturn]] TypeDescr repr_td(Copaque) const noexcept override { _fatal(); } + [[noreturn]] bool is_equal_to(Copaque, const obj_AType &) const override { _fatal(); } + [[noreturn]] bool is_subtype_of(Copaque, const obj_AType &) const override { _fatal(); } // nonconst methods diff --git a/include/xo/type/type/IType_Xfer.hpp b/include/xo/type/type/IType_Xfer.hpp index 98b138c..dbc82bc 100644 --- a/include/xo/type/type/IType_Xfer.hpp +++ b/include/xo/type/type/IType_Xfer.hpp @@ -14,6 +14,7 @@ #pragma once #include +#include namespace xo { namespace scm { @@ -29,6 +30,7 @@ namespace scm { /** integer identifying a type **/ using typeseq = AType::typeseq; using obj_AType = AType::obj_AType; + using TypeDescr = AType::TypeDescr; ///@} /** @defgroup scm-type-xfer-methods **/ @@ -47,10 +49,13 @@ namespace scm { Metatype metatype(Copaque data) const noexcept override { return I::metatype(_dcast(data)); } - bool is_equal_to(Copaque data, const obj_AType & y) override { + TypeDescr repr_td(Copaque data) const noexcept override { + return I::repr_td(_dcast(data)); + } + bool is_equal_to(Copaque data, const obj_AType & y) const override { return I::is_equal_to(_dcast(data), y); } - bool is_subtype_of(Copaque data, const obj_AType & y) override { + bool is_subtype_of(Copaque data, const obj_AType & y) const override { return I::is_subtype_of(_dcast(data), y); } diff --git a/include/xo/type/type/RType.hpp b/include/xo/type/type/RType.hpp index 853745e..648749b 100644 --- a/include/xo/type/type/RType.hpp +++ b/include/xo/type/type/RType.hpp @@ -32,6 +32,7 @@ public: using DataPtr = Object::DataPtr; using typeseq = xo::reflect::typeseq; using obj_AType = AType::obj_AType; + using TypeDescr = AType::TypeDescr; ///@} /** @defgroup scm-type-router-ctors **/ @@ -56,10 +57,13 @@ public: Metatype metatype() const noexcept { return O::iface()->metatype(O::data()); } - bool is_equal_to(const obj_AType & y) { + TypeDescr repr_td() const noexcept { + return O::iface()->repr_td(O::data()); + } + bool is_equal_to(const obj_AType & y) const { return O::iface()->is_equal_to(O::data(), y); } - bool is_subtype_of(const obj_AType & y) { + bool is_subtype_of(const obj_AType & y) const { return O::iface()->is_subtype_of(O::data(), y); } diff --git a/src/type/CMakeLists.txt b/src/type/CMakeLists.txt index 3bc7b2e..6d6cdcc 100644 --- a/src/type/CMakeLists.txt +++ b/src/type/CMakeLists.txt @@ -31,6 +31,7 @@ xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 $ # xo-type/cmake/xo_typeConfig.cmake.in xo_dependency(${SELF_LIB} xo_object2) +xo_dependency(${SELF_LIB} reflect) xo_dependency(${SELF_LIB} xo_alloc2) xo_dependency(${SELF_LIB} xo_facet) xo_dependency(${SELF_LIB} subsys) diff --git a/src/type/DArrayType.cpp b/src/type/DArrayType.cpp index de5320e..652186a 100644 --- a/src/type/DArrayType.cpp +++ b/src/type/DArrayType.cpp @@ -5,18 +5,24 @@ #include "Type.hpp" #include "ArrayType.hpp" +#include "TypeDescr.hpp" +#include #include #include #include namespace xo { + using xo::reflect::Reflect; + using xo::reflect::TypeDescr; using xo::mm::AGCObject; using xo::mm::AAllocator; using xo::facet::FacetRegistry; namespace scm { - DArrayType::DArrayType(obj elt) : elt_type_{elt} {} + DArrayType::DArrayType(obj elt) + : elt_type_{elt} + {} DArrayType * DArrayType::_make(obj mm, @@ -29,12 +35,18 @@ namespace xo { // ----- type facet ----- + TypeDescr + DArrayType::repr_td() const noexcept + { + return Reflect::require(); + } + bool DArrayType::is_equal_to(const obj & y_arg) const noexcept { Metatype y_mtype = y_arg.metatype(); - if (y_mtype != Metatype::array()) + if (y_mtype != Metatype::t_array()) return false; auto y = obj::from(y_arg); @@ -49,10 +61,10 @@ namespace xo { { Metatype y_mtype = y_arg.metatype(); - if (y_mtype == Metatype::any()) + if (y_mtype == Metatype::t_any()) return true; - if (y_mtype != Metatype::array()) + if (y_mtype != Metatype::t_array()) return false; auto y = obj::from(y_arg); @@ -81,7 +93,7 @@ namespace xo { { { auto e = FacetRegistry::instance().variant(elt_type_); - gc.forward_inplace(e.iface(), (void **)&(e.data_)); + gc.forward_inplace(e.iface(), (void **)&(elt_type_.data_)); } return this->shallow_size(); diff --git a/src/type/DAtomicType.cpp b/src/type/DAtomicType.cpp index 18c64c8..bc2fe55 100644 --- a/src/type/DAtomicType.cpp +++ b/src/type/DAtomicType.cpp @@ -4,8 +4,12 @@ **/ #include "AtomicType.hpp" +#include namespace xo { + using xo::reflect::Reflect; + using xo::reflect::TypeDescr; + namespace scm { DAtomicType * @@ -16,8 +20,20 @@ namespace xo { return new (mem) DAtomicType(mtype); } + obj + DAtomicType::make(obj mm, Metatype mtype) + { + return obj(_make(mm, mtype)); + } + // ----- Type facet ----- + TypeDescr + DAtomicType::repr_td() const noexcept + { + return Reflect::require(); + } + bool DAtomicType::is_equal_to(const obj & y) const noexcept { diff --git a/src/type/DFunctionType.cpp b/src/type/DFunctionType.cpp index 5fdbbdf..88de628 100644 --- a/src/type/DFunctionType.cpp +++ b/src/type/DFunctionType.cpp @@ -4,21 +4,30 @@ **/ #include "FunctionType.hpp" +#include #include namespace xo { + using xo::reflect::Reflect; + using xo::reflect::TypeDescr; using xo::facet::FacetRegistry; namespace scm { // ----- type facet ----- + TypeDescr + DFunctionType::repr_td() const noexcept + { + return Reflect::require(); + } + bool DFunctionType::is_equal_to(obj y_arg) const noexcept { Metatype y_mtype = y_arg.metatype(); - if (y_mtype != Metatype::function()) + if (y_mtype != Metatype::t_function()) return false; auto y = obj::from(y_arg); @@ -48,10 +57,10 @@ namespace xo { { Metatype y_mtype = y_arg.metatype(); - if (y_mtype == Metatype::any()) + if (y_mtype == Metatype::t_any()) return true; - if (y_mtype != Metatype::function()) + if (y_mtype != Metatype::t_function()) return false; auto y = obj::from(y_arg); @@ -95,7 +104,7 @@ namespace xo { { { auto e = FacetRegistry::instance().variant(return_type_); - gc.forward_inplace(e.iface(), (void **)&(e.data_)); + gc.forward_inplace(e.iface(), (void **)&(return_type_.data_)); } gc.forward_inplace(&arg_types_); diff --git a/src/type/DListType.cpp b/src/type/DListType.cpp index 4be59a3..35b2923 100644 --- a/src/type/DListType.cpp +++ b/src/type/DListType.cpp @@ -5,11 +5,15 @@ #include "Type.hpp" #include "ListType.hpp" +#include "TypeDescr.hpp" +#include #include #include #include namespace xo { + using xo::reflect::Reflect; + using xo::reflect::TypeDescr; using xo::mm::AGCObject; using xo::mm::AAllocator; using xo::facet::FacetRegistry; @@ -29,12 +33,18 @@ namespace xo { // ----- type facet ----- + TypeDescr + DListType::repr_td() const noexcept + { + return Reflect::require(); + } + bool DListType::is_equal_to(const obj & y_arg) const noexcept { Metatype y_mtype = y_arg.metatype(); - if (y_mtype != Metatype::list()) + if (y_mtype != Metatype::t_list()) return false; auto y = obj::from(y_arg); @@ -49,10 +59,10 @@ namespace xo { { Metatype y_mtype = y_arg.metatype(); - if (y_mtype == Metatype::any()) + if (y_mtype == Metatype::t_any()) return true; - if (y_mtype != Metatype::list()) + if (y_mtype != Metatype::t_list()) return false; auto y = obj::from(y_arg); @@ -81,7 +91,7 @@ namespace xo { { { auto e = FacetRegistry::instance().variant(elt_type_); - gc.forward_inplace(e.iface(), (void **)&(e.data_)); + gc.forward_inplace(e.iface(), (void **)&(elt_type_.data_)); } return this->shallow_size(); diff --git a/src/type/IType_DArrayType.cpp b/src/type/IType_DArrayType.cpp index 2ed6010..363e79c 100644 --- a/src/type/IType_DArrayType.cpp +++ b/src/type/IType_DArrayType.cpp @@ -21,6 +21,12 @@ namespace xo { return self.metatype(); } + auto + IType_DArrayType::repr_td(const DArrayType & self) noexcept -> TypeDescr + { + return self.repr_td(); + } + auto IType_DArrayType::is_equal_to(const DArrayType & self, const obj_AType & y) -> bool { diff --git a/src/type/IType_DAtomicType.cpp b/src/type/IType_DAtomicType.cpp index 65fcb02..fd137cb 100644 --- a/src/type/IType_DAtomicType.cpp +++ b/src/type/IType_DAtomicType.cpp @@ -21,6 +21,12 @@ namespace xo { return self.metatype(); } + auto + IType_DAtomicType::repr_td(const DAtomicType & self) noexcept -> TypeDescr + { + return self.repr_td(); + } + auto IType_DAtomicType::is_equal_to(const DAtomicType & self, const obj_AType & y) -> bool { diff --git a/src/type/IType_DFunctionType.cpp b/src/type/IType_DFunctionType.cpp index 230cf67..6e77a15 100644 --- a/src/type/IType_DFunctionType.cpp +++ b/src/type/IType_DFunctionType.cpp @@ -21,6 +21,12 @@ namespace xo { return self.metatype(); } + auto + IType_DFunctionType::repr_td(const DFunctionType & self) noexcept -> TypeDescr + { + return self.repr_td(); + } + auto IType_DFunctionType::is_equal_to(const DFunctionType & self, const obj_AType & y) -> bool { diff --git a/src/type/IType_DListType.cpp b/src/type/IType_DListType.cpp index a29e3d7..9632f40 100644 --- a/src/type/IType_DListType.cpp +++ b/src/type/IType_DListType.cpp @@ -21,6 +21,12 @@ namespace xo { return self.metatype(); } + auto + IType_DListType::repr_td(const DListType & self) noexcept -> TypeDescr + { + return self.repr_td(); + } + auto IType_DListType::is_equal_to(const DListType & self, const obj_AType & y) -> bool { diff --git a/src/type/Metatype.cpp b/src/type/Metatype.cpp index aa97fdc..ca61d9c 100644 --- a/src/type/Metatype.cpp +++ b/src/type/Metatype.cpp @@ -12,17 +12,24 @@ namespace xo { Metatype::_descr() const noexcept { switch (code_) { - case code::t_any: return "any"; + case code::t_unit: return "unit"; case code::t_bool: return "bool"; - case code::t_i64: return "i64"; - case code::t_f64: return "f64"; case code::t_str: return "str"; + + case code::t_i16: return "i16"; + case code::t_i32: return "i32"; + case code::t_i64: return "i64"; + + case code::t_f32: return "f32"; + case code::t_f64: return "f64"; + case code::t_sum: return "sum"; case code::t_list: return "list"; case code::t_array: return "array"; case code::t_function: return "function"; case code::t_struct: return "struct"; - case code::t_unit: return "unit"; + + case code::t_any: return "any"; } } @@ -30,16 +37,26 @@ namespace xo { Metatype::is_atomic() const noexcept { switch (code_) { - case code::t_any: - return true; + case code::t_unit: + return false; + 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_i16: + return true; + case code::t_i32: + return true; + case code::t_i64: + return true; + + case code::t_f32: + return true; + case code::t_f64: + return true; + case code::t_sum: return false; case code::t_list: @@ -50,8 +67,9 @@ namespace xo { return false; case code::t_struct: return false; - case code::t_unit: - return false; + + case code::t_any: + return true; } } diff --git a/utest/DArrayType.test.cpp b/utest/DArrayType.test.cpp index fc4ed8c..5947eb3 100644 --- a/utest/DArrayType.test.cpp +++ b/utest/DArrayType.test.cpp @@ -31,7 +31,7 @@ namespace xo { DArena arena = DArena::map(cfg); auto alloc = obj(&arena); - auto i64_type = TypeOps::atomic_type(alloc, Metatype::i64()); + auto i64_type = TypeOps::atomic_type(alloc, Metatype::t_i64()); auto array_i64_type = TypeOps::array_type(alloc, i64_type); REQUIRE(array_i64_type); @@ -43,7 +43,7 @@ namespace xo { REQUIRE(array_bool_type); REQUIRE(array_bool_type.is_equal_to(array_bool_type)); - auto any_type = TypeOps::atomic_type(alloc, Metatype::any()); + auto any_type = TypeOps::atomic_type(alloc, Metatype::t_any()); auto array_any_type = TypeOps::array_type(alloc, any_type); REQUIRE(array_any_type); diff --git a/utest/DAtomicType.test.cpp b/utest/DAtomicType.test.cpp index 9bab45d..5455701 100644 --- a/utest/DAtomicType.test.cpp +++ b/utest/DAtomicType.test.cpp @@ -28,14 +28,14 @@ namespace xo { DArena arena = DArena::map(cfg); auto alloc = obj(&arena); - auto unit_type = obj(DAtomicType::_make(alloc, Metatype::unit())); - auto i64_type = obj(DAtomicType::_make(alloc, Metatype::i64())); - auto f64_type = obj(DAtomicType::_make(alloc, Metatype::f64())); - auto str_type = obj(DAtomicType::_make(alloc, Metatype::str())); - auto any_type = obj(DAtomicType::_make(alloc, Metatype::any())); + auto unit_type = obj(DAtomicType::_make(alloc, Metatype::t_unit())); + auto i64_type = obj(DAtomicType::_make(alloc, Metatype::t_i64())); + auto f64_type = obj(DAtomicType::_make(alloc, Metatype::t_f64())); + auto str_type = obj(DAtomicType::_make(alloc, Metatype::t_str())); + auto any_type = obj(DAtomicType::_make(alloc, Metatype::t_any())); { REQUIRE(unit_type); - REQUIRE(unit_type.metatype().code() == Metatype::unit().code()); + REQUIRE(unit_type.metatype().code() == Metatype::t_unit().code()); REQUIRE(unit_type.is_equal_to(unit_type)); REQUIRE(unit_type.is_subtype_of(unit_type)); @@ -43,7 +43,7 @@ namespace xo { { REQUIRE(i64_type); - REQUIRE(i64_type.metatype().code() == Metatype::i64().code()); + REQUIRE(i64_type.metatype().code() == Metatype::t_i64().code()); REQUIRE(i64_type.is_equal_to(i64_type)); REQUIRE(i64_type.is_subtype_of(i64_type)); @@ -54,7 +54,7 @@ namespace xo { { REQUIRE(f64_type); - REQUIRE(f64_type.metatype().code() == Metatype::f64().code()); + REQUIRE(f64_type.metatype().code() == Metatype::t_f64().code()); REQUIRE(f64_type.is_equal_to(f64_type)); REQUIRE(f64_type.is_subtype_of(f64_type)); @@ -67,7 +67,7 @@ namespace xo { { REQUIRE(str_type); - REQUIRE(str_type.metatype().code() == Metatype::str().code()); + REQUIRE(str_type.metatype().code() == Metatype::t_str().code()); REQUIRE(str_type.is_equal_to(str_type)); REQUIRE(str_type.is_subtype_of(str_type)); @@ -83,7 +83,7 @@ namespace xo { { REQUIRE(any_type); - REQUIRE(any_type.metatype().code() == Metatype::any().code()); + REQUIRE(any_type.metatype().code() == Metatype::t_any().code()); REQUIRE(any_type.is_equal_to(any_type)); REQUIRE(any_type.is_subtype_of(any_type)); diff --git a/utest/DListType.test.cpp b/utest/DListType.test.cpp index fed5d91..1eace38 100644 --- a/utest/DListType.test.cpp +++ b/utest/DListType.test.cpp @@ -32,7 +32,7 @@ namespace xo { DArena arena = DArena::map(cfg); auto alloc = obj(&arena); - auto i64_type = TypeOps::atomic_type(alloc, Metatype::i64()); + auto i64_type = TypeOps::atomic_type(alloc, Metatype::t_i64()); auto list_i64_type = TypeOps::list_type(alloc, i64_type); REQUIRE(list_i64_type); @@ -44,7 +44,7 @@ namespace xo { REQUIRE(list_bool_type); REQUIRE(list_bool_type.is_equal_to(list_bool_type)); - auto any_type = TypeOps::atomic_type(alloc, Metatype::any()); + auto any_type = TypeOps::atomic_type(alloc, Metatype::t_any()); auto list_any_type = TypeOps::list_type(alloc, any_type); REQUIRE(list_any_type);