xo-alloc: mutation log tracking in working state + unit test
This commit is contained in:
parent
e1d5ae46d2
commit
5d2fcf6498
25 changed files with 735 additions and 185 deletions
|
|
@ -1,37 +0,0 @@
|
|||
/* @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 */
|
||||
|
|
@ -15,7 +15,12 @@ namespace xo {
|
|||
Integer() = default;
|
||||
explicit Integer(int_type x);
|
||||
|
||||
/** create instance holding integer value @p x **/
|
||||
static gp<Integer> make(int_type x);
|
||||
/** downcast from @p x iff x is actually an Integer. Otherwise nullptr **/
|
||||
static gp<Integer> from(gp<Object> x);
|
||||
|
||||
int_type value() const { return value_; }
|
||||
|
||||
// inherited from Object..
|
||||
virtual std::size_t _shallow_size() const override;
|
||||
|
|
|
|||
|
|
@ -18,14 +18,36 @@ namespace xo {
|
|||
/** @return list with first element @p car, and tail @p cdr **/
|
||||
static gp<List> cons(gp<Object> car, gp<List> cdr);
|
||||
|
||||
/** @return list with single element @p x1 **/
|
||||
template <typename T>
|
||||
static gp<List> list(T && x1) {
|
||||
return List::cons(x1, nil);
|
||||
}
|
||||
|
||||
/** @return list with elements @p x1, ..., @p rest in argument order **/
|
||||
template <typename T, typename... Rest>
|
||||
static gp<List> list(T && x1, Rest &&... rest) {
|
||||
return List::cons(x1, list(rest...));
|
||||
}
|
||||
|
||||
/** @return true iff list is empty **/
|
||||
bool is_nil() const { return this == nil.ptr(); }
|
||||
|
||||
gp<Object> head() const { return head_; }
|
||||
gp<List> tail() const { return tail_; }
|
||||
gp<List> rest() const { return rest_; }
|
||||
|
||||
/** @return first element in list; synonym for @ref head **/
|
||||
gp<Object> car() const { return head_; }
|
||||
/** @return remainder of list after first element; synonym for @ref rest **/
|
||||
gp<Object> cdr() const { return rest_; }
|
||||
|
||||
/** @return number of top-level elements in this list **/
|
||||
std::size_t size() const;
|
||||
gp<Object> list_ref(std::size_t i) const;
|
||||
|
||||
void assign_head(gp<Object> head);
|
||||
void assign_rest(gp<List> rest);
|
||||
|
||||
// inherited from Object..
|
||||
|
||||
virtual std::size_t _shallow_size() const override;
|
||||
|
|
@ -33,11 +55,11 @@ namespace xo {
|
|||
virtual std::size_t _forward_children() override;
|
||||
|
||||
private:
|
||||
List(gp<Object> head, gp<List> tail);
|
||||
List(gp<Object> head, gp<List> rest);
|
||||
|
||||
private:
|
||||
gp<Object> head_;
|
||||
gp<List> tail_;
|
||||
gp<List> rest_;
|
||||
};
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace xo {
|
|||
public:
|
||||
enum Owner { unique, shared };
|
||||
|
||||
/** donwcase from @p x iff x is actually a String. Otherwise nullptr **/
|
||||
/** donwcast 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 **/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue