xo-objectd2 xo-printable xo-facet: pp working for List(Integer)

Also streamline facet switching
This commit is contained in:
Roland Conybeare 2026-01-09 17:48:54 -05:00
commit 09ee3a20ac
23 changed files with 508 additions and 27 deletions

View file

@ -13,6 +13,7 @@
namespace xo {
namespace scm {
// TODO: consider renaming to DCons
struct DList {
using size_type = std::size_t;
using AGCObject = xo::mm::AGCObject;
@ -22,8 +23,27 @@ namespace xo {
DList(xo::obj<AGCObject> h,
DList * r) : head_{h}, rest_{r} {}
template <typename AConsFacet = AGCObject>
static obj<AConsFacet,DList> nil();
/** shortcut for
* cons(mm, cdr, cdr.data())
**/
template <typename AConsFacet = AGCObject, typename ACdrFacet = AGCObject>
static obj<AConsFacet,DList> cons(obj<AAllocator> mm,
obj<AGCObject> car,
obj<ACdrFacet,DList> cdr);
/** sentinel for null list **/
static DList * null();
static DList * _nil();
/** list with first element @p car,
* followed by contents of list @p cdr.
* Shares structure with @p cdr
**/
static DList * _cons(obj<AAllocator> mm,
obj<AGCObject> car,
DList * cdr);
/** list with one element @p h1, allocated from @p mm **/
static DList * list(obj<AAllocator> mm,
@ -51,6 +71,22 @@ namespace xo {
DList * rest_ = nullptr;
};
template <typename AConsFacet>
obj<AConsFacet,DList>
DList::nil()
{
return obj<AConsFacet,DList>(DList::_nil());
}
template <typename AConsFacet, typename ACdrFacet>
obj<AConsFacet,DList>
DList::cons(obj<AAllocator> mm,
obj<AGCObject> car,
obj<ACdrFacet,DList> cdr)
{
return obj<AConsFacet,DList>(DList::_cons(mm, car, cdr.data()));
}
} /*namespace scm*/
} /*namespace xo*/