xo-interpreter2 stack: refactor: move cons() pm to object2/

This commit is contained in:
Roland Conybeare 2026-03-15 11:51:37 -05:00
commit 7be6463835
3 changed files with 28 additions and 1 deletions

View file

@ -21,9 +21,12 @@ namespace xo {
using AAllocator = xo::mm::AAllocator;
public:
/** create primitive for fetching nth element of a sequence **/
/** create primitive: fetch nth element of a sequence **/
static DPrimitive_gco_2_gco_gco * make_nth_pm(obj<AAllocator> mm);
/** create primitive: create cons cell **/
static DPrimitive_gco_2_gco_gco * make_cons_pm(obj<AAllocator> mm);
/** create pirmitive for creating a dictionary instance **/
static DPrimitive_gco_0 * make_dict_make_pm(obj<AAllocator> mm);

View file

@ -6,6 +6,7 @@
#include "ObjectPrimitives.hpp"
#include <xo/object2/Dictionary.hpp>
#include <xo/object2/Sequence.hpp>
#include <xo/object2/List.hpp>
#include <xo/object2/Integer.hpp>
#include <xo/printable2/Printable.hpp>
#include <xo/stringtable2/String.hpp>
@ -44,6 +45,28 @@ namespace xo {
return DPrimitive_gco_2_gco_gco::_make(mm, "nth", &xfer_nth);
}
// ----- cons -----
obj<AGCObject>
xfer_cons(obj<ARuntimeContext> rcx,
obj<AGCObject> car,
obj<AGCObject> cdr)
{
(void)rcx;
auto cdr_list = obj<AGCObject,DList>::from(cdr);
return DList::cons(rcx.allocator(),
car,
cdr_list.data());
}
DPrimitive_gco_2_gco_gco *
ObjectPrimitives::make_cons_pm(obj<AAllocator> mm)
{
return DPrimitive_gco_2_gco_gco::_make(mm, "cons", &xfer_cons);
}
// ----- dict_make -----
obj<AGCObject>

View file

@ -62,6 +62,7 @@ namespace xo {
bool ok = true;
ok = ok & install_aux(sink, ObjectPrimitives::make_nth_pm(mm), flags);
ok = ok & install_aux(sink, ObjectPrimitives::make_cons_pm(mm), flags);
ok = ok & install_aux(sink, ObjectPrimitives::make_dict_make_pm(mm), flags);
ok = ok & install_aux(sink, ObjectPrimitives::make_dict_upsert_pm(mm), flags);