From 121fb2dfad94fcaaf1ca50142121370a13b88641 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 17 Feb 2026 14:42:17 -0500 Subject: [PATCH] xo-interpreter2 stack: define-expr's work at top-level --- include/xo/reader2/ParserStateMachine.hpp | 21 ++++++++++++--------- include/xo/reader2/SchematikaParser.hpp | 2 ++ include/xo/reader2/SchematikaReader.hpp | 3 +++ src/reader2/SchematikaParser.cpp | 6 ++++++ src/reader2/SchematikaReader.cpp | 6 ++++++ utest/SchematikaParser.test.cpp | 1 + 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/include/xo/reader2/ParserStateMachine.hpp b/include/xo/reader2/ParserStateMachine.hpp index 2dfba437..f2654e1c 100644 --- a/include/xo/reader2/ParserStateMachine.hpp +++ b/include/xo/reader2/ParserStateMachine.hpp @@ -71,6 +71,7 @@ namespace xo { bool debug_flag() const noexcept { return debug_flag_; } ParserStack * stack() const noexcept { return stack_; } obj expr_alloc() const noexcept { return expr_alloc_; } + DGlobalSymtab * global_symtab() const noexcept { return global_symtab_.data(); } DLocalSymtab * local_symtab() const noexcept { return local_symtab_; } const ParserResult & result() const noexcept { return result_; } @@ -315,6 +316,17 @@ namespace xo { **/ obj aux_alloc_; + /** global symbol table. + * Toplevel definitions go here. + * + * Uses mmap -> non-trivial destructor. + * + * TODO: may want to move ownership upstairs. + * if so, along with stringtable_. + * maybe new struct ParserState? + **/ + dp global_symtab_; + /** symbol table with local bindings. * non-null during parsing of lambda expressions. * Always allocated from @p expr_alloc_. @@ -323,15 +335,6 @@ namespace xo { **/ DLocalSymtab * local_symtab_ = nullptr; - /** global symbol table. - * Toplevel definitions go here. - * - * Uses mmap -> non-trivial destructor. - * - * TODO: may want to move ownership upstairs - **/ - dp global_symtab_; - /** current output from parser **/ ParserResult result_; diff --git a/include/xo/reader2/SchematikaParser.hpp b/include/xo/reader2/SchematikaParser.hpp index 45b45c19..96de8628 100644 --- a/include/xo/reader2/SchematikaParser.hpp +++ b/include/xo/reader2/SchematikaParser.hpp @@ -183,6 +183,8 @@ namespace xo { /** scm-schematikaparser-access-methods **/ ///@{ + DGlobalSymtab * global_symtab() const noexcept; + bool debug_flag() const { return debug_flag_; } /** true if parser is at top-level, diff --git a/include/xo/reader2/SchematikaReader.hpp b/include/xo/reader2/SchematikaReader.hpp index 5a4243a1..efd031ca 100644 --- a/include/xo/reader2/SchematikaReader.hpp +++ b/include/xo/reader2/SchematikaReader.hpp @@ -54,6 +54,9 @@ namespace xo { /** non-trivial dtor because of @p parser **/ ~SchematikaReader() = default; + /** top-level symbol table **/ + DGlobalSymtab * global_symtab() const noexcept; + /** visit reader-owned memory pools; call visitor(info) for each. * Specifically exclude expr_alloc, since we don't consider * that reader-owned diff --git a/src/reader2/SchematikaParser.cpp b/src/reader2/SchematikaParser.cpp index 1bb188cb..25b3bc7f 100644 --- a/src/reader2/SchematikaParser.cpp +++ b/src/reader2/SchematikaParser.cpp @@ -32,6 +32,12 @@ namespace xo { { } + DGlobalSymtab * + SchematikaParser::global_symtab() const noexcept + { + return psm_.global_symtab(); + } + bool SchematikaParser::is_at_toplevel() const { diff --git a/src/reader2/SchematikaReader.cpp b/src/reader2/SchematikaReader.cpp index 98d44112..c3e13254 100644 --- a/src/reader2/SchematikaReader.cpp +++ b/src/reader2/SchematikaReader.cpp @@ -24,6 +24,12 @@ namespace xo { { } + DGlobalSymtab * + SchematikaReader::global_symtab() const noexcept + { + return parser_.global_symtab(); + } + void SchematikaReader::visit_pools(const MemorySizeVisitor & visitor) const { diff --git a/utest/SchematikaParser.test.cpp b/utest/SchematikaParser.test.cpp index e4a0e1de..6153ecb7 100644 --- a/utest/SchematikaParser.test.cpp +++ b/utest/SchematikaParser.test.cpp @@ -117,6 +117,7 @@ namespace xo { aux_arena_.visit_pools(visitor); FacetRegistry::instance().visit_pools(visitor); + TypeRegistry::instance().visit_pools(visitor); expr_arena_->visit_pools(visitor); parser_->visit_pools(visitor);