From c6c05ab6335165140b91ae5ae6bd957d426e67da Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 1 Feb 2026 00:16:37 -0500 Subject: [PATCH] xo-reader2: construct LambdaExpr to complete LambdaSsm + utest --- include/xo/expression2/StringTable.hpp | 5 +++++ src/expression2/DLambdaExpr.cpp | 12 +++++++++-- src/expression2/DSequenceExpr.cpp | 7 +++++- src/expression2/StringTable.cpp | 30 ++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/include/xo/expression2/StringTable.hpp b/include/xo/expression2/StringTable.hpp index 54b0a826..471fbc0d 100644 --- a/include/xo/expression2/StringTable.hpp +++ b/include/xo/expression2/StringTable.hpp @@ -35,6 +35,11 @@ namespace xo { /** return unique string with contents @p key. Idempotent! **/ const DUniqueString * intern(std::string_view key); + /** generate unique symbol -- guaranteed not to collide + * with existing symbol in this table. + **/ + const DUniqueString * gensym(std::string_view prefix); + /** verify StringTable invariants. * Act on failure according to policy @p p **/ diff --git a/src/expression2/DLambdaExpr.cpp b/src/expression2/DLambdaExpr.cpp index a27e788b..080e49b5 100644 --- a/src/expression2/DLambdaExpr.cpp +++ b/src/expression2/DLambdaExpr.cpp @@ -1,10 +1,12 @@ -/** @file DLambda.cpp +/** @file DLambdaExpr.cpp * * @author Roland Conybeare, Jan 2026 **/ #include "DLambdaExpr.hpp" #include "detail/IExpression_DLambdaExpr.hpp" +#include "DLocalSymtab.hpp" +#include "symtab/IPrintable_DLocalSymtab.hpp" #include #include #include @@ -17,6 +19,7 @@ namespace xo { using xo::reflect::TypeDescrBase; using xo::reflect::FunctionTdxInfo; using xo::reflect::typeseq; + using xo::print::quot; namespace scm { @@ -139,9 +142,14 @@ namespace xo { AExpression>(body_expr_); if (name_ && body) { + auto local_symtab_pr + = obj(local_symtab_); + return ppii.pps()->pretty_struct(ppii, "LambdaExpr", - refrtag("name", name_), + refrtag("tref", typeref_), + refrtag("name", quot(std::string_view(*name_))), + refrtag("local_symtab", local_symtab_pr), //refrtag("argv", local_env_->argv()), refrtag("body", body)); } else { diff --git a/src/expression2/DSequenceExpr.cpp b/src/expression2/DSequenceExpr.cpp index 73b9c2b5..a9783802 100644 --- a/src/expression2/DSequenceExpr.cpp +++ b/src/expression2/DSequenceExpr.cpp @@ -6,6 +6,7 @@ #include "DSequenceExpr.hpp" #include "detail/IExpression_DSequenceExpr.hpp" #include +#include #include #include #include @@ -15,6 +16,7 @@ namespace xo { using xo::mm::AGCObject; + using xo::print::APrintable; using xo::facet::FacetRegistry; using xo::reflect::typeseq; @@ -95,9 +97,12 @@ namespace xo { { using xo::print::ppstate; + auto expr_v_pr = obj(expr_v_); + return ppii.pps()->pretty_struct (ppii, - "DSequenceExpr"); + "DSequenceExpr", + refrtag("expr_v", expr_v_pr)); } // gc hooks for IGCObject_DSequenceExpr diff --git a/src/expression2/StringTable.cpp b/src/expression2/StringTable.cpp index ae48eea9..f59bb24d 100644 --- a/src/expression2/StringTable.cpp +++ b/src/expression2/StringTable.cpp @@ -72,6 +72,36 @@ namespace xo { return nullptr; } + const DUniqueString * + StringTable::gensym(std::string_view prefix) + { + static std::size_t s_counter = 0; + + while (true) { + ++s_counter; + + char buf[80]; + assert(prefix.size() + 20 < sizeof(buf)); + + int n = snprintf(buf, sizeof(buf), + "%s:%lu", + prefix.data(), s_counter); + + if ((0 < n) && (std::size_t(n) < sizeof(buf))) + buf[n] = '\0'; + else + buf[sizeof(buf)-1] = '\0'; + + std::string_view sv(buf); + const DUniqueString * retval = this->lookup(sv); + if (!retval) { + /* not already in string view -> we have viable candidate */ + retval = this->intern(sv); + return retval; + } + } + } + bool StringTable::verify_ok(verify_policy policy) const {