xo-interpreter2 stack: lambda expr -> closure runs in VSM utest
This commit is contained in:
parent
e9413abbd6
commit
0df7e05e82
8 changed files with 175 additions and 58 deletions
|
|
@ -20,6 +20,7 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
class DLambdaExpr {
|
class DLambdaExpr {
|
||||||
public:
|
public:
|
||||||
|
using ACollector = xo::mm::ACollector;
|
||||||
using AAllocator = xo::mm::AAllocator;
|
using AAllocator = xo::mm::AAllocator;
|
||||||
using TypeDescr = xo::reflect::TypeDescr;
|
using TypeDescr = xo::reflect::TypeDescr;
|
||||||
using ppindentinfo = xo::print::ppindentinfo;
|
using ppindentinfo = xo::print::ppindentinfo;
|
||||||
|
|
@ -78,6 +79,14 @@ namespace xo {
|
||||||
TypeDescr valuetype() const noexcept;
|
TypeDescr valuetype() const noexcept;
|
||||||
void assign_valuetype(TypeDescr td) 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 **/
|
/** @defgroup scm-lambdaexpr-printable-facet **/
|
||||||
///@{
|
///@{
|
||||||
|
|
@ -95,7 +104,7 @@ namespace xo {
|
||||||
/** name for this lambda (generated if necessary) **/
|
/** name for this lambda (generated if necessary) **/
|
||||||
const DUniqueString * name_ = nullptr;
|
const DUniqueString * name_ = nullptr;
|
||||||
|
|
||||||
#ifdef NOT_YET
|
#ifdef NOT_YET // when enabled, need to visit forward_children()
|
||||||
/** e.g.
|
/** e.g.
|
||||||
* i64(f64,string)
|
* i64(f64,string)
|
||||||
* for function of two arguments with types (f64, string) respectively,
|
* for function of two arguments with types (f64, string) respectively,
|
||||||
|
|
|
||||||
13
include/xo/expression2/IfElseExpr.hpp
Normal file
13
include/xo/expression2/IfElseExpr.hpp
Normal 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 */
|
||||||
12
include/xo/expression2/UniqueString.hpp
Normal file
12
include/xo/expression2/UniqueString.hpp
Normal 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 */
|
||||||
|
|
@ -10,15 +10,13 @@ set(SELF_SRCS
|
||||||
DVariable.cpp
|
DVariable.cpp
|
||||||
DVarRef.cpp
|
DVarRef.cpp
|
||||||
DDefineExpr.cpp
|
DDefineExpr.cpp
|
||||||
DLambdaExpr.cpp
|
|
||||||
DApplyExpr.cpp
|
DApplyExpr.cpp
|
||||||
DIfElseExpr.cpp
|
|
||||||
DSequenceExpr.cpp
|
|
||||||
|
|
||||||
TypeRef.cpp
|
TypeRef.cpp
|
||||||
Binding.cpp
|
Binding.cpp
|
||||||
|
|
||||||
IExpression_Any.cpp
|
IExpression_Any.cpp
|
||||||
|
ISymbolTable_Any.cpp
|
||||||
|
|
||||||
IExpression_DConstant.cpp
|
IExpression_DConstant.cpp
|
||||||
IGCObject_DConstant.cpp
|
IGCObject_DConstant.cpp
|
||||||
|
|
@ -39,25 +37,28 @@ set(SELF_SRCS
|
||||||
IGCObject_DApplyExpr.cpp
|
IGCObject_DApplyExpr.cpp
|
||||||
IPrintable_DApplyExpr.cpp
|
IPrintable_DApplyExpr.cpp
|
||||||
|
|
||||||
|
DLambdaExpr.cpp
|
||||||
IExpression_DLambdaExpr.cpp
|
IExpression_DLambdaExpr.cpp
|
||||||
|
IGCObject_DLambdaExpr.cpp
|
||||||
IPrintable_DLambdaExpr.cpp
|
IPrintable_DLambdaExpr.cpp
|
||||||
|
|
||||||
|
DIfElseExpr.cpp
|
||||||
IExpression_DIfElseExpr.cpp
|
IExpression_DIfElseExpr.cpp
|
||||||
IGCObject_DIfElseExpr.cpp
|
IGCObject_DIfElseExpr.cpp
|
||||||
IPrintable_DIfElseExpr.cpp
|
IPrintable_DIfElseExpr.cpp
|
||||||
|
|
||||||
|
DSequenceExpr.cpp
|
||||||
IExpression_DSequenceExpr.cpp
|
IExpression_DSequenceExpr.cpp
|
||||||
IGCObject_DSequenceExpr.cpp
|
IGCObject_DSequenceExpr.cpp
|
||||||
IPrintable_DSequenceExpr.cpp
|
IPrintable_DSequenceExpr.cpp
|
||||||
|
|
||||||
DLocalSymtab.cpp
|
DLocalSymtab.cpp
|
||||||
DGlobalSymtab.cpp
|
|
||||||
|
|
||||||
ISymbolTable_Any.cpp
|
|
||||||
|
|
||||||
ISymbolTable_DLocalSymtab.cpp
|
ISymbolTable_DLocalSymtab.cpp
|
||||||
|
IGCObject_DLocalSymtab.cpp
|
||||||
IPrintable_DLocalSymtab.cpp
|
IPrintable_DLocalSymtab.cpp
|
||||||
|
|
||||||
|
DGlobalSymtab.cpp
|
||||||
|
|
||||||
StringTable.cpp
|
StringTable.cpp
|
||||||
|
|
||||||
DUniqueString.cpp
|
DUniqueString.cpp
|
||||||
|
|
|
||||||
|
|
@ -80,32 +80,6 @@ namespace xo {
|
||||||
typeref_.resolve(td);
|
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
|
// GCObject facet
|
||||||
|
|
||||||
std::size_t
|
std::size_t
|
||||||
|
|
@ -145,6 +119,34 @@ namespace xo {
|
||||||
return shallow_size();
|
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
|
#ifdef NOPE
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,16 @@
|
||||||
* @author Roland Conybeare, Jan 2026
|
* @author Roland Conybeare, Jan 2026
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "DLambdaExpr.hpp"
|
#include "LambdaExpr.hpp"
|
||||||
#include "detail/IExpression_DLambdaExpr.hpp"
|
#include "LocalSymtab.hpp"
|
||||||
#include "DLocalSymtab.hpp"
|
#include "UniqueString.hpp"
|
||||||
#include "symtab/IPrintable_DLocalSymtab.hpp"
|
|
||||||
#include <xo/alloc2/Allocator.hpp>
|
#include <xo/alloc2/Allocator.hpp>
|
||||||
#include <xo/printable2/Printable.hpp>
|
#include <xo/printable2/Printable.hpp>
|
||||||
#include <xo/facet/FacetRegistry.hpp>
|
#include <xo/facet/FacetRegistry.hpp>
|
||||||
#include <xo/reflectutil/typeseq.hpp>
|
#include <xo/reflectutil/typeseq.hpp>
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
|
using xo::mm::AGCObject;
|
||||||
using xo::print::APrintable;
|
using xo::print::APrintable;
|
||||||
using xo::facet::FacetRegistry;
|
using xo::facet::FacetRegistry;
|
||||||
using xo::reflect::TypeDescr;
|
using xo::reflect::TypeDescr;
|
||||||
|
|
@ -134,6 +134,49 @@ namespace xo {
|
||||||
typeref_.resolve(td);
|
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
|
bool
|
||||||
DLambdaExpr::pretty(const ppindentinfo & ppii) const
|
DLambdaExpr::pretty(const ppindentinfo & ppii) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,14 @@
|
||||||
* @author Roland Conybeare, Jan 2026
|
* @author Roland Conybeare, Jan 2026
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "DLocalSymtab.hpp"
|
#include "LocalSymtab.hpp"
|
||||||
|
#include "Variable.hpp"
|
||||||
#include "DUniqueString.hpp"
|
#include "DUniqueString.hpp"
|
||||||
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
|
|
||||||
#include <xo/printable2/Printable.hpp>
|
#include <xo/printable2/Printable.hpp>
|
||||||
#include <xo/indentlog/scope.hpp>
|
#include <xo/indentlog/scope.hpp>
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
|
using xo::mm::AGCObject;
|
||||||
using xo::print::APrintable;
|
using xo::print::APrintable;
|
||||||
using xo::facet::typeseq;
|
using xo::facet::typeseq;
|
||||||
using xo::print::ppstate;
|
using xo::print::ppstate;
|
||||||
|
|
@ -77,6 +78,50 @@ namespace xo {
|
||||||
return Binding();
|
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
|
bool
|
||||||
DLocalSymtab::pretty(const ppindentinfo & ppii) const
|
DLocalSymtab::pretty(const ppindentinfo & ppii) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,28 +17,16 @@
|
||||||
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
|
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
|
||||||
|
|
||||||
#include <xo/expression2/VarRef.hpp>
|
#include <xo/expression2/VarRef.hpp>
|
||||||
|
#include <xo/expression2/Constant.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/ApplyExpr.hpp>
|
#include <xo/expression2/ApplyExpr.hpp>
|
||||||
|
#include <xo/expression2/LambdaExpr.hpp>
|
||||||
#include <xo/expression2/detail/IExpression_DLambdaExpr.hpp>
|
#include <xo/expression2/IfElseExpr.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/detail/IExpression_DSequenceExpr.hpp>
|
#include <xo/expression2/detail/IExpression_DSequenceExpr.hpp>
|
||||||
#include <xo/expression2/detail/IGCObject_DSequenceExpr.hpp>
|
#include <xo/expression2/detail/IGCObject_DSequenceExpr.hpp>
|
||||||
#include <xo/expression2/detail/IPrintable_DSequenceExpr.hpp>
|
#include <xo/expression2/detail/IPrintable_DSequenceExpr.hpp>
|
||||||
|
|
||||||
#include <xo/expression2/symtab/ISymbolTable_DLocalSymtab.hpp>
|
#include <xo/expression2/LocalSymtab.hpp>
|
||||||
//#include <xo/expression2/detail/IGCObject_DLocalSymtab.hpp>
|
|
||||||
#include <xo/expression2/symtab/IPrintable_DLocalSymtab.hpp>
|
|
||||||
|
|
||||||
#include <xo/gc/detail/AGCObject.hpp>
|
#include <xo/gc/detail/AGCObject.hpp>
|
||||||
#include <xo/printable2/detail/APrintable.hpp>
|
#include <xo/printable2/detail/APrintable.hpp>
|
||||||
|
|
@ -70,6 +58,10 @@ namespace xo {
|
||||||
// +- IfElseExpr
|
// +- IfElseExpr
|
||||||
// \- SequenceExpr
|
// \- SequenceExpr
|
||||||
|
|
||||||
|
// SymbolTable
|
||||||
|
// +- LocalSymtab
|
||||||
|
// \- GlobalSymtab
|
||||||
|
|
||||||
FacetRegistry::register_impl<AExpression, DConstant>();
|
FacetRegistry::register_impl<AExpression, DConstant>();
|
||||||
FacetRegistry::register_impl<AGCObject, DConstant>();
|
FacetRegistry::register_impl<AGCObject, DConstant>();
|
||||||
FacetRegistry::register_impl<APrintable, DConstant>();
|
FacetRegistry::register_impl<APrintable, DConstant>();
|
||||||
|
|
@ -91,7 +83,7 @@ namespace xo {
|
||||||
FacetRegistry::register_impl<APrintable, DApplyExpr>();
|
FacetRegistry::register_impl<APrintable, DApplyExpr>();
|
||||||
|
|
||||||
FacetRegistry::register_impl<AExpression, DLambdaExpr>();
|
FacetRegistry::register_impl<AExpression, DLambdaExpr>();
|
||||||
//FacetRegistry::register_impl<AGCObject, DLambdaExpr>();
|
FacetRegistry::register_impl<AGCObject, DLambdaExpr>();
|
||||||
FacetRegistry::register_impl<APrintable, DLambdaExpr>();
|
FacetRegistry::register_impl<APrintable, DLambdaExpr>();
|
||||||
|
|
||||||
FacetRegistry::register_impl<AExpression, DIfElseExpr>();
|
FacetRegistry::register_impl<AExpression, DIfElseExpr>();
|
||||||
|
|
@ -103,7 +95,7 @@ namespace xo {
|
||||||
FacetRegistry::register_impl<APrintable, DSequenceExpr>();
|
FacetRegistry::register_impl<APrintable, DSequenceExpr>();
|
||||||
|
|
||||||
FacetRegistry::register_impl<ASymbolTable, DLocalSymtab>();
|
FacetRegistry::register_impl<ASymbolTable, DLocalSymtab>();
|
||||||
//FacetRegistry::register_impl<AGCObject, DLocalSymtab>();
|
FacetRegistry::register_impl<AGCObject, DLocalSymtab>();
|
||||||
FacetRegistry::register_impl<APrintable, DLocalSymtab>();
|
FacetRegistry::register_impl<APrintable, DLocalSymtab>();
|
||||||
|
|
||||||
log && log(xtag("DUniqueString.tseq", typeseq::id<DUniqueString>()));
|
log && log(xtag("DUniqueString.tseq", typeseq::id<DUniqueString>()));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue