xo-alloc xo-object: + Object.self_tp
This commit is contained in:
parent
ea60d107e8
commit
150bfa4aa2
11 changed files with 76 additions and 14 deletions
|
|
@ -12,6 +12,7 @@ namespace xo {
|
|||
explicit Forwarding1(gp<Object> 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;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "xo/reflect/SelfTagging.hpp"
|
||||
#include "xo/reflect/TaggedPtr.hpp"
|
||||
#include "IAlloc.hpp"
|
||||
#include <concepts>
|
||||
#include <cstdint>
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -4,15 +4,25 @@
|
|||
*/
|
||||
|
||||
#include "Forwarding1.hpp"
|
||||
#include "xo/reflect/Reflect.hpp"
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
|
||||
namespace xo {
|
||||
using xo::reflect::Reflect;
|
||||
using xo::reflect::TaggedPtr;
|
||||
|
||||
namespace obj {
|
||||
Forwarding1::Forwarding1(gp<Object> dest)
|
||||
: dest_{dest}
|
||||
{}
|
||||
|
||||
TaggedPtr
|
||||
Forwarding1::self_tp() const
|
||||
{
|
||||
return Reflect::make_tp(const_cast<Forwarding1*>(this));
|
||||
}
|
||||
|
||||
Object *
|
||||
Forwarding1::_offset_destination(Object * src) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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} {}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Object> head, gp<List> rest);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -4,11 +4,16 @@
|
|||
*/
|
||||
|
||||
#include "Boolean.hpp"
|
||||
#include "TaggedPtr.hpp"
|
||||
#include "xo/reflect/Reflect.hpp"
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
namespace xo {
|
||||
using xo::reflect::Reflect;
|
||||
using xo::reflect::TaggedPtr;
|
||||
|
||||
namespace obj {
|
||||
gp<Boolean>
|
||||
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<Boolean*>(this));
|
||||
}
|
||||
|
||||
std::size_t
|
||||
Boolean::_shallow_size() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,9 +4,13 @@
|
|||
*/
|
||||
|
||||
#include "Integer.hpp"
|
||||
#include "xo/reflect/Reflect.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
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<Integer*>(x.ptr());
|
||||
}
|
||||
|
||||
TaggedPtr
|
||||
Integer::self_tp() const {
|
||||
return Reflect::make_tp(const_cast<Integer*>(this));
|
||||
}
|
||||
|
||||
std::size_t
|
||||
Integer::_shallow_size() const {
|
||||
return sizeof(Integer);
|
||||
|
|
|
|||
|
|
@ -4,11 +4,15 @@
|
|||
**/
|
||||
|
||||
#include "List.hpp"
|
||||
#include "xo/reflect/Reflect.hpp"
|
||||
#include "xo/indentlog/scope.hpp"
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
namespace xo {
|
||||
using xo::reflect::Reflect;
|
||||
using xo::reflect::TaggedPtr;
|
||||
|
||||
namespace obj {
|
||||
List::List(gp<Object> head, gp<List> 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<List*>(this));
|
||||
}
|
||||
|
||||
std::size_t
|
||||
List::_shallow_size() const {
|
||||
return sizeof(List);
|
||||
|
|
|
|||
|
|
@ -5,12 +5,17 @@
|
|||
|
||||
#include "String.hpp"
|
||||
#include "GC.hpp"
|
||||
#include "TaggedPtr.hpp"
|
||||
#include "xo/reflect/Reflect.hpp"
|
||||
#include <bsd/string.h>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
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<String*>(this));
|
||||
}
|
||||
|
||||
// ----- GC support -----
|
||||
|
||||
std::size_t
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue