xo-interpreter2 stack: move fn_n_args() to ObjectPrimitives

This commit is contained in:
Roland Conybeare 2026-03-15 14:35:44 -05:00
commit e644a59a11
5 changed files with 29 additions and 44 deletions

View file

@ -100,9 +100,6 @@ namespace xo {
/** visit vsm-owned memory pools; call visitor(info) for each **/
void visit_pools(const MemorySizeVisitor & visitor) const;
/** install hardwired functions into global {symtab,env} **/
void install_core_primitives();
/** begin interactive session. **/
void begin_interactive_session();
/** begin batch session **/

View file

@ -86,8 +86,6 @@ namespace xo {
}
this->global_env_ = reader_.global_env();
this->install_core_primitives();
}
obj<AAllocator>
@ -875,45 +873,6 @@ namespace xo {
}
}
// ----- primitive: fn_n_args() -----
obj<AGCObject>
xfer_fn_n_args(obj<ARuntimeContext> rcx,
obj<AGCObject> fn_gco)
{
scope log(XO_DEBUG(true));
log && log(xtag("fn_gco.tseq", fn_gco._typeseq()));
log && log(xtag("fn_gco.tname", TypeRegistry::id2name(fn_gco._typeseq())));
auto fn_proc = FacetRegistry::instance().try_variant<AProcedure,AGCObject>(fn_gco);
assert(fn_proc);
return DInteger::box<AGCObject>(rcx.allocator(), fn_proc.n_args());
}
static DPrimitive_gco_1_gco s_fn_n_args_pm("_fn_n_args",
&xfer_fn_n_args);
// ----- install primitives -----
void
VirtualSchematikaMachine::install_core_primitives()
{
/* fn_n_args */
{
const DUniqueString * name
= reader_.intern_string("fn_n_args");
global_env_->_upsert_value
(mm_.to_op(),
name,
Reflect::require<DPrimitive_gco_1_gco>(),
obj<AGCObject,DPrimitive_gco_1_gco>(&s_fn_n_args_pm));
}
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -6,6 +6,7 @@
#pragma once
#include "Primitive_gco_0.hpp"
#include "Primitive_gco_1_gco.hpp"
#include "Primitive_gco_2_gco_gco.hpp"
#include "Primitive_gco_3_dict_string_gco.hpp"
@ -35,6 +36,9 @@ namespace xo {
/** create primitive that upserts a key,value pair into a dictionary **/
static DPrimitive_gco_3_dict_string_gco * make_dict_upsert_pm(obj<AAllocator> mm);
/** create primitive: get fixed number of args for function **/
static DPrimitive_gco_1_gco * make_fn_n_args_pm(obj<AAllocator> mm);
};
} /*namespace scm*/

View file

@ -133,6 +133,30 @@ namespace xo {
return DPrimitive_gco_3_dict_string_gco::_make(mm, "dict_upsert", &xfer_dict_upsert);
}
// ----- fn_n_args -----
obj<AGCObject>
xfer_fn_n_args(obj<ARuntimeContext> rcx,
obj<AGCObject> fn_gco)
{
scope log(XO_DEBUG(true));
log && log(xtag("fn_gco.tseq", fn_gco._typeseq()));
log && log(xtag("fn_gco.tname", TypeRegistry::id2name(fn_gco._typeseq())));
auto fn_proc = FacetRegistry::instance().try_variant<AProcedure,AGCObject>(fn_gco);
assert(fn_proc);
return DInteger::box<AGCObject>(rcx.allocator(), fn_proc.n_args());
}
DPrimitive_gco_1_gco *
ObjectPrimitives::make_fn_n_args_pm(obj<AAllocator> mm)
{
return DPrimitive_gco_1_gco::_make(mm, "fn_n_args", &xfer_fn_n_args);
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -66,6 +66,7 @@ namespace xo {
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);
ok = ok & install_aux(sink, ObjectPrimitives::make_fn_n_args_pm(mm), flags);
return ok;
}