xo-reader2: + SyntaxStateMachine.forward_children method

Support gc traversal with goal of making ParserStateMachine a gc root
This commit is contained in:
Roland Conybeare 2026-03-24 17:43:45 -04:00
commit 3af72fec64
91 changed files with 626 additions and 39 deletions

View file

@ -19,11 +19,12 @@
#include <xo/type/Type.hpp>
#include <xo/tokenizer2/Token.hpp>
#include <xo/reflect/TypeDescr.hpp>
#include <xo/alloc2/Collector.hpp>
#include <xo/facet/obj.hpp>
#include <xo/facet/facet_implementation.hpp>
#include <xo/facet/typeseq.hpp>
// {pretex} here
// {pretext} here
namespace xo {
namespace scm {
@ -45,6 +46,8 @@ public:
using Opaque = void *;
/** reflected c++ type **/
using TypeDescr = xo::reflect::TypeDescr;
/** gc interface **/
using ACollector = xo::mm::ACollector;
/** gc-aware object **/
using AGCObject = xo::mm::AGCObject;
///@}
@ -52,6 +55,11 @@ public:
/** @defgroup scm-syntaxstatemachine-methods **/
///@{
// const methods
/** An uninitialized ASyntaxStateMachine instance will have zero vtable pointer (per {linux,osx} abi).
* Use case for this is narrow. We go to some lengths to avoid null vtable pointers. For example
* obj<AFacet> will have non-null vtable (via IFacet_Any) with all methods terminating.
**/
bool _has_null_vptr() const noexcept { return *reinterpret_cast<const void * const *>(this) == nullptr; }
/** RTTI: unique id# for actual runtime data representation **/
virtual typeseq _typeseq() const noexcept = 0;
/** destroy instance @p d; calls c++ dtor only for actual runtime type; does not recover memory **/
@ -82,6 +90,8 @@ public:
virtual void on_parsed_expression_with_token(Opaque data, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) = 0;
/** update state machine for nested quoted literal @p lit **/
virtual void on_quoted_literal(Opaque data, obj<AGCObject> lit, ParserStateMachine * p_psm) = 0;
/** gc support: move immediate children to to-space and sub forwarding pointer **/
virtual void forward_children(Opaque data, obj<ACollector> gc) = 0;
///@}
}; /*ASyntaxStateMachine*/

View file

@ -45,6 +45,7 @@ namespace scm {
/** integer identifying a type **/
using typeseq = xo::facet::typeseq;
using TypeDescr = ASyntaxStateMachine::TypeDescr;
using ACollector = ASyntaxStateMachine::ACollector;
using AGCObject = ASyntaxStateMachine::AGCObject;
///@}
@ -74,6 +75,7 @@ namespace scm {
[[noreturn]] void on_parsed_expression(Opaque, obj<AExpression>, ParserStateMachine *) override;
[[noreturn]] void on_parsed_expression_with_token(Opaque, obj<AExpression>, const Token &, ParserStateMachine *) override;
[[noreturn]] void on_quoted_literal(Opaque, obj<AGCObject>, ParserStateMachine *) override;
[[noreturn]] void forward_children(Opaque, obj<ACollector>) override;
///@}

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-ddefinessm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DDefineSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DDefineSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DDefineSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dexpectexprssm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DExpectExprSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DExpectExprSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DExpectExprSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dexpectformalarglistssm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DExpectFormalArglistSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DExpectFormalArglistSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DExpectFormalArglistSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dexpectqarrayssm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DExpectQArraySsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DExpectQArraySsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DExpectQArraySsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dexpectqlistssm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DExpectQListSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DExpectQListSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DExpectQListSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dexpectqliteralssm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DExpectQLiteralSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DExpectQLiteralSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DExpectQLiteralSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dexpectsymbolssm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DExpectSymbolSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DExpectSymbolSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DExpectSymbolSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dexpecttypessm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DExpectTypeSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DExpectTypeSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DExpectTypeSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dprogressssm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DProgressSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DProgressSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DProgressSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dquotessm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DQuoteSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DQuoteSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DQuoteSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dsequencessm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DSequenceSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DSequenceSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DSequenceSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -42,6 +42,7 @@ namespace xo {
/** @defgroup scm-syntaxstatemachine-dtoplevelseqssm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using ACollector = xo::scm::ASyntaxStateMachine::ACollector;
using AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
@ -75,6 +76,8 @@ namespace xo {
static void on_parsed_expression_with_token(DToplevelSeqSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DToplevelSeqSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
/** gc support: move immediate children to to-space and sub forwarding pointer **/
static void forward_children(DToplevelSeqSsm & self, obj<ACollector> gc);
///@}
};

View file

@ -18,6 +18,7 @@
#include <xo/type/Type.hpp>
#include <xo/tokenizer2/Token.hpp>
#include <xo/reflect/TypeDescr.hpp>
#include <xo/alloc2/Collector.hpp>
namespace xo {
namespace scm {
@ -33,6 +34,7 @@ namespace scm {
/** integer identifying a type **/
using typeseq = ASyntaxStateMachine::typeseq;
using TypeDescr = ASyntaxStateMachine::TypeDescr;
using ACollector = ASyntaxStateMachine::ACollector;
using AGCObject = ASyntaxStateMachine::AGCObject;
///@}
@ -87,6 +89,9 @@ namespace scm {
void on_quoted_literal(Opaque data, obj<AGCObject> lit, ParserStateMachine * p_psm) override {
return I::on_quoted_literal(_dcast(data), lit, p_psm);
}
void forward_children(Opaque data, obj<ACollector> gc) override {
return I::forward_children(_dcast(data), gc);
}
///@}

View file

@ -32,6 +32,7 @@ public:
using DataPtr = Object::DataPtr;
using typeseq = xo::reflect::typeseq;
using TypeDescr = ASyntaxStateMachine::TypeDescr;
using ACollector = ASyntaxStateMachine::ACollector;
using AGCObject = ASyntaxStateMachine::AGCObject;
///@}
@ -92,6 +93,9 @@ public:
void on_quoted_literal(obj<AGCObject> lit, ParserStateMachine * p_psm) {
return O::iface()->on_quoted_literal(O::data(), lit, p_psm);
}
void forward_children(obj<ACollector> gc) {
return O::iface()->forward_children(O::data(), gc);
}
///@}
/** @defgroup scm-syntaxstatemachine-member-vars **/