+ xo-alloc + xo-object + xo-alloc docs + GC utests
This commit is contained in:
parent
03c8d66401
commit
e1d5ae46d2
58 changed files with 3948 additions and 83 deletions
37
xo-object/include/xo/object/Boolean.hpp
Normal file
37
xo-object/include/xo/object/Boolean.hpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* @file Boolean.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "xo/alloc/Object.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obj {
|
||||
/** @class Boolean
|
||||
* @brief Boxed wrapper for a boolean value
|
||||
**/
|
||||
class Boolean : public Object {
|
||||
public:
|
||||
/** @return instance representing boolean with truth-value @p x **/
|
||||
static gp<Boolean> boolean_obj(bool x);
|
||||
static gp<Boolean> true_obj();
|
||||
static gp<Boolean> false_obj();
|
||||
|
||||
bool 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;
|
||||
|
||||
private:
|
||||
explicit Boolean(bool x) : value_{x} {}
|
||||
|
||||
private:
|
||||
bool value_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/* end Boolean.hpp */
|
||||
37
xo-object/include/xo/object/BooleanObj.hpp
Normal file
37
xo-object/include/xo/object/BooleanObj.hpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* @file BooleanObj.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "xo/alloc/Object.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obj {
|
||||
/** @class BooleanObj
|
||||
* @brief Boxed wrapper for a boolean value
|
||||
**/
|
||||
class BooleanObj : public Object {
|
||||
public:
|
||||
/** @return instance representing boolean with truth-value @p x **/
|
||||
static gp<BooleanObj> boolean_obj(bool x);
|
||||
static gp<BooleanObj> true_obj();
|
||||
static gp<BooleanObj> false_obj();
|
||||
|
||||
bool 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;
|
||||
|
||||
private:
|
||||
explicit BooleanObj(bool x) : value_{x} {}
|
||||
|
||||
private:
|
||||
bool value_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/* end BooleanObj.hpp */
|
||||
21
xo-object/include/xo/object/Collection.hpp
Normal file
21
xo-object/include/xo/object/Collection.hpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* @file Collection.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "xo/alloc/Object.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obj {
|
||||
class Collection : public Object {
|
||||
// inherited from Object..
|
||||
|
||||
//virtual std::size_t _shallow_size() const override;
|
||||
//virtual Object * _shallow_copy() const override;
|
||||
//virtual std::size_t _forward_children() override;
|
||||
};
|
||||
|
||||
} /*namespace obj*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Collection.hpp */
|
||||
31
xo-object/include/xo/object/Integer.hpp
Normal file
31
xo-object/include/xo/object/Integer.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* @file Integer.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "Number.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obj {
|
||||
class Integer : public Number {
|
||||
public:
|
||||
using int_type = long long;
|
||||
|
||||
public:
|
||||
Integer() = default;
|
||||
explicit Integer(int_type x);
|
||||
|
||||
static gp<Integer> make(int_type x);
|
||||
|
||||
// inherited from Object..
|
||||
virtual std::size_t _shallow_size() const override;
|
||||
virtual Object * _shallow_copy() const override;
|
||||
virtual std::size_t _forward_children() override;
|
||||
|
||||
private:
|
||||
int_type value_ = 0;
|
||||
};
|
||||
} /*namespace obj*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Integer.hpp */
|
||||
43
xo-object/include/xo/object/List.hpp
Normal file
43
xo-object/include/xo/object/List.hpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* @file List.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "Sequence.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obj {
|
||||
/** @class List
|
||||
* @brief A list element -- aka cons cell
|
||||
**/
|
||||
class List : public Sequence {
|
||||
public:
|
||||
/** the empty list. unique sentinel object **/
|
||||
static gp<List> nil;
|
||||
|
||||
/** @return list with first element @p car, and tail @p cdr **/
|
||||
static gp<List> cons(gp<Object> car, gp<List> cdr);
|
||||
|
||||
bool is_nil() const { return this == nil.ptr(); }
|
||||
|
||||
gp<Object> head() const { return head_; }
|
||||
gp<List> tail() const { return tail_; }
|
||||
|
||||
std::size_t size() const;
|
||||
gp<Object> list_ref(std::size_t i) 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;
|
||||
|
||||
private:
|
||||
List(gp<Object> head, gp<List> tail);
|
||||
|
||||
private:
|
||||
gp<Object> head_;
|
||||
gp<List> tail_;
|
||||
};
|
||||
}
|
||||
} /*namespace xo*/
|
||||
20
xo-object/include/xo/object/Number.hpp
Normal file
20
xo-object/include/xo/object/Number.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* @file Number.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "Scalar.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obj {
|
||||
class Number : public Scalar {
|
||||
// inherited from Object..
|
||||
|
||||
//virtual std::size_t _shallow_size() const override;
|
||||
//virtual Object * _shallow_copy() override;
|
||||
//virtual std::size_t _forward_children() override;
|
||||
};
|
||||
} /*namespace obj*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Number.hpp */
|
||||
20
xo-object/include/xo/object/Numeric.hpp
Normal file
20
xo-object/include/xo/object/Numeric.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* @file Numeric.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "xo/alloc/Object.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obj {
|
||||
class Numeric : public Object {
|
||||
// inherited from Object..
|
||||
|
||||
//virtual std::size_t _shallow_size() const override;
|
||||
//virtual Object * _shallow_copy() override;
|
||||
//virtual std::size_t _forward_children() override;
|
||||
};
|
||||
} /*namespace obj*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Numeric.hpp */
|
||||
20
xo-object/include/xo/object/Scalar.hpp
Normal file
20
xo-object/include/xo/object/Scalar.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* @file Scalar.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "Numeric.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obj {
|
||||
class Scalar : public Numeric {
|
||||
// inherited from Object..
|
||||
|
||||
//virtual std::size_t _shallow_size() const override;
|
||||
//virtual Object * _shallow_copy() override;
|
||||
//virtual std::size_t _forward_children() override;
|
||||
};
|
||||
} /*namespace obj*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Scalar.hpp */
|
||||
20
xo-object/include/xo/object/Sequence.hpp
Normal file
20
xo-object/include/xo/object/Sequence.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* @file Sequence.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "Collection.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obj {
|
||||
class Sequence : public Collection {
|
||||
// inherited from Object..
|
||||
|
||||
//virtual std::size_t _shallow_size() const override;
|
||||
//virtual Object * _shallow_copy() const override;
|
||||
//virtual std::size_t _fixup_forwarded_children() override;
|
||||
};
|
||||
} /*namespace obj*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Sequence.hpp */
|
||||
54
xo-object/include/xo/object/String.hpp
Normal file
54
xo-object/include/xo/object/String.hpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* @file String.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "xo/alloc/IAlloc.hpp"
|
||||
#include "xo/alloc/Object.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obj {
|
||||
class String : public Object {
|
||||
public:
|
||||
enum Owner { unique, shared };
|
||||
|
||||
/** donwcase from @p x iff x is actually a String. Otherwise nullptr **/
|
||||
static gp<String> from(gp<Object> x);
|
||||
|
||||
/** create copy of string @p s, using allocator @ref Object::mm **/
|
||||
static gp<String> copy(const char * s);
|
||||
/** create copy of string @p s, using allocator @p mm **/
|
||||
static gp<String> copy(gc::IAlloc * mm, const char * s);
|
||||
|
||||
/** create empty string with @p z bytes of string space **/
|
||||
static gp<String> allocate(std::size_t z);
|
||||
/** create string containing contents of @p s1 follwed by contents of @p s2 **/
|
||||
static gp<String> append(gp<String> s1, gp<String> s2);
|
||||
|
||||
const char * c_str() const { return chars_; }
|
||||
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;
|
||||
|
||||
private:
|
||||
String(Owner owner, std::size_t z, char * s);
|
||||
/** create instance, copying string contents (when @p copy_flag is true) using allocator @p mm **/
|
||||
String(gc::IAlloc * mm, Owner owner, std::size_t z, char * s, bool copy);
|
||||
|
||||
private:
|
||||
/** true iff storage in @ref chars_ is owned by this String.
|
||||
**/
|
||||
Owner owner_ = Owner::shared;
|
||||
/** length of @ref chars_ in bytes (storage allocated, not necessarily string length) **/
|
||||
std::size_t z_chars_ = 0;
|
||||
/** string contents. always null-terminated **/
|
||||
char * chars_ = nullptr;
|
||||
};
|
||||
} /*namespace obj*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end String.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue