xo-interpreter2 stack: define-expr's work at top-level

This commit is contained in:
Roland Conybeare 2026-02-17 14:42:17 -05:00
commit f777aeade0
10 changed files with 184 additions and 12 deletions

View file

@ -230,6 +230,17 @@ xo_add_genfacetimpl(
OUTPUT_IMPL_SUBDIR detail
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-expression2-facetimpl-gcobject-defineexpr
FACET_PKG xo_gc
FACET GCObject
REPR DefineExpr
INPUT idl/IGCObject_DDefineExpr.json5
OUTPUT_HPP_DIR include/xo/expression2
OUTPUT_IMPL_SUBDIR define
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-expression2-facetimpl-printable-defineexpr

View file

@ -0,0 +1,18 @@
{
mode: "implementation",
output_cpp_dir: "src/expression2",
output_hpp_dir: "include/xo/expression2",
output_impl_subdir: "define",
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 DDefineExpr",
using_doxygen: true,
repr: "DDefineExpr",
doc: [ "implement AGCObject for DDefineExpr" ],
}

View file

@ -1,5 +1,5 @@
/** @file DDefineExpr.hpp
*
*
* @author Roland Conybeare, Jan 2026
**/
@ -23,6 +23,7 @@ namespace xo {
class DDefineExpr {
public:
using ppindentinfo = xo::print::ppindentinfo;
using ACollector = xo::mm::ACollector;
using AAllocator = xo::mm::AAllocator;
using TypeDescr = xo::reflect::TypeDescr;
@ -67,6 +68,14 @@ namespace xo {
TypeDescr valuetype() const noexcept { return lhs_var_->typeref().td(); }
void assign_valuetype(TypeDescr td) noexcept;
///@}
/** @defgroup scm-defineexpr-gcobject-facet **/
///@{
std::size_t shallow_size() const noexcept;
DDefineExpr * shallow_copy(obj<AAllocator> mm) const noexcept;
std::size_t forward_children(obj<ACollector> gc) noexcept;
///@}
/** @defgroup scm-defineexpr-printable-facet **/
///@{

View file

@ -32,6 +32,7 @@ namespace xo {
using AAllocator = xo::mm::AAllocator;
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
using ppindentinfo = xo::print::ppindentinfo;
using size_type = std::uint32_t;
public:
/** @defgroup scm-globalsymtab-ctors constructors **/
@ -55,6 +56,9 @@ namespace xo {
/** @defgroup scm-globalsymtab-access-methods access methods **/
///@{
size_type size() const noexcept { return map_->size(); }
size_type capacity() const noexcept { return map_->capacity(); }
/** visit symtab-owned memory pools; call visitor(info) for each **/
void visit_pools(const MemorySizeVisitor & visitor) const;

View file

@ -7,7 +7,7 @@
#include "DDefineExpr.hpp"
#include "detail/IExpression_DDefineExpr.hpp"
//#include "detail/IGCObject_DDefineExpr.hpp"
#include "define/IGCObject_DDefineExpr.hpp"
#include "detail/IPrintable_DDefineExpr.hpp"
/* end DefineExpr.hpp */

View file

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

View file

@ -9,7 +9,6 @@ set(SELF_SRCS
DConstant.cpp
DVariable.cpp
DVarRef.cpp
DDefineExpr.cpp
DApplyExpr.cpp
TypeRef.cpp
@ -30,7 +29,9 @@ set(SELF_SRCS
IGCObject_DVarRef.cpp
IPrintable_DVarRef.cpp
DDefineExpr.cpp
IExpression_DDefineExpr.cpp
IGCObject_DDefineExpr.cpp
IPrintable_DDefineExpr.cpp
IExpression_DApplyExpr.cpp

View file

@ -4,13 +4,16 @@
**/
#include "DDefineExpr.hpp"
#include "detail/IPrintable_DVariable.hpp"
#include "Variable.hpp"
#include <xo/gc/GCObject.hpp>
#include <xo/gc/PolyForwarderUtil.hpp>
#include <xo/printable2/Printable.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/indentlog/scope.hpp>
#include <xo/indentlog/print/cond.hpp>
namespace xo {
using xo::mm::poly_forward_inplace;
using xo::print::APrintable;
using xo::facet::FacetRegistry;
using xo::facet::typeseq;
@ -68,10 +71,35 @@ namespace xo {
}
void
DDefineExpr::assign_rhs(obj<AExpression> x) {
DDefineExpr::assign_rhs(obj<AExpression> x)
{
this->rhs_ = x;
}
// ----- GCObject facet -----
std::size_t
DDefineExpr::shallow_size() const noexcept
{
return sizeof(*this);
}
DDefineExpr *
DDefineExpr::shallow_copy(obj<AAllocator> mm) const noexcept
{
return mm.std_copy_for(this);
}
std::size_t
DDefineExpr::forward_children(obj<ACollector> gc) noexcept
{
gc.forward_inplace(&lhs_var_);
//gc.forward_inplace(&rhs_); // complicated - need to access via GCObject facet
poly_forward_inplace(gc, &rhs_);
return this->shallow_size();
}
bool
DDefineExpr::pretty(const ppindentinfo & ppii) const
{

View file

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

View file

@ -6,17 +6,12 @@
#include "expression2_register_facets.hpp"
#include <xo/expression2/UniqueString.hpp>
//#include <xo/expression2/detail/IGCObject_DUniqueString.hpp>
//#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>
#include <xo/expression2/detail/IGCObject_DVariable.hpp>
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
#include <xo/expression2/DefineExpr.hpp>
#include <xo/expression2/VarRef.hpp>
#include <xo/expression2/Constant.hpp>
#include <xo/expression2/ApplyExpr.hpp>
@ -74,7 +69,7 @@ namespace xo {
FacetRegistry::register_impl<APrintable, DVarRef>();
FacetRegistry::register_impl<AExpression, DDefineExpr>();
//FacetRegistry::register_impl<AGCObject, DDefineExpr>();
FacetRegistry::register_impl<AGCObject, DDefineExpr>();
FacetRegistry::register_impl<APrintable, DDefineExpr>();
FacetRegistry::register_impl<AExpression, DApplyExpr>();