xo-interpreter2 stack: modularize nth() primitive setup/install
This commit is contained in:
parent
f6ecc56a1c
commit
6d6066995a
7 changed files with 158 additions and 2 deletions
|
|
@ -72,6 +72,7 @@ namespace xo {
|
|||
template <typename Fn>
|
||||
class Primitive {
|
||||
public:
|
||||
using FunctionPtrType = Fn;
|
||||
using Traits = detail::PmFnTraits<Fn>;
|
||||
|
||||
using ACollector = xo::mm::ACollector;
|
||||
|
|
|
|||
29
include/xo/procedure2/ObjectPrimitives.hpp
Normal file
29
include/xo/procedure2/ObjectPrimitives.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/** @file ObjectPrimitives.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Mar 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/procedure2/DPrimitive_gco_2_gco_gco.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @brief primitives centered on object2/ data structures.
|
||||
*
|
||||
* Note: they don't reside in object2/ because DPrimitive
|
||||
* not available yet at that level
|
||||
**/
|
||||
class ObjectPrimitives {
|
||||
public:
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
|
||||
public:
|
||||
/** create primitive for fetching nth element of a sequence **/
|
||||
static DPrimitive_gco_2_gco_gco * make_nth_pm(obj<AAllocator> mm);
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ObjectPrimitives.hpp */
|
||||
|
|
@ -10,8 +10,10 @@
|
|||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** Register gc-aware (AGCObject,DRepr) combinations with garbage collector @p gc **/
|
||||
bool procedure2_register_primitives(obj<xo::mm::AAllocator> gc, InstallSink sink);
|
||||
/** Register primitive-factories **/
|
||||
bool procedure2_register_primitives(obj<xo::mm::AAllocator> gc,
|
||||
InstallSink sink,
|
||||
InstallFlags flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@ set(SELF_LIB xo_procedure2)
|
|||
set(SELF_SRCS
|
||||
init_procedure2.cpp
|
||||
init_primitives.cpp
|
||||
procedure2_register_primitives.cpp
|
||||
procedure2_register_types.cpp
|
||||
procedure2_register_facets.cpp
|
||||
ObjectPrimitives.cpp
|
||||
PrimitiveRegistry.cpp
|
||||
DPrimitive.cpp
|
||||
DSimpleRcx.cpp
|
||||
|
|
|
|||
45
src/procedure2/ObjectPrimitives.cpp
Normal file
45
src/procedure2/ObjectPrimitives.cpp
Normal 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 */
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
#include "init_primitives.hpp"
|
||||
#include "procedure2_register_facets.hpp"
|
||||
#include "procedure2_register_types.hpp"
|
||||
#include "procedure2_register_primitives.hpp"
|
||||
|
||||
#include <xo/object2/init_object2.hpp>
|
||||
#include <xo/alloc2/CollectorTypeRegistry.hpp>
|
||||
|
|
@ -14,6 +15,8 @@
|
|||
namespace xo {
|
||||
using xo::scm::procedure2_register_facets;
|
||||
using xo::scm::procedure2_register_types;
|
||||
using xo::scm::procedure2_register_primitives;
|
||||
using xo::scm::PrimitiveRegistry;
|
||||
using xo::mm::CollectorTypeRegistry;
|
||||
|
||||
void
|
||||
|
|
@ -22,6 +25,7 @@ namespace xo {
|
|||
procedure2_register_facets();
|
||||
|
||||
CollectorTypeRegistry::instance().register_types(&procedure2_register_types);
|
||||
PrimitiveRegistry::instance().register_primitives(&procedure2_register_primitives);
|
||||
}
|
||||
|
||||
InitEvidence
|
||||
|
|
|
|||
73
src/procedure2/procedure2_register_primitives.cpp
Normal file
73
src/procedure2/procedure2_register_primitives.cpp
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/** @file procedure2_register_primitives.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Mar 2026
|
||||
**/
|
||||
|
||||
#include "procedure2_register_primitives.hpp"
|
||||
#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 {
|
||||
template <typename PrimitiveRepr>
|
||||
bool install_aux(InstallSink sink,
|
||||
PrimitiveRepr * pm,
|
||||
InstallFlags flags)
|
||||
{
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
if ((flags & InstallFlags::f_generalpurpose) == InstallFlags::f_generalpurpose) {
|
||||
log && log("create primitive", xtag("name", pm->name()));
|
||||
|
||||
return sink(pm->name(),
|
||||
pm->fn_td(),
|
||||
obj<AProcedure,PrimitiveRepr>(pm),
|
||||
flags);
|
||||
} else {
|
||||
log && log("skip primitive", xtag("name", pm->name()));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Primitive>
|
||||
bool install_aux(InstallSink sink,
|
||||
obj<AAllocator> mm,
|
||||
std::string_view name,
|
||||
typename Primitive::FunctionPtrType impl,
|
||||
InstallFlags flags)
|
||||
{
|
||||
if (flags != InstallFlags::f_none) {
|
||||
auto pm
|
||||
= Primitive::_make(mm, name, impl);
|
||||
|
||||
return install_aux(sink, pm, flags);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
procedure2_register_primitives(obj<xo::mm::AAllocator> mm,
|
||||
InstallSink sink,
|
||||
InstallFlags flags)
|
||||
{
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_nth_pm(mm), flags);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end procedure2_register_primitives.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue