xo-reader2 stack: top-level lambda w/ apply parses
This commit is contained in:
parent
da1f099b4f
commit
60b8fda134
26 changed files with 858 additions and 20 deletions
41
src/expression2/Binding.cpp
Normal file
41
src/expression2/Binding.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/** @file Binding.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "Binding.hpp"
|
||||
#include <cassert>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
Binding
|
||||
Binding::relative(int32_t i_link, Binding def)
|
||||
{
|
||||
if (def.i_link_ == Binding::c_link_global) {
|
||||
// for globally defined vars, i_link always -1
|
||||
return def;
|
||||
} else if (def.i_link_ >= 0) {
|
||||
return Binding(i_link + def.i_link_, def.j_slot_);
|
||||
} else {
|
||||
assert(false);
|
||||
return Binding();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Binding::print(std::ostream & os) const
|
||||
{
|
||||
if (i_link_ == c_link_global) {
|
||||
os << "{path:global}";
|
||||
} else if (i_link_ == c_link_sentinel) {
|
||||
os << "{path}";
|
||||
} else {
|
||||
os << "{path:" << i_link_ << ":" << j_slot_ << "}";
|
||||
}
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Binding.cpp */
|
||||
|
|
@ -3,9 +3,12 @@
|
|||
set(SELF_LIB xo_expression2)
|
||||
set(SELF_SRCS
|
||||
init_expression2.cpp
|
||||
expression2_register_facets.cpp
|
||||
expression2_register_types.cpp
|
||||
|
||||
DConstant.cpp
|
||||
DVariable.cpp
|
||||
DVarRef.cpp
|
||||
DDefineExpr.cpp
|
||||
DLambdaExpr.cpp
|
||||
DApplyExpr.cpp
|
||||
|
|
@ -13,6 +16,7 @@ set(SELF_SRCS
|
|||
DSequenceExpr.cpp
|
||||
|
||||
TypeRef.cpp
|
||||
Binding.cpp
|
||||
|
||||
IExpression_Any.cpp
|
||||
|
||||
|
|
@ -24,10 +28,15 @@ set(SELF_SRCS
|
|||
IGCObject_DVariable.cpp
|
||||
IPrintable_DVariable.cpp
|
||||
|
||||
IExpression_DVarRef.cpp
|
||||
IGCObject_DVarRef.cpp
|
||||
IPrintable_DVarRef.cpp
|
||||
|
||||
IExpression_DDefineExpr.cpp
|
||||
IPrintable_DDefineExpr.cpp
|
||||
|
||||
IExpression_DApplyExpr.cpp
|
||||
IGCObject_DApplyExpr.cpp
|
||||
IPrintable_DApplyExpr.cpp
|
||||
|
||||
IExpression_DLambdaExpr.cpp
|
||||
|
|
@ -55,8 +64,6 @@ set(SELF_SRCS
|
|||
IGCObject_DUniqueString.cpp
|
||||
IPrintable_DUniqueString.cpp
|
||||
|
||||
expression2_register_facets.cpp
|
||||
expression2_register_types.cpp
|
||||
)
|
||||
|
||||
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
|
|
|
|||
|
|
@ -102,6 +102,48 @@ namespace xo {
|
|||
typeref_.resolve(td);
|
||||
}
|
||||
|
||||
// ----- gcobject facet -----
|
||||
|
||||
std::size_t
|
||||
DApplyExpr::shallow_size() const noexcept {
|
||||
return sizeof(DApplyExpr) + (n_args_ * sizeof(obj<AExpression>));
|
||||
}
|
||||
|
||||
DApplyExpr *
|
||||
DApplyExpr::shallow_copy(obj<AAllocator> mm) const noexcept {
|
||||
DApplyExpr * copy = (DApplyExpr *)mm.alloc_copy((std::byte *)this);
|
||||
|
||||
if (copy) {
|
||||
copy->typeref_ = typeref_;
|
||||
copy->fn_ = fn_;
|
||||
copy->n_args_ = n_args_;
|
||||
|
||||
constexpr auto c_obj_z = sizeof(obj<AExpression>);
|
||||
|
||||
::memcpy((void*)&(copy->args_[0]), (void*)&(args_[0]), n_args_ * c_obj_z);
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DApplyExpr::forward_children(obj<ACollector> gc) noexcept
|
||||
{
|
||||
for (size_type i = 0; i < n_args_; ++i) {
|
||||
obj<AExpression> & arg = args_[i];
|
||||
|
||||
// runtime poly here
|
||||
obj<AGCObject> arg_gco = arg.to_facet<AGCObject>();
|
||||
|
||||
// need the data address within *this
|
||||
gc.forward_inplace(arg_gco.iface(), (void **)(&arg.data_));
|
||||
}
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
// ----- printable facet -----
|
||||
|
||||
bool
|
||||
DApplyExpr::pretty(const ppindentinfo & ppii) const {
|
||||
using xo::print::ppstate;
|
||||
|
|
|
|||
105
src/expression2/DVarRef.cpp
Normal file
105
src/expression2/DVarRef.cpp
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/** @file DVarRef.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
using xo::reflect::TypeDescr;
|
||||
|
||||
namespace scm {
|
||||
|
||||
DVarRef::DVarRef(DVariable * vardef,
|
||||
Binding path)
|
||||
: vardef_{vardef},
|
||||
path_{path}
|
||||
{}
|
||||
|
||||
DVarRef *
|
||||
DVarRef::make(obj<AAllocator> mm,
|
||||
DVariable * vardef,
|
||||
int32_t link)
|
||||
{
|
||||
assert(vardef);
|
||||
|
||||
void * mem = mm.alloc_for<DVarRef>();
|
||||
|
||||
return new (mem) DVarRef(vardef,
|
||||
Binding::relative(link,
|
||||
vardef->path()));
|
||||
}
|
||||
|
||||
const DUniqueString *
|
||||
DVarRef::name() const {
|
||||
return vardef_->name();
|
||||
}
|
||||
|
||||
TypeRef
|
||||
DVarRef::typeref() const noexcept {
|
||||
assert(vardef_);
|
||||
|
||||
return vardef_->typeref();
|
||||
}
|
||||
|
||||
TypeDescr
|
||||
DVarRef::valuetype() const noexcept
|
||||
{
|
||||
return this->typeref().td();
|
||||
}
|
||||
|
||||
void
|
||||
DVarRef::assign_valuetype(TypeDescr td) noexcept
|
||||
{
|
||||
assert(vardef_);
|
||||
vardef_->assign_valuetype(td);
|
||||
}
|
||||
|
||||
// gcobject facet
|
||||
|
||||
std::size_t
|
||||
DVarRef::shallow_size() const noexcept
|
||||
{
|
||||
return sizeof(DVarRef);
|
||||
}
|
||||
|
||||
DVarRef *
|
||||
DVarRef::shallow_copy(obj<AAllocator> mm) const noexcept
|
||||
{
|
||||
DVarRef * copy = (DVarRef *)mm.alloc_copy((std::byte *)this);
|
||||
|
||||
if (copy)
|
||||
*copy = *this;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DVarRef::forward_children(obj<ACollector> gc) noexcept
|
||||
{
|
||||
// TODO: this can be helper in RCollector interface
|
||||
auto iface = xo::facet::impl_for<AGCObject,DVariable>();
|
||||
gc.forward_inplace(&iface, (void **)vardef_);
|
||||
|
||||
// TODO: concept to indicate that no gc pointers in Binding
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
// printable facet
|
||||
|
||||
bool
|
||||
DVarRef::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"DVarRef",
|
||||
refrtag("name", std::string_view(*(this->name()))),
|
||||
refrtag("path", this->path_));
|
||||
}
|
||||
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DVarRef.cpp */
|
||||
45
src/expression2/IExpression_DVarRef.cpp
Normal file
45
src/expression2/IExpression_DVarRef.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/** @file IExpression_DVarRef.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IExpression_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IExpression_DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IExpression_DVarRef::extype(const DVarRef & self) noexcept -> exprtype
|
||||
{
|
||||
return self.extype();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DVarRef::typeref(const DVarRef & self) noexcept -> TypeRef
|
||||
{
|
||||
return self.typeref();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DVarRef::valuetype(const DVarRef & self) noexcept -> TypeDescr
|
||||
{
|
||||
return self.valuetype();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DVarRef::assign_valuetype(DVarRef & self, TypeDescr td) noexcept -> void
|
||||
{
|
||||
self.assign_valuetype(td);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IExpression_DVarRef.cpp */
|
||||
39
src/expression2/IGCObject_DApplyExpr.cpp
Normal file
39
src/expression2/IGCObject_DApplyExpr.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/** @file IGCObject_DApplyExpr.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DApplyExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DApplyExpr.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IGCObject_DApplyExpr.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IGCObject_DApplyExpr::shallow_size(const DApplyExpr & self) noexcept -> size_type
|
||||
{
|
||||
return self.shallow_size();
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DApplyExpr::shallow_copy(const DApplyExpr & self, obj<AAllocator> mm) noexcept -> Opaque
|
||||
{
|
||||
return self.shallow_copy(mm);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DApplyExpr::forward_children(DApplyExpr & self, obj<ACollector> gc) noexcept -> size_type
|
||||
{
|
||||
return self.forward_children(gc);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_DApplyExpr.cpp */
|
||||
39
src/expression2/IGCObject_DVarRef.cpp
Normal file
39
src/expression2/IGCObject_DVarRef.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/** @file IGCObject_DVarRef.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IGCObject_DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IGCObject_DVarRef::shallow_size(const DVarRef & self) noexcept -> size_type
|
||||
{
|
||||
return self.shallow_size();
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DVarRef::shallow_copy(const DVarRef & self, obj<AAllocator> mm) noexcept -> Opaque
|
||||
{
|
||||
return self.shallow_copy(mm);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DVarRef::forward_children(DVarRef & self, obj<ACollector> gc) noexcept -> size_type
|
||||
{
|
||||
return self.forward_children(gc);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_DVarRef.cpp */
|
||||
28
src/expression2/IPrintable_DVarRef.cpp
Normal file
28
src/expression2/IPrintable_DVarRef.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DVarRef.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IPrintable_DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DVarRef::pretty(const DVarRef & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DVarRef.cpp */
|
||||
|
|
@ -16,13 +16,13 @@
|
|||
#include <xo/expression2/detail/IGCObject_DVariable.hpp>
|
||||
#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/detail/IExpression_DApplyExpr.hpp>
|
||||
//#include <xo/expression2/detail/IGCObject_DApplyExpr.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DApplyExpr.hpp>
|
||||
#include <xo/expression2/ApplyExpr.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IExpression_DLambdaExpr.hpp>
|
||||
//#include <xo/expression2/detail/IGCObject_DLambdaExpr.hpp>
|
||||
|
|
@ -63,6 +63,7 @@ namespace xo {
|
|||
// Expression
|
||||
// +- Constant
|
||||
// +- Variable
|
||||
// +- VarRef
|
||||
// +- DefineExpr
|
||||
// +- ApplyExpr
|
||||
// +- LambdaExpr
|
||||
|
|
@ -77,13 +78,20 @@ namespace xo {
|
|||
FacetRegistry::register_impl<AGCObject, DVariable>();
|
||||
FacetRegistry::register_impl<APrintable, DVariable>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DVarRef>();
|
||||
FacetRegistry::register_impl<AGCObject, DVarRef>();
|
||||
FacetRegistry::register_impl<APrintable, DVarRef>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DDefineExpr>();
|
||||
//FacetRegistry::register_impl<AGCObject, DDefineExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DDefineExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DApplyExpr>();
|
||||
FacetRegistry::register_impl<AGCObject, DApplyExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DApplyExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DLambdaExpr>();
|
||||
//FacetRegistry::register_impl<AGCObject, DLambdaExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DLambdaExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DIfElseExpr>();
|
||||
|
|
@ -95,11 +103,13 @@ namespace xo {
|
|||
FacetRegistry::register_impl<APrintable, DSequenceExpr>();
|
||||
|
||||
FacetRegistry::register_impl<ASymbolTable, DLocalSymtab>();
|
||||
//FacetRegistry::register_impl<AGCObject, DLocalSymtab>();
|
||||
FacetRegistry::register_impl<APrintable, DLocalSymtab>();
|
||||
|
||||
log && log(xtag("DUniqueString.tseq", typeseq::id<DUniqueString>()));
|
||||
log && log(xtag("DDefineExpr.tseq", typeseq::id<DDefineExpr>()));
|
||||
log && log(xtag("DVariable.tseq", typeseq::id<DVariable>()));
|
||||
log && log(xtag("DVarRef.tseq", typeseq::id<DVarRef>()));
|
||||
log && log(xtag("DConstant.tseq", typeseq::id<DConstant>()));
|
||||
log && log(xtag("DApplyExpr.tseq", typeseq::id<DApplyExpr>()));
|
||||
log && log(xtag("DLambdaExpr.tseq", typeseq::id<DLambdaExpr>()));
|
||||
|
|
@ -108,7 +118,7 @@ namespace xo {
|
|||
|
||||
log && log(xtag("DLocalSymtab.tseq", typeseq::id<DLocalSymtab>()));
|
||||
|
||||
log && log(xtag("AExpression.tqseq", typeseq::id<AExpression>()));
|
||||
log && log(xtag("AExpression.tseq", typeseq::id<AExpression>()));
|
||||
log && log(xtag("ASymbolTable.tseq", typeseq::id<ASymbolTable>()));
|
||||
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue