xo-interpreter2 stack: refactor: move cwd() -> ObjectPrimitives
This commit is contained in:
parent
c421eb979e
commit
04a0caf209
4 changed files with 22 additions and 27 deletions
|
|
@ -37,7 +37,6 @@
|
|||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
#include <cassert>
|
||||
#include <unistd.h> // for getcwd()
|
||||
|
||||
namespace xo {
|
||||
using xo::scm::DDictionary;
|
||||
|
|
@ -876,20 +875,6 @@ namespace xo {
|
|||
}
|
||||
}
|
||||
|
||||
// ----- primitive: 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));
|
||||
}
|
||||
|
||||
static DPrimitive_gco_0 s_cwd_pm("_cwd",
|
||||
&xfer_cwd);
|
||||
|
||||
// ----- primitive: fn_n_args() -----
|
||||
|
||||
obj<AGCObject>
|
||||
|
|
@ -916,18 +901,6 @@ namespace xo {
|
|||
void
|
||||
VirtualSchematikaMachine::install_core_primitives()
|
||||
{
|
||||
/* cwd */
|
||||
{
|
||||
const DUniqueString * name
|
||||
= reader_.intern_string("cwd");
|
||||
|
||||
global_env_->_upsert_value
|
||||
(mm_.to_op(),
|
||||
name,
|
||||
Reflect::require<DPrimitive_gco_0>(),
|
||||
obj<AGCObject,DPrimitive_gco_0>(&s_cwd_pm));
|
||||
}
|
||||
|
||||
/* fn_n_args */
|
||||
{
|
||||
const DUniqueString * name
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue