xo-reader2 xo-expression2: + DSequenceSsm ++ utest

This commit is contained in:
Roland Conybeare 2026-01-31 18:28:25 -05:00
commit 0f7dccc193
14 changed files with 384 additions and 4 deletions

View file

@ -82,6 +82,18 @@ xo_add_genfacetimpl(
OUTPUT_CPP_DIR src/expression2
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-expression2-facetimpl-gcobject-constant
FACET_PKG xo_gc
FACET GCObject
REPR Constant
INPUT idl/IGCObject_DConstant.json5
OUTPUT_HPP_DIR include/xo/expression2
OUTPUT_IMPL_SUBDIR detail
OUTPUT_CPP_DIR src/expression2
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-expression2-facetimpl-printable-constant
@ -224,6 +236,18 @@ xo_add_genfacetimpl(
OUTPUT_CPP_DIR src/expression2
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-expression2-facetimpl-gcobject-ifelseexpr
FACET_PKG xo_gc
FACET GCObject
REPR IfElseExpr
INPUT idl/IGCObject_DIfElseExpr.json5
OUTPUT_HPP_DIR include/xo/expression2
OUTPUT_IMPL_SUBDIR detail
OUTPUT_CPP_DIR src/expression2
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-expression2-facetimpl-printable-ifelseexpr

View file

@ -0,0 +1,15 @@
{
mode: "implementation",
includes: [
"<xo/gc/GCObject.hpp>",
"<xo/alloc2/Allocator.hpp>"
],
local_types: [ ],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/GCObject.json5",
brief: "provide AGCObject interface for DConstant",
using_doxygen: true,
repr: "DConstant",
doc: [ "implement AGCObject for DConstant" ],
}

View file

@ -0,0 +1,15 @@
{
mode: "implementation",
includes: [
"<xo/gc/GCObject.hpp>",
"<xo/alloc2/Allocator.hpp>"
],
local_types: [ ],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/GCObject.json5",
brief: "provide AGCObject interface for DIfElseExpr",
using_doxygen: true,
repr: "DIfElseExpr",
doc: [ "implement AGCObject for DIfElseExpr" ],
}

View file

@ -8,8 +8,9 @@
#include "Expression.hpp"
#include "TypeRef.hpp"
#include "exprtype.hpp"
#include <xo/reflect/TaggedPtr.hpp>
#include <xo/gc/Collector.hpp>
#include <xo/gc/GCObject.hpp>
#include <xo/reflect/TaggedPtr.hpp>
namespace xo {
namespace scm {
@ -20,6 +21,7 @@ namespace xo {
public:
using TaggedPtr = xo::reflect::TaggedPtr;
using TypeDescr = xo::reflect::TypeDescr;
using ACollector = xo::mm::ACollector;
using AAllocator = xo::mm::AAllocator;
using AGCObject = xo::mm::AGCObject;
using typeseq = xo::reflect::typeseq;
@ -56,6 +58,14 @@ namespace xo {
TypeDescr valuetype() const noexcept { return typeref_.td(); }
void assign_valuetype(TypeDescr td) noexcept { typeref_.resolve(td); }
///@}
/** @defgroup scm-constant-gcobject-facet **/
///@{
size_t shallow_size() const noexcept;
DConstant * shallow_copy(obj<AAllocator> mm) const noexcept;
size_t forward_children(obj<ACollector> gc) noexcept;
///@}
/** @defgroup scm-constant-printable-facet **/
///@{

View file

@ -8,6 +8,7 @@
#include "Expression.hpp"
#include "TypeRef.hpp"
#include "exprtype.hpp"
#include <xo/gc/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
//#include <vector>
#include <string>
@ -21,6 +22,7 @@ namespace xo {
**/
class DIfElseExpr {
public:
using ACollector = xo::mm::ACollector;
using AAllocator = xo::mm::AAllocator;
using TypeDescr = xo::reflect::TypeDescr;
using ppindentinfo = xo::print::ppindentinfo;
@ -93,6 +95,14 @@ namespace xo {
bool pretty(const ppindentinfo & ppii) const;
///@}
/** @defgroup scm-ifelseexpr-gcobject-facet **/
///@{
std::size_t shallow_size() const noexcept;
DIfElseExpr * shallow_copy(obj<AAllocator> mm) const noexcept;
std::size_t forward_children(obj<ACollector> gc) noexcept;
///@}
#ifdef NOT_YET
virtual std::set<std::string> get_free_variables() const override {

View file

@ -0,0 +1,67 @@
/** @file IGCObject_DConstant.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObject_DConstant.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObject_DConstant.json5]
**/
#pragma once
#include "GCObject.hpp"
#include <xo/gc/GCObject.hpp>
#include <xo/alloc2/Allocator.hpp>
#include "DConstant.hpp"
namespace xo { namespace scm { class IGCObject_DConstant; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::mm::AGCObject,
xo::scm::DConstant>
{
using ImplType = xo::mm::IGCObject_Xfer
<xo::scm::DConstant,
xo::scm::IGCObject_DConstant>;
};
}
}
namespace xo {
namespace scm {
/** @class IGCObject_DConstant
**/
class IGCObject_DConstant {
public:
/** @defgroup scm-gcobject-dconstant-type-traits **/
///@{
using size_type = xo::mm::AGCObject::size_type;
using AAllocator = xo::mm::AGCObject::AAllocator;
using ACollector = xo::mm::AGCObject::ACollector;
using Copaque = xo::mm::AGCObject::Copaque;
using Opaque = xo::mm::AGCObject::Opaque;
///@}
/** @defgroup scm-gcobject-dconstant-methods **/
///@{
// const methods
/** memory consumption for this instance **/
static size_type shallow_size(const DConstant & self) noexcept;
/** copy instance using allocator **/
static Opaque shallow_copy(const DConstant & self, obj<AAllocator> mm) noexcept;
// non-const methods
/** during GC: forward immdiate children **/
static size_type forward_children(DConstant & self, obj<ACollector> gc) noexcept;
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -0,0 +1,67 @@
/** @file IGCObject_DIfElseExpr.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObject_DIfElseExpr.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObject_DIfElseExpr.json5]
**/
#pragma once
#include "GCObject.hpp"
#include <xo/gc/GCObject.hpp>
#include <xo/alloc2/Allocator.hpp>
#include "DIfElseExpr.hpp"
namespace xo { namespace scm { class IGCObject_DIfElseExpr; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::mm::AGCObject,
xo::scm::DIfElseExpr>
{
using ImplType = xo::mm::IGCObject_Xfer
<xo::scm::DIfElseExpr,
xo::scm::IGCObject_DIfElseExpr>;
};
}
}
namespace xo {
namespace scm {
/** @class IGCObject_DIfElseExpr
**/
class IGCObject_DIfElseExpr {
public:
/** @defgroup scm-gcobject-difelseexpr-type-traits **/
///@{
using size_type = xo::mm::AGCObject::size_type;
using AAllocator = xo::mm::AGCObject::AAllocator;
using ACollector = xo::mm::AGCObject::ACollector;
using Copaque = xo::mm::AGCObject::Copaque;
using Opaque = xo::mm::AGCObject::Opaque;
///@}
/** @defgroup scm-gcobject-difelseexpr-methods **/
///@{
// const methods
/** memory consumption for this instance **/
static size_type shallow_size(const DIfElseExpr & self) noexcept;
/** copy instance using allocator **/
static Opaque shallow_copy(const DIfElseExpr & self, obj<AAllocator> mm) noexcept;
// non-const methods
/** during GC: forward immdiate children **/
static size_type forward_children(DIfElseExpr & self, obj<ACollector> gc) noexcept;
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -17,6 +17,7 @@ set(SELF_SRCS
IExpression_Any.cpp
IExpression_DConstant.cpp
IGCObject_DConstant.cpp
IPrintable_DConstant.cpp
IExpression_DVariable.cpp
@ -33,6 +34,7 @@ set(SELF_SRCS
IPrintable_DLambdaExpr.cpp
IExpression_DIfElseExpr.cpp
IGCObject_DIfElseExpr.cpp
IPrintable_DIfElseExpr.cpp
IExpression_DSequenceExpr.cpp

View file

@ -71,6 +71,31 @@ namespace xo {
return nullptr;
}
std::size_t
DConstant::shallow_size() const noexcept
{
return sizeof(DConstant);
}
DConstant *
DConstant::shallow_copy(obj<AAllocator> mm) const noexcept
{
DConstant * copy = (DConstant *)mm.alloc_copy((std::byte *)this);
if (copy)
*copy = *this;
return copy;
}
std::size_t
DConstant::forward_children(obj<ACollector> gc) noexcept
{
gc.forward_inplace(value_.iface(), (void **)&(value_.data_));
return shallow_size();
}
bool
DConstant::pretty(const ppindentinfo & ppii) const
{

View file

@ -5,11 +5,13 @@
#include "DIfElseExpr.hpp"
#include "detail/IExpression_DIfElseExpr.hpp"
#include <xo/gc/GCObject.hpp>
#include <xo/printable2/Printable.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/reflectutil/typeseq.hpp>
namespace xo {
using xo::mm::AGCObject;
using xo::print::APrintable;
using xo::reflect::typeseq;
using xo::facet::FacetRegistry;
@ -120,6 +122,45 @@ namespace xo {
}
}
// GCObject facet
std::size_t
DIfElseExpr::shallow_size() const noexcept
{
return sizeof(DIfElseExpr);
}
DIfElseExpr *
DIfElseExpr::shallow_copy(obj<AAllocator> mm) const noexcept
{
DIfElseExpr * copy = (DIfElseExpr *)mm.alloc_copy((std::byte *)this);
if (copy)
*copy = *this;
return copy;
}
std::size_t
DIfElseExpr::forward_children(obj<ACollector> gc) noexcept
{
// GC needs to locate AGCObject iface for each member.
{
auto gco = FacetRegistry::instance().variant<AGCObject,AExpression>(test_);
gc.forward_inplace(gco.iface(), (void **)&(test_.data_));
}
{
auto gco = FacetRegistry::instance().variant<AGCObject,AExpression>(when_true_);
gc.forward_inplace(gco.iface(), (void **)&(when_true_.data_));
}
{
auto gco = FacetRegistry::instance().variant<AGCObject,AExpression>(when_false_);
gc.forward_inplace(gco.iface(), (void **)&(when_false_.data_));
}
return shallow_size();
}
// ----------------------------------------------------------------
#ifdef NOPE

View file

@ -0,0 +1,39 @@
/** @file IGCObject_DConstant.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObject_DConstant.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObject_DConstant.json5]
**/
#include "detail/IGCObject_DConstant.hpp"
namespace xo {
namespace scm {
auto
IGCObject_DConstant::shallow_size(const DConstant & self) noexcept -> size_type
{
return self.shallow_size();
}
auto
IGCObject_DConstant::shallow_copy(const DConstant & self, obj<AAllocator> mm) noexcept -> Opaque
{
return self.shallow_copy(mm);
}
auto
IGCObject_DConstant::forward_children(DConstant & self, obj<ACollector> gc) noexcept -> size_type
{
return self.forward_children(gc);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IGCObject_DConstant.cpp */

View file

@ -0,0 +1,39 @@
/** @file IGCObject_DIfElseExpr.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObject_DIfElseExpr.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObject_DIfElseExpr.json5]
**/
#include "detail/IGCObject_DIfElseExpr.hpp"
namespace xo {
namespace scm {
auto
IGCObject_DIfElseExpr::shallow_size(const DIfElseExpr & self) noexcept -> size_type
{
return self.shallow_size();
}
auto
IGCObject_DIfElseExpr::shallow_copy(const DIfElseExpr & self, obj<AAllocator> mm) noexcept -> Opaque
{
return self.shallow_copy(mm);
}
auto
IGCObject_DIfElseExpr::forward_children(DIfElseExpr & self, obj<ACollector> gc) noexcept -> size_type
{
return self.forward_children(gc);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IGCObject_DIfElseExpr.cpp */

View file

@ -9,6 +9,7 @@
#include <xo/expression2/detail/IPrintable_DUniqueString.hpp>
#include <xo/expression2/detail/IExpression_DDefineExpr.hpp>
//#include <xo/expression2/detail/IGCObject_DDefineExpr.hpp>
#include <xo/expression2/detail/IPrintable_DDefineExpr.hpp>
#include <xo/expression2/detail/IExpression_DVariable.hpp>
@ -16,15 +17,19 @@
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
#include <xo/expression2/detail/IExpression_DConstant.hpp>
#include <xo/expression2/detail/IGCObject_DConstant.hpp>
#include <xo/expression2/detail/IPrintable_DConstant.hpp>
#include <xo/expression2/detail/IExpression_DApplyExpr.hpp>
//#include <xo/expression2/detail/IGCObject_DApplyExpr.hpp>
#include <xo/expression2/detail/IPrintable_DApplyExpr.hpp>
#include <xo/expression2/detail/IExpression_DLambdaExpr.hpp>
//#include <xo/expression2/detail/IGCObject_DLambdaExpr.hpp>
#include <xo/expression2/detail/IPrintable_DLambdaExpr.hpp>
#include <xo/expression2/detail/IExpression_DIfElseExpr.hpp>
#include <xo/expression2/detail/IGCObject_DIfElseExpr.hpp>
#include <xo/expression2/detail/IPrintable_DIfElseExpr.hpp>
#include <xo/expression2/detail/IExpression_DSequenceExpr.hpp>
@ -32,6 +37,7 @@
#include <xo/expression2/detail/IPrintable_DSequenceExpr.hpp>
#include <xo/expression2/symtab/ISymbolTable_DLocalSymtab.hpp>
//#include <xo/expression2/detail/IGCObject_DLocalSymtab.hpp>
#include <xo/expression2/symtab/IPrintable_DLocalSymtab.hpp>
#include <xo/gc/detail/AGCObject.hpp>
@ -60,9 +66,11 @@ namespace xo {
// +- DefineExpr
// +- ApplyExpr
// +- LambdaExpr
// \- IfElseExpr
// +- IfElseExpr
// \- SequenceExpr
FacetRegistry::register_impl<AExpression, DConstant>();
FacetRegistry::register_impl<AGCObject, DConstant>();
FacetRegistry::register_impl<APrintable, DConstant>();
FacetRegistry::register_impl<AExpression, DVariable>();
@ -79,6 +87,7 @@ namespace xo {
FacetRegistry::register_impl<APrintable, DLambdaExpr>();
FacetRegistry::register_impl<AExpression, DIfElseExpr>();
FacetRegistry::register_impl<AGCObject, DIfElseExpr>();
FacetRegistry::register_impl<APrintable, DIfElseExpr>();
FacetRegistry::register_impl<AExpression, DSequenceExpr>();

View file

@ -5,11 +5,18 @@
#include "expression2_register_types.hpp"
#include "detail/IGCObject_DConstant.hpp"
#include "detail/IGCObject_DVariable.hpp"
//#include "detail/IGCObject_DDefineExpr.hpp" // when avail
//#include "detail/IGCObject_DApplyExpr.hpp" // when avail
//#include "detail/IGCObject_DLambdaExpr.hpp" // when avail
#include "detail/IGCObject_DIfElseExpr.hpp"
#include "detail/IGCObject_DSequenceExpr.hpp"
//#include "detail/IGCObject_DLocalSymtab.hpp" // when avail
#include "detail/IGCObject_DUniqueString.hpp"
//#include "detail/IPrintable_DUniqueString.hpp"
//#include "detail/IPrintable_DUniqueString.hpp" // when avail
//#include <xo/facet/FacetRegistry.hpp>
#include <xo/indentlog/scope.hpp>
namespace xo {
@ -27,6 +34,16 @@ namespace xo {
bool ok = true;
ok &= gc.install_type(impl_for<AGCObject, DConstant>());
ok &= gc.install_type(impl_for<AGCObject, DVariable>());
//ok &= gc.install_type(impl_for<AGCObject, DDefineExpr>()); // when avail
//ok &= gc.install_type(impl_for<AGCObject, DApplyExpr>()); // when avail
//ok &= gc.install_type(impl_for<AGCObject, DLambdaExpr>()); // when avail
ok &= gc.install_type(impl_for<AGCObject, DIfElseExpr>());
ok &= gc.install_type(impl_for<AGCObject, DSequenceExpr>());
//ok &= gc.install_type(impl_for<AGCObject, DLocalSymtab>()); // when avail
ok &= gc.install_type(impl_for<AGCObject, DUniqueString>());
return ok;