diff --git a/xo-alloc/include/xo/alloc/Forwarding1.hpp b/xo-alloc/include/xo/alloc/Forwarding1.hpp index 4fb61d08..17a38df2 100644 --- a/xo-alloc/include/xo/alloc/Forwarding1.hpp +++ b/xo-alloc/include/xo/alloc/Forwarding1.hpp @@ -12,6 +12,7 @@ namespace xo { explicit Forwarding1(gp dest); // inherited from Object.. + virtual TaggedPtr self_tp() const final override; virtual bool _is_forwarded() const final override { return true; } virtual Object * _offset_destination(Object * src) const final override; virtual Object * _destination() final override; diff --git a/xo-alloc/include/xo/alloc/Object.hpp b/xo-alloc/include/xo/alloc/Object.hpp index 347b5018..47b26261 100644 --- a/xo-alloc/include/xo/alloc/Object.hpp +++ b/xo-alloc/include/xo/alloc/Object.hpp @@ -5,7 +5,7 @@ #pragma once -#include "xo/reflect/SelfTagging.hpp" +#include "xo/reflect/TaggedPtr.hpp" #include "IAlloc.hpp" #include #include @@ -79,6 +79,9 @@ namespace xo { * but cost would be an extra layer of indirection **/ class Object { + public: + using TaggedPtr = xo::reflect::TaggedPtr; + public: virtual ~Object() = default; @@ -148,6 +151,12 @@ namespace xo { **/ static Object * _shallow_move(Object * src, gc::GC * gc); + // Reflection support + + /** tagged pointer with runtime type information + **/ + virtual TaggedPtr self_tp() const = 0; + // GC support /** true iff this object represents a forwarding pointer. diff --git a/xo-alloc/src/alloc/Forwarding1.cpp b/xo-alloc/src/alloc/Forwarding1.cpp index 32d95b60..2122d248 100644 --- a/xo-alloc/src/alloc/Forwarding1.cpp +++ b/xo-alloc/src/alloc/Forwarding1.cpp @@ -4,15 +4,25 @@ */ #include "Forwarding1.hpp" +#include "xo/reflect/Reflect.hpp" #include #include namespace xo { + using xo::reflect::Reflect; + using xo::reflect::TaggedPtr; + namespace obj { Forwarding1::Forwarding1(gp dest) : dest_{dest} {} + TaggedPtr + Forwarding1::self_tp() const + { + return Reflect::make_tp(const_cast(this)); + } + Object * Forwarding1::_offset_destination(Object * src) const { diff --git a/xo-object/include/xo/object/Boolean.hpp b/xo-object/include/xo/object/Boolean.hpp index 68d3d687..883ace32 100644 --- a/xo-object/include/xo/object/Boolean.hpp +++ b/xo-object/include/xo/object/Boolean.hpp @@ -21,9 +21,10 @@ namespace xo { // inherited from Object.. - virtual std::size_t _shallow_size() const override; - virtual Object * _shallow_copy() const override; - virtual std::size_t _forward_children() override; + virtual TaggedPtr self_tp() const final override; + virtual std::size_t _shallow_size() const final override; + virtual Object * _shallow_copy() const final override; + virtual std::size_t _forward_children() final override; private: explicit Boolean(bool x) : value_{x} {} diff --git a/xo-object/include/xo/object/Integer.hpp b/xo-object/include/xo/object/Integer.hpp index ad9f80e3..9f6b2aca 100644 --- a/xo-object/include/xo/object/Integer.hpp +++ b/xo-object/include/xo/object/Integer.hpp @@ -23,9 +23,10 @@ namespace xo { int_type value() const { return value_; } // inherited from Object.. - virtual std::size_t _shallow_size() const override; - virtual Object * _shallow_copy() const override; - virtual std::size_t _forward_children() override; + virtual TaggedPtr self_tp() const final override; + virtual std::size_t _shallow_size() const final override; + virtual Object * _shallow_copy() const final override; + virtual std::size_t _forward_children() final override; private: int_type value_ = 0; diff --git a/xo-object/include/xo/object/List.hpp b/xo-object/include/xo/object/List.hpp index caf3be5a..2cbfa857 100644 --- a/xo-object/include/xo/object/List.hpp +++ b/xo-object/include/xo/object/List.hpp @@ -53,9 +53,10 @@ namespace xo { // inherited from Object.. - virtual std::size_t _shallow_size() const override; - virtual Object * _shallow_copy() const override; - virtual std::size_t _forward_children() override; + virtual TaggedPtr self_tp() const final override; + virtual std::size_t _shallow_size() const final override; + virtual Object * _shallow_copy() const final override; + virtual std::size_t _forward_children() final override; private: List(gp head, gp rest); diff --git a/xo-object/include/xo/object/String.hpp b/xo-object/include/xo/object/String.hpp index a2719318..0532c06f 100644 --- a/xo-object/include/xo/object/String.hpp +++ b/xo-object/include/xo/object/String.hpp @@ -31,10 +31,10 @@ namespace xo { std::size_t length() const; // inherited from Object.. - - virtual std::size_t _shallow_size() const override; - virtual Object * _shallow_copy() const override; - virtual std::size_t _forward_children() override; + virtual TaggedPtr self_tp() const final override; + virtual std::size_t _shallow_size() const final override; + virtual Object * _shallow_copy() const final override; + virtual std::size_t _forward_children() final override; private: String(owner owner, std::size_t z, char * s); diff --git a/xo-object/src/object/Boolean.cpp b/xo-object/src/object/Boolean.cpp index ad5bbeb7..afb30232 100644 --- a/xo-object/src/object/Boolean.cpp +++ b/xo-object/src/object/Boolean.cpp @@ -4,11 +4,16 @@ */ #include "Boolean.hpp" +#include "TaggedPtr.hpp" +#include "xo/reflect/Reflect.hpp" #include #include #include namespace xo { + using xo::reflect::Reflect; + using xo::reflect::TaggedPtr; + namespace obj { gp Boolean::boolean_obj(bool x) @@ -31,6 +36,12 @@ namespace xo { return boolean_obj(false); } + TaggedPtr + Boolean::self_tp() const + { + return Reflect::make_tp(const_cast(this)); + } + std::size_t Boolean::_shallow_size() const { diff --git a/xo-object/src/object/Integer.cpp b/xo-object/src/object/Integer.cpp index fe4454da..94f51bbb 100644 --- a/xo-object/src/object/Integer.cpp +++ b/xo-object/src/object/Integer.cpp @@ -4,9 +4,13 @@ */ #include "Integer.hpp" +#include "xo/reflect/Reflect.hpp" #include namespace xo { + using xo::reflect::Reflect; + using xo::reflect::TaggedPtr; + namespace obj { Integer::Integer(int_type x) : value_{x} {} @@ -20,6 +24,11 @@ namespace xo { return dynamic_cast(x.ptr()); } + TaggedPtr + Integer::self_tp() const { + return Reflect::make_tp(const_cast(this)); + } + std::size_t Integer::_shallow_size() const { return sizeof(Integer); diff --git a/xo-object/src/object/List.cpp b/xo-object/src/object/List.cpp index 00e9c19c..2cf9f5a3 100644 --- a/xo-object/src/object/List.cpp +++ b/xo-object/src/object/List.cpp @@ -4,11 +4,15 @@ **/ #include "List.hpp" +#include "xo/reflect/Reflect.hpp" #include "xo/indentlog/scope.hpp" #include #include namespace xo { + using xo::reflect::Reflect; + using xo::reflect::TaggedPtr; + namespace obj { List::List(gp head, gp rest) : head_{head}, rest_{rest} {} @@ -66,6 +70,11 @@ namespace xo { Object::assign_member(this, &(this->rest_), tail); } + TaggedPtr + List::self_tp() const { + return Reflect::make_tp(const_cast(this)); + } + std::size_t List::_shallow_size() const { return sizeof(List); diff --git a/xo-object/src/object/String.cpp b/xo-object/src/object/String.cpp index e2767673..1d420e7d 100644 --- a/xo-object/src/object/String.cpp +++ b/xo-object/src/object/String.cpp @@ -5,12 +5,17 @@ #include "String.hpp" #include "GC.hpp" +#include "TaggedPtr.hpp" +#include "xo/reflect/Reflect.hpp" #include #include #include #include namespace xo { + using xo::reflect::Reflect; + using xo::reflect::TaggedPtr; + namespace obj { String::String(owner owner, std::size_t z, char * s) : owner_{owner}, z_chars_{z}, chars_{s} @@ -86,6 +91,11 @@ namespace xo { return ::strlen(chars_); } + TaggedPtr + String::self_tp() const { + return Reflect::make_tp(const_cast(this)); + } + // ----- GC support ----- std::size_t