xo-interpreter2 stack: modularize nth() primitive setup/install

This commit is contained in:
Roland Conybeare 2026-03-15 09:47:14 -05:00
commit 6d6066995a
7 changed files with 158 additions and 2 deletions

View file

@ -0,0 +1,45 @@
/** @file ObjectPrimitives.cpp
*
* @author Roland Conybeare, Mar 2026
**/
#include "ObjectPrimitives.hpp"
#include "Primitive_gco_2_gco_gco.hpp"
#include <xo/object2/Sequence.hpp>
#include <xo/object2/Integer.hpp>
namespace xo {
using xo::scm::ASequence;
using xo::mm::AAllocator;
using xo::mm::AGCObject;
namespace scm {
// TODO: seq_gc -> obj<ASequence>
// n_gco -> obj<AGCObject,DInteger>
//
obj<AGCObject>
xfer_nth(obj<ARuntimeContext> rcx,
obj<AGCObject> seq_gco,
obj<AGCObject> n_gco)
{
scope log(XO_DEBUG(true));
(void)rcx;
obj<ASequence> seq = seq_gco.to_facet<ASequence>();
auto n = obj<AGCObject,DInteger>::from(n_gco);
return seq.at(n->value());
}
DPrimitive_gco_2_gco_gco *
ObjectPrimitives::make_nth_pm(obj<AAllocator> mm)
{
return DPrimitive_gco_2_gco_gco::_make(mm, "nth", &xfer_nth);
}
} /*namespace scm*/
} /*namespace xo*/
/* end ObjectPrimitives.cpp */