xo-interpreter2 stack: lambda expr -> closure runs in VSM utest

This commit is contained in:
Roland Conybeare 2026-02-08 23:32:20 -05:00
commit 0df7e05e82
8 changed files with 175 additions and 58 deletions

View file

@ -20,6 +20,7 @@ namespace xo {
**/
class DLambdaExpr {
public:
using ACollector = xo::mm::ACollector;
using AAllocator = xo::mm::AAllocator;
using TypeDescr = xo::reflect::TypeDescr;
using ppindentinfo = xo::print::ppindentinfo;
@ -78,6 +79,14 @@ namespace xo {
TypeDescr valuetype() const noexcept;
void assign_valuetype(TypeDescr td) noexcept;
///@}
/** @defgroup scm-lambdaexpr-gcobject-facet **/
///@{
std::size_t shallow_size() const noexcept;
DLambdaExpr * shallow_copy(obj<AAllocator> mm) const noexcept;
std::size_t forward_children(obj<ACollector> gc) noexcept;
///@}
/** @defgroup scm-lambdaexpr-printable-facet **/
///@{
@ -95,7 +104,7 @@ namespace xo {
/** name for this lambda (generated if necessary) **/
const DUniqueString * name_ = nullptr;
#ifdef NOT_YET
#ifdef NOT_YET // when enabled, need to visit forward_children()
/** e.g.
* i64(f64,string)
* for function of two arguments with types (f64, string) respectively,

View file

@ -0,0 +1,13 @@
/** @file IfElseExpr.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DIfElseExpr.hpp"
#include "detail/IExpression_DIfElseExpr.hpp"
#include "detail/IGCObject_DIfElseExpr.hpp"
#include "detail/IPrintable_DIfElseExpr.hpp"
/* end IfElseExpr.hpp */

View file

@ -0,0 +1,12 @@
/** @file UniqueString.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DUniqueString.hpp"
#include "detail/IGCObject_DUniqueString.hpp"
#include "detail/IPrintable_DUniqueString.hpp"
/* end UniqueString.hpp */

View file

@ -10,15 +10,13 @@ set(SELF_SRCS
DVariable.cpp
DVarRef.cpp
DDefineExpr.cpp
DLambdaExpr.cpp
DApplyExpr.cpp
DIfElseExpr.cpp
DSequenceExpr.cpp
TypeRef.cpp
Binding.cpp
IExpression_Any.cpp
ISymbolTable_Any.cpp
IExpression_DConstant.cpp
IGCObject_DConstant.cpp
@ -39,25 +37,28 @@ set(SELF_SRCS
IGCObject_DApplyExpr.cpp
IPrintable_DApplyExpr.cpp
DLambdaExpr.cpp
IExpression_DLambdaExpr.cpp
IGCObject_DLambdaExpr.cpp
IPrintable_DLambdaExpr.cpp
DIfElseExpr.cpp
IExpression_DIfElseExpr.cpp
IGCObject_DIfElseExpr.cpp
IPrintable_DIfElseExpr.cpp
DSequenceExpr.cpp
IExpression_DSequenceExpr.cpp
IGCObject_DSequenceExpr.cpp
IPrintable_DSequenceExpr.cpp
DLocalSymtab.cpp
DGlobalSymtab.cpp
ISymbolTable_Any.cpp
ISymbolTable_DLocalSymtab.cpp
IGCObject_DLocalSymtab.cpp
IPrintable_DLocalSymtab.cpp
DGlobalSymtab.cpp
StringTable.cpp
DUniqueString.cpp

View file

@ -80,32 +80,6 @@ namespace xo {
typeref_.resolve(td);
}
bool
DIfElseExpr::pretty(const ppindentinfo & ppii) const
{
auto test
= FacetRegistry::instance().try_variant<APrintable,
AExpression>(test_);
auto when_true
= FacetRegistry::instance().try_variant<APrintable,
AExpression>(when_true_);
auto when_false
= FacetRegistry::instance().try_variant<APrintable,
AExpression>(when_false_);
bool test_present = test;
bool when_true_present = when_true;
bool when_false_present = when_false;
return ppii.pps()->pretty_struct
(ppii,
"DIfElseExpr",
refrtag("typeref", typeref_),
refrtag("test", test, test_present),
refrtag("when_true", when_true, when_true_present),
refrtag("when_false", when_false, when_false_present));
}
// GCObject facet
std::size_t
@ -145,6 +119,34 @@ namespace xo {
return shallow_size();
}
// ----- printable facet -----
bool
DIfElseExpr::pretty(const ppindentinfo & ppii) const
{
auto test
= FacetRegistry::instance().try_variant<APrintable,
AExpression>(test_);
auto when_true
= FacetRegistry::instance().try_variant<APrintable,
AExpression>(when_true_);
auto when_false
= FacetRegistry::instance().try_variant<APrintable,
AExpression>(when_false_);
bool test_present = test;
bool when_true_present = when_true;
bool when_false_present = when_false;
return ppii.pps()->pretty_struct
(ppii,
"DIfElseExpr",
refrtag("typeref", typeref_),
refrtag("test", test, test_present),
refrtag("when_true", when_true, when_true_present),
refrtag("when_false", when_false, when_false_present));
}
// ----------------------------------------------------------------
#ifdef NOPE

View file

@ -3,16 +3,16 @@
* @author Roland Conybeare, Jan 2026
**/
#include "DLambdaExpr.hpp"
#include "detail/IExpression_DLambdaExpr.hpp"
#include "DLocalSymtab.hpp"
#include "symtab/IPrintable_DLocalSymtab.hpp"
#include "LambdaExpr.hpp"
#include "LocalSymtab.hpp"
#include "UniqueString.hpp"
#include <xo/alloc2/Allocator.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::facet::FacetRegistry;
using xo::reflect::TypeDescr;
@ -134,6 +134,49 @@ namespace xo {
typeref_.resolve(td);
}
std::size_t
DLambdaExpr::shallow_size() const noexcept {
return sizeof(DLambdaExpr);
}
DLambdaExpr *
DLambdaExpr::shallow_copy(obj<AAllocator> mm) const noexcept {
DLambdaExpr * copy = (DLambdaExpr *)mm.alloc_copy((std::byte *)this);
if (copy) {
*copy = *this;
}
return copy;
}
std::size_t
DLambdaExpr::forward_children(obj<ACollector> gc) noexcept {
{
auto iface = xo::facet::impl_for<AGCObject,DUniqueString>();
gc.forward_inplace(&iface, (void **)(&name_));
}
// type_name_str_
{
auto iface = xo::facet::impl_for<AGCObject,DLocalSymtab>();
gc.forward_inplace(&iface, (void **)(&local_symtab_));
}
{
auto iface = body_expr_.to_facet<AGCObject>().iface();
gc.forward_inplace(iface, (void **)(&body_expr_));
}
// xxx free_var_set
// xxx captured_var_set
// xxx layer_var_map
// xxx nested_lambda_map
return shallow_size();
}
bool
DLambdaExpr::pretty(const ppindentinfo & ppii) const
{

View file

@ -3,13 +3,14 @@
* @author Roland Conybeare, Jan 2026
**/
#include "DLocalSymtab.hpp"
#include "LocalSymtab.hpp"
#include "Variable.hpp"
#include "DUniqueString.hpp"
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
#include <xo/printable2/Printable.hpp>
#include <xo/indentlog/scope.hpp>
namespace xo {
using xo::mm::AGCObject;
using xo::print::APrintable;
using xo::facet::typeseq;
using xo::print::ppstate;
@ -77,6 +78,50 @@ namespace xo {
return Binding();
}
// ----- gcobject facet -----
std::size_t
DLocalSymtab::shallow_size() const noexcept
{
return (sizeof(DLocalSymtab) + (capacity_ * sizeof(Slot)));
}
DLocalSymtab *
DLocalSymtab::shallow_copy(obj<AAllocator> mm) const noexcept
{
DLocalSymtab * copy = (DLocalSymtab *)mm.alloc_copy((std::byte *)this);
if (copy) {
*copy = *this;
::memcpy((void*)&(copy->slots_[0]),
(void*)&(slots_[0]),
capacity_ * sizeof(Slot));
}
return copy;
}
std::size_t
DLocalSymtab::forward_children(obj<ACollector> gc) noexcept
{
{
auto iface
= xo::facet::impl_for<AGCObject,DLocalSymtab>();
gc.forward_inplace(&iface, (void **)(&parent_));
}
auto iface
= xo::facet::impl_for<AGCObject,DVariable>();
for (size_type i = 0; i < size_; ++i) {
gc.forward_inplace(&iface, (void **)(&(slots_[i].var_)));
}
return shallow_size();
}
// ----- printable facet -----
bool
DLocalSymtab::pretty(const ppindentinfo & ppii) const
{

View file

@ -17,28 +17,16 @@
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
#include <xo/expression2/VarRef.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/Constant.hpp>
#include <xo/expression2/ApplyExpr.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/LambdaExpr.hpp>
#include <xo/expression2/IfElseExpr.hpp>
#include <xo/expression2/detail/IExpression_DSequenceExpr.hpp>
#include <xo/expression2/detail/IGCObject_DSequenceExpr.hpp>
#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/expression2/LocalSymtab.hpp>
#include <xo/gc/detail/AGCObject.hpp>
#include <xo/printable2/detail/APrintable.hpp>
@ -70,6 +58,10 @@ namespace xo {
// +- IfElseExpr
// \- SequenceExpr
// SymbolTable
// +- LocalSymtab
// \- GlobalSymtab
FacetRegistry::register_impl<AExpression, DConstant>();
FacetRegistry::register_impl<AGCObject, DConstant>();
FacetRegistry::register_impl<APrintable, DConstant>();
@ -91,7 +83,7 @@ namespace xo {
FacetRegistry::register_impl<APrintable, DApplyExpr>();
FacetRegistry::register_impl<AExpression, DLambdaExpr>();
//FacetRegistry::register_impl<AGCObject, DLambdaExpr>();
FacetRegistry::register_impl<AGCObject, DLambdaExpr>();
FacetRegistry::register_impl<APrintable, DLambdaExpr>();
FacetRegistry::register_impl<AExpression, DIfElseExpr>();
@ -103,7 +95,7 @@ namespace xo {
FacetRegistry::register_impl<APrintable, DSequenceExpr>();
FacetRegistry::register_impl<ASymbolTable, DLocalSymtab>();
//FacetRegistry::register_impl<AGCObject, DLocalSymtab>();
FacetRegistry::register_impl<AGCObject, DLocalSymtab>();
FacetRegistry::register_impl<APrintable, DLocalSymtab>();
log && log(xtag("DUniqueString.tseq", typeseq::id<DUniqueString>()));