xo-interpreter2 stack: refactor + bugfix operator expr
This commit is contained in:
parent
6f76c9ee3b
commit
b69ec48d00
6 changed files with 164 additions and 31 deletions
|
|
@ -14,21 +14,25 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
class NumericPrimitives {
|
class NumericPrimitives {
|
||||||
public:
|
public:
|
||||||
/** polymorphic (in both arguments) multiply **/
|
using AAllocator = xo::mm::AAllocator;
|
||||||
static DPrimitive_gco_2_gco_gco s_mul_gco_gco_pm;
|
|
||||||
|
public:
|
||||||
|
/** polymorphic (in both arguments1) multiply **/
|
||||||
|
static DPrimitive_gco_2_gco_gco * make_multiply_pm(obj<AAllocator> mm);
|
||||||
|
|
||||||
/** polymorphic (in both arguments) divide **/
|
/** polymorphic (in both arguments) divide **/
|
||||||
static DPrimitive_gco_2_gco_gco s_div_gco_gco_pm;
|
static DPrimitive_gco_2_gco_gco * make_divide_pm(obj<AAllocator> mm);
|
||||||
/** polymorphic (in both arguments) add **/
|
/** polymorphic (in both arguments) add **/
|
||||||
static DPrimitive_gco_2_gco_gco s_add_gco_gco_pm;
|
static DPrimitive_gco_2_gco_gco * make_add_pm(obj<AAllocator> mm);
|
||||||
/** polymorphic (in both arguments) subtract **/
|
/** polymorphic (in both arguments) subtract **/
|
||||||
static DPrimitive_gco_2_gco_gco s_sub_gco_gco_pm;
|
static DPrimitive_gco_2_gco_gco * make_subtract_pm(obj<AAllocator> mm);
|
||||||
|
|
||||||
/** polymorphic (in both arguments) compare (==) **/
|
/** polymorphic (in both arguments) compare (==) **/
|
||||||
static DPrimitive_gco_2_gco_gco s_cmpeq_gco_gco_pm;
|
static DPrimitive_gco_2_gco_gco * make_cmpeq_pm(obj<AAllocator> mm);
|
||||||
/** polymorphic (in both arguments) compare (!=) **/
|
/** polymorphic (in both arguments) compare (!=) **/
|
||||||
static DPrimitive_gco_2_gco_gco s_cmpne_gco_gco_pm;
|
static DPrimitive_gco_2_gco_gco * make_cmpne_pm(obj<AAllocator> mm);
|
||||||
/** polymorphic (in both arguments) compare (<) **/
|
/** polymorphic (in both arguments) compare (<) **/
|
||||||
static DPrimitive_gco_2_gco_gco s_cmplt_gco_gco_pm;
|
static DPrimitive_gco_2_gco_gco * make_cmplt_pm(obj<AAllocator> mm);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
include/xo/numeric/numeric_register_primitives.hpp
Normal file
20
include/xo/numeric/numeric_register_primitives.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/** @file numeric_register_primitives.hpp
|
||||||
|
*
|
||||||
|
* @author Roland Conybeare, Mar 2026
|
||||||
|
**/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "PrimitiveRegistry.hpp"
|
||||||
|
#include <xo/alloc2/Collector.hpp>
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace scm {
|
||||||
|
/** Register gc-aware (AGCObject,DRepr) combinations with garbage collector @p gc **/
|
||||||
|
bool numeric_register_primitives(obj<xo::mm::AAllocator> gc,
|
||||||
|
InstallSink sink,
|
||||||
|
InstallFlags flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end numeric_register_primitives.hpp */
|
||||||
|
|
@ -4,6 +4,7 @@ set(SELF_LIB xo_numeric)
|
||||||
set(SELF_SRCS
|
set(SELF_SRCS
|
||||||
init_numeric.cpp
|
init_numeric.cpp
|
||||||
numeric_register_facets.cpp
|
numeric_register_facets.cpp
|
||||||
|
numeric_register_primitives.cpp
|
||||||
NumericPrimitives.cpp
|
NumericPrimitives.cpp
|
||||||
NumericDispatch.cpp
|
NumericDispatch.cpp
|
||||||
INumeric_Any.cpp
|
INumeric_Any.cpp
|
||||||
|
|
|
||||||
|
|
@ -7,38 +7,59 @@
|
||||||
#include "NumericDispatch.hpp"
|
#include "NumericDispatch.hpp"
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
using xo::mm::AGCObject;
|
using xo::mm::AAllocator;
|
||||||
|
//using xo::mm::AGCObject;
|
||||||
|
|
||||||
namespace scm {
|
namespace scm {
|
||||||
|
|
||||||
DPrimitive_gco_2_gco_gco
|
DPrimitive_gco_2_gco_gco *
|
||||||
NumericPrimitives::s_mul_gco_gco_pm("_mul",
|
NumericPrimitives::make_multiply_pm(obj<AAllocator> mm)
|
||||||
&NumericDispatch::multiply);
|
{
|
||||||
|
return DPrimitive_gco_2_gco_gco::_make(mm, "_mul",
|
||||||
|
&NumericDispatch::multiply);
|
||||||
|
}
|
||||||
|
|
||||||
DPrimitive_gco_2_gco_gco
|
DPrimitive_gco_2_gco_gco *
|
||||||
NumericPrimitives::s_div_gco_gco_pm("_div",
|
NumericPrimitives::make_divide_pm(obj<AAllocator> mm)
|
||||||
&NumericDispatch::divide);
|
{
|
||||||
|
return DPrimitive_gco_2_gco_gco::_make(mm, "_div",
|
||||||
|
&NumericDispatch::divide);
|
||||||
|
}
|
||||||
|
|
||||||
DPrimitive_gco_2_gco_gco
|
DPrimitive_gco_2_gco_gco *
|
||||||
NumericPrimitives::s_add_gco_gco_pm("_add",
|
NumericPrimitives::make_add_pm(obj<AAllocator> mm)
|
||||||
&NumericDispatch::add);
|
{
|
||||||
|
return DPrimitive_gco_2_gco_gco::_make(mm, "_add",
|
||||||
|
&NumericDispatch::add);
|
||||||
|
}
|
||||||
|
|
||||||
DPrimitive_gco_2_gco_gco
|
DPrimitive_gco_2_gco_gco *
|
||||||
NumericPrimitives::s_sub_gco_gco_pm("_sub",
|
NumericPrimitives::make_subtract_pm(obj<AAllocator> mm)
|
||||||
&NumericDispatch::subtract);
|
{
|
||||||
|
return DPrimitive_gco_2_gco_gco::_make(mm, "_sub",
|
||||||
|
&NumericDispatch::subtract);
|
||||||
|
}
|
||||||
|
|
||||||
DPrimitive_gco_2_gco_gco
|
DPrimitive_gco_2_gco_gco *
|
||||||
NumericPrimitives::s_cmpeq_gco_gco_pm("_cmpeq",
|
NumericPrimitives::make_cmpeq_pm(obj<AAllocator> mm)
|
||||||
&NumericDispatch::cmp_equal);
|
{
|
||||||
|
return DPrimitive_gco_2_gco_gco::_make(mm, "_cmpeq",
|
||||||
|
&NumericDispatch::cmp_equal);
|
||||||
|
}
|
||||||
|
|
||||||
DPrimitive_gco_2_gco_gco
|
DPrimitive_gco_2_gco_gco *
|
||||||
NumericPrimitives::s_cmpne_gco_gco_pm("_cmpne",
|
NumericPrimitives::make_cmpne_pm(obj<AAllocator> mm)
|
||||||
&NumericDispatch::cmp_notequal);
|
{
|
||||||
|
return DPrimitive_gco_2_gco_gco::_make(mm, "_cmpne",
|
||||||
DPrimitive_gco_2_gco_gco
|
&NumericDispatch::cmp_notequal);
|
||||||
NumericPrimitives::s_cmplt_gco_gco_pm("_cmplt",
|
}
|
||||||
&NumericDispatch::cmp_less);
|
|
||||||
|
|
||||||
|
DPrimitive_gco_2_gco_gco *
|
||||||
|
NumericPrimitives::make_cmplt_pm(obj<AAllocator> mm)
|
||||||
|
{
|
||||||
|
return DPrimitive_gco_2_gco_gco::_make(mm, "_cmplt",
|
||||||
|
&NumericDispatch::cmp_less);
|
||||||
|
}
|
||||||
|
|
||||||
} /*namespace scm*/
|
} /*namespace scm*/
|
||||||
} /*namespace xo*/
|
} /*namespace xo*/
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,20 @@
|
||||||
#include <xo/procedure2/init_procedure2.hpp>
|
#include <xo/procedure2/init_procedure2.hpp>
|
||||||
#include "Subsystem.hpp"
|
#include "Subsystem.hpp"
|
||||||
#include "numeric_register_facets.hpp"
|
#include "numeric_register_facets.hpp"
|
||||||
|
#include "numeric_register_primitives.hpp"
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
using xo::scm::numeric_register_facets;
|
using xo::scm::numeric_register_facets;
|
||||||
|
using xo::scm::numeric_register_primitives;
|
||||||
|
using xo::scm::PrimitiveRegistry;
|
||||||
|
|
||||||
void
|
void
|
||||||
InitSubsys<S_numeric_tag>::init()
|
InitSubsys<S_numeric_tag>::init()
|
||||||
{
|
{
|
||||||
numeric_register_facets();
|
numeric_register_facets();
|
||||||
|
|
||||||
|
PrimitiveRegistry::instance().register_primitives(&numeric_register_primitives);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InitEvidence
|
InitEvidence
|
||||||
|
|
|
||||||
81
src/numeric/numeric_register_primitives.cpp
Normal file
81
src/numeric/numeric_register_primitives.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
/** @file numeric_register_primitives.cpp
|
||||||
|
*
|
||||||
|
* @author Roland Conybeare, Mar 2026
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "numeric_register_primitives.hpp"
|
||||||
|
#include "NumericPrimitives.hpp"
|
||||||
|
#include "NumericDispatch.hpp"
|
||||||
|
#include <xo/procedure2/Primitive_gco_2_gco_gco.hpp>
|
||||||
|
#include <xo/indentlog/scope.hpp>
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
using xo::mm::AAllocator;
|
||||||
|
using xo::scope;
|
||||||
|
|
||||||
|
namespace scm {
|
||||||
|
namespace {
|
||||||
|
bool install_aux(InstallSink sink,
|
||||||
|
DPrimitive_gco_2_gco_gco * pm,
|
||||||
|
InstallFlags flags)
|
||||||
|
{
|
||||||
|
if (flags != InstallFlags::f_none) {
|
||||||
|
return sink(pm->name(),
|
||||||
|
pm->fn_td(),
|
||||||
|
obj<AProcedure,DPrimitive_gco_2_gco_gco>(pm),
|
||||||
|
flags);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool install_aux(InstallSink sink,
|
||||||
|
obj<AAllocator> mm,
|
||||||
|
std::string_view name,
|
||||||
|
obj<AGCObject> (*impl)(obj<ARuntimeContext> rcx,
|
||||||
|
obj<AGCObject> x,
|
||||||
|
obj<AGCObject> y),
|
||||||
|
InstallFlags flags)
|
||||||
|
{
|
||||||
|
if (flags != InstallFlags::f_none) {
|
||||||
|
auto pm
|
||||||
|
= DPrimitive_gco_2_gco_gco::_make(mm, name, impl);
|
||||||
|
|
||||||
|
return install_aux(sink, pm, flags);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
numeric_register_primitives(obj<AAllocator> mm, InstallSink sink, InstallFlags flags)
|
||||||
|
{
|
||||||
|
scope log(XO_DEBUG(true));
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
ok = ok & install_aux(sink,
|
||||||
|
NumericPrimitives::make_multiply_pm(mm),
|
||||||
|
flags & InstallFlags::f_essential);
|
||||||
|
ok = ok & install_aux(sink,
|
||||||
|
NumericPrimitives::make_divide_pm(mm),
|
||||||
|
flags & InstallFlags::f_essential);
|
||||||
|
ok = ok & install_aux(sink, mm, "_add", &NumericDispatch::add,
|
||||||
|
flags & InstallFlags::f_essential);
|
||||||
|
ok = ok & install_aux(sink, mm, "_sub", &NumericDispatch::subtract,
|
||||||
|
flags & InstallFlags::f_essential);
|
||||||
|
|
||||||
|
ok = ok & install_aux(sink, mm, "_cmpeq", &NumericDispatch::cmp_equal,
|
||||||
|
flags & InstallFlags::f_essential);
|
||||||
|
ok = ok & install_aux(sink, mm, "_cmpne", &NumericDispatch::cmp_notequal,
|
||||||
|
flags & InstallFlags::f_essential);
|
||||||
|
ok = ok & install_aux(sink, mm, "_cmplt", &NumericDispatch::cmp_less,
|
||||||
|
flags & InstallFlags::f_essential);
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
/* end numeric_register_primitives.cpp */
|
||||||
Loading…
Add table
Add a link
Reference in a new issue