xo-interpreter2 stack: refactor: move cwd() -> ObjectPrimitives

This commit is contained in:
Roland Conybeare 2026-03-15 14:25:35 -05:00
commit 32b26d1163
3 changed files with 22 additions and 0 deletions

View file

@ -21,6 +21,9 @@ namespace xo {
using AAllocator = xo::mm::AAllocator;
public:
/** create primitive: report current working directory **/
static DPrimitive_gco_0 * make_cwd_pm(obj<AAllocator> mm);
/** create primitive: fetch nth element of a sequence **/
static DPrimitive_gco_2_gco_gco * make_nth_pm(obj<AAllocator> mm);

View file

@ -10,6 +10,7 @@
#include <xo/object2/Integer.hpp>
#include <xo/printable2/Printable.hpp>
#include <xo/stringtable2/String.hpp>
#include <unistd.h> // for getcwd()
namespace xo {
using xo::scm::ASequence;
@ -21,6 +22,23 @@ namespace xo {
namespace scm {
// ----- cwd -----
obj<AGCObject>
xfer_cwd(obj<ARuntimeContext> rcx)
{
char buf[PATH_MAX];
::getcwd(buf, sizeof(buf));
return obj<AGCObject,DString>(DString::from_cstr(rcx.allocator(), buf));
}
DPrimitive_gco_0 *
ObjectPrimitives::make_cwd_pm(obj<AAllocator> mm)
{
return DPrimitive_gco_0::_make(mm, "cwd", &xfer_cwd);
}
// ----- nth -----
// TODO: seq_gc -> obj<ASequence>

View file

@ -61,6 +61,7 @@ namespace xo {
bool ok = true;
ok = ok & install_aux(sink, ObjectPrimitives::make_cwd_pm(mm), flags);
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);