xo-interpreter2: + nil + cons
This commit is contained in:
parent
84ddc0338b
commit
87f08a4e4d
2 changed files with 24 additions and 4 deletions
|
|
@ -26,11 +26,14 @@ namespace xo {
|
||||||
DList(xo::obj<AGCObject> h,
|
DList(xo::obj<AGCObject> h,
|
||||||
DList * r) : head_{h}, rest_{r} {}
|
DList * r) : head_{h}, rest_{r} {}
|
||||||
|
|
||||||
/** sentinel for null list.
|
/** sentinel for null list. Idempotent.
|
||||||
* Application code may prefer ListOps::nil()
|
* Application code may prefer ListOps::nil()
|
||||||
**/
|
**/
|
||||||
static DList * _nil();
|
static DList * _nil();
|
||||||
|
|
||||||
|
/** like _nil(), but retrn fop wrapper **/
|
||||||
|
static obj<AGCObject,DList> nil();
|
||||||
|
|
||||||
/** list with first element @p car,
|
/** list with first element @p car,
|
||||||
* followed by contents of list @p cdr.
|
* followed by contents of list @p cdr.
|
||||||
* Shares structure with @p cdr
|
* Shares structure with @p cdr
|
||||||
|
|
@ -40,6 +43,11 @@ namespace xo {
|
||||||
obj<AGCObject> car,
|
obj<AGCObject> car,
|
||||||
DList * cdr);
|
DList * cdr);
|
||||||
|
|
||||||
|
/** like @c _cons(mm,car,cdr), but return fop wrapper **/
|
||||||
|
static obj<AGCObject,DList> cons(obj<AAllocator> mm,
|
||||||
|
obj<AGCObject> car,
|
||||||
|
DList * cdr);
|
||||||
|
|
||||||
/** DList length is at least 1 **/
|
/** DList length is at least 1 **/
|
||||||
bool is_empty() const noexcept;
|
bool is_empty() const noexcept;
|
||||||
/** DList models a finite sequence **/
|
/** DList models a finite sequence **/
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace xo {
|
||||||
using xo::print::APrintable;
|
using xo::print::APrintable;
|
||||||
using xo::mm::AGCObject;
|
using xo::mm::AGCObject;
|
||||||
using xo::facet::FacetRegistry;
|
using xo::facet::FacetRegistry;
|
||||||
using xo::facet::typeseq;
|
//using xo::facet::typeseq;
|
||||||
|
|
||||||
namespace scm {
|
namespace scm {
|
||||||
static DList s_null(obj<AGCObject>(), nullptr);
|
static DList s_null(obj<AGCObject>(), nullptr);
|
||||||
|
|
@ -28,6 +28,12 @@ namespace xo {
|
||||||
return &s_null;
|
return &s_null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obj<AGCObject,DList>
|
||||||
|
DList::nil()
|
||||||
|
{
|
||||||
|
return obj<AGCObject,DList>(_nil());
|
||||||
|
}
|
||||||
|
|
||||||
DList *
|
DList *
|
||||||
DList::_cons(obj<AAllocator> mm,
|
DList::_cons(obj<AAllocator> mm,
|
||||||
obj<AGCObject> car,
|
obj<AGCObject> car,
|
||||||
|
|
@ -38,6 +44,14 @@ namespace xo {
|
||||||
return new (mem) DList(car, cdr);
|
return new (mem) DList(car, cdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obj<AGCObject,DList>
|
||||||
|
DList::cons(obj<AAllocator> mm,
|
||||||
|
obj<AGCObject> car,
|
||||||
|
DList * cdr)
|
||||||
|
{
|
||||||
|
return obj<AGCObject,DList>(_cons(mm, car, cdr));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef OBSOLETE
|
#ifdef OBSOLETE
|
||||||
DList *
|
DList *
|
||||||
DList::list(obj<AAllocator> mm,
|
DList::list(obj<AAllocator> mm,
|
||||||
|
|
@ -137,8 +151,6 @@ namespace xo {
|
||||||
obj<APrintable> elt
|
obj<APrintable> elt
|
||||||
= FacetRegistry::instance().variant<APrintable, AGCObject>(l->head_);
|
= FacetRegistry::instance().variant<APrintable, AGCObject>(l->head_);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
assert(elt.data());
|
assert(elt.data());
|
||||||
|
|
||||||
if (!pps->print_upto(elt))
|
if (!pps->print_upto(elt))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue