xo-expression2: + LambdaExpr ++ LocalSymtab
This commit is contained in:
parent
a69023096d
commit
666482a945
15 changed files with 621 additions and 9 deletions
|
|
@ -7,6 +7,7 @@ set(SELF_SRCS
|
|||
DConstant.cpp
|
||||
DVariable.cpp
|
||||
DDefineExpr.cpp
|
||||
DLambdaExpr.cpp
|
||||
DApplyExpr.cpp
|
||||
DIfElseExpr.cpp
|
||||
|
||||
|
|
@ -26,6 +27,9 @@ set(SELF_SRCS
|
|||
IExpression_DApplyExpr.cpp
|
||||
IPrintable_DApplyExpr.cpp
|
||||
|
||||
IExpression_DLambdaExpr.cpp
|
||||
IPrintable_DLambdaExpr.cpp
|
||||
|
||||
IExpression_DIfElseExpr.cpp
|
||||
IPrintable_DIfElseExpr.cpp
|
||||
|
||||
|
|
|
|||
129
src/expression2/DLambdaExpr.cpp
Normal file
129
src/expression2/DLambdaExpr.cpp
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/** @file DLambda.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include "DLambdaExpr.hpp"
|
||||
// #include "detail/IExpression_DLambdaExpr.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::print::APrintable;
|
||||
using xo::facet::FacetRegistry;
|
||||
using xo::reflect::TypeDescr;
|
||||
using xo::reflect::typeseq;
|
||||
|
||||
namespace scm {
|
||||
|
||||
#ifdef NOT_YET
|
||||
TypeDescr
|
||||
assemble_lambda_td()
|
||||
{
|
||||
std::vector<TypeDescr> arg_td_v;
|
||||
{
|
||||
arg_td_v.reserve(local_symtab->size());
|
||||
|
||||
for (DLocalSymtab::size_type i = 0, n = local_symtab->size(); i < n; ++i) {
|
||||
const DVariable * var = local_symtab->lookup_var(i);
|
||||
|
||||
if (!var)
|
||||
break;
|
||||
|
||||
TypeDescr arg_td = var->valuetype();
|
||||
|
||||
if (!arg_td)
|
||||
break;
|
||||
|
||||
arg_td_v.push_back(arg_td);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
DLambdaExpr::DLambdaExpr(TypeRef typeref,
|
||||
const DUniqueString * name,
|
||||
DLocalSymtab * local_symtab,
|
||||
obj<AExpression> body) : typeref_{typeref},
|
||||
name_{name},
|
||||
local_symtab_{local_symtab},
|
||||
body_expr_{body}
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef NOT_YET
|
||||
obj<AExpression,DLambdaExpr>
|
||||
DLambdaExpr::make(obj<AAllocator> mm,
|
||||
TypeRef typeref,
|
||||
const DUniqueString * name,
|
||||
DLocalSymtab * local_symtab,
|
||||
obj<AExpression> body)
|
||||
{
|
||||
return obj<AExpression,DLambdaExpr>(_make(mm, typeref,
|
||||
name, local_symtab, body);
|
||||
}
|
||||
#endif
|
||||
|
||||
DLambdaExpr *
|
||||
DLambdaExpr::_make(obj<AAllocator> mm,
|
||||
TypeRef typeref,
|
||||
const DUniqueString * name,
|
||||
DLocalSymtab * local_symtab,
|
||||
obj<AExpression> body)
|
||||
{
|
||||
// in general we're not going to know argument types yet.
|
||||
// perhaps want to delay this until after type resolution.
|
||||
|
||||
void * mem = mm.alloc(typeseq::id<DLambdaExpr>(), sizeof(DLambdaExpr));
|
||||
|
||||
return new (mem) DLambdaExpr(typeref,
|
||||
name,
|
||||
local_symtab,
|
||||
body);
|
||||
}
|
||||
|
||||
exprtype
|
||||
DLambdaExpr::extype() const noexcept {
|
||||
return exprtype::lambda;
|
||||
}
|
||||
|
||||
TypeRef
|
||||
DLambdaExpr::typeref() const noexcept {
|
||||
return typeref_;
|
||||
}
|
||||
|
||||
TypeDescr
|
||||
DLambdaExpr::valuetype() const noexcept {
|
||||
return typeref_.td();
|
||||
}
|
||||
|
||||
void
|
||||
DLambdaExpr::assign_valuetype(TypeDescr td) noexcept {
|
||||
typeref_.resolve(td);
|
||||
}
|
||||
|
||||
bool
|
||||
DLambdaExpr::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
auto body
|
||||
= FacetRegistry::instance().try_variant<APrintable,
|
||||
AExpression>(body_expr_);
|
||||
|
||||
if (name_ && body) {
|
||||
return ppii.pps()->pretty_struct(ppii,
|
||||
"LambdaExpr",
|
||||
refrtag("name", name_),
|
||||
//refrtag("argv", local_env_->argv()),
|
||||
refrtag("body", body));
|
||||
} else {
|
||||
return ppii.pps()->pretty_struct(ppii,
|
||||
"LambdaExpr");
|
||||
}
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DLambda.cpp */
|
||||
|
|
@ -8,13 +8,62 @@
|
|||
#include <xo/indentlog/scope.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::facet::typeseq;
|
||||
|
||||
namespace scm {
|
||||
|
||||
DLocalSymtab::DLocalSymtab(size_type n) : capacity_{n}, size_{0}
|
||||
{
|
||||
for (size_type i = 0; i < n; ++i) {
|
||||
void * mem = &slots_[i];
|
||||
new (mem) Slot();
|
||||
}
|
||||
}
|
||||
|
||||
DLocalSymtab *
|
||||
DLocalSymtab::_make_empty(obj<AAllocator> mm, size_type n)
|
||||
{
|
||||
void * mem = mm.alloc(typeseq::id<DLocalSymtab>(),
|
||||
sizeof(DLocalSymtab) + (n * sizeof(Slot)));
|
||||
|
||||
return new (mem) DLocalSymtab(n);
|
||||
}
|
||||
|
||||
Binding
|
||||
DLocalSymtab::append_var(obj<AAllocator> mm,
|
||||
const DUniqueString * name,
|
||||
TypeRef typeref)
|
||||
{
|
||||
assert(name);
|
||||
|
||||
if (size_ >= capacity_ || !name) {
|
||||
assert(false);
|
||||
|
||||
return Binding::null();
|
||||
} else {
|
||||
size_type i_slot = (this->size_)++;
|
||||
Binding binding = Binding::local(i_slot);
|
||||
DVariable * var = DVariable::make(mm, name, typeref, binding);
|
||||
|
||||
this->slots_[i_slot] = Slot(var);
|
||||
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
|
||||
Binding
|
||||
DLocalSymtab::lookup_binding(const DUniqueString * sym) const noexcept
|
||||
{
|
||||
scope log(XO_DEBUG(true), "stub impl");
|
||||
log && log(xtag("sym", std::string_view(*sym)));
|
||||
assert(sym);
|
||||
|
||||
if (sym) {
|
||||
for (size_type i = 0; i < size_; ++i) {
|
||||
const Slot & slot = slots_[i];
|
||||
|
||||
if (*sym == *(slot.var_->name()))
|
||||
return slot.var_->path();
|
||||
}
|
||||
}
|
||||
|
||||
return Binding();
|
||||
}
|
||||
|
|
|
|||
45
src/expression2/IExpression_DLambdaExpr.cpp
Normal file
45
src/expression2/IExpression_DLambdaExpr.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/** @file IExpression_DLambdaExpr.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DLambdaExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IExpression_DLambdaExpr.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IExpression_DLambdaExpr.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IExpression_DLambdaExpr::extype(const DLambdaExpr & self) noexcept -> exprtype
|
||||
{
|
||||
return self.extype();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DLambdaExpr::typeref(const DLambdaExpr & self) noexcept -> TypeRef
|
||||
{
|
||||
return self.typeref();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DLambdaExpr::valuetype(const DLambdaExpr & self) noexcept -> TypeDescr
|
||||
{
|
||||
return self.valuetype();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DLambdaExpr::assign_valuetype(DLambdaExpr & self, TypeDescr td) noexcept -> void
|
||||
{
|
||||
self.assign_valuetype(td);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IExpression_DLambdaExpr.cpp */
|
||||
28
src/expression2/IPrintable_DLambdaExpr.cpp
Normal file
28
src/expression2/IPrintable_DLambdaExpr.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DLambdaExpr.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DLambdaExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DLambdaExpr.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IPrintable_DLambdaExpr.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DLambdaExpr::pretty(const DLambdaExpr & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DLambdaExpr.cpp */
|
||||
|
|
@ -20,6 +20,9 @@
|
|||
#include <xo/expression2/detail/IExpression_DApplyExpr.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DApplyExpr.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IExpression_DLambdaExpr.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DLambdaExpr.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IExpression_DIfElseExpr.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DIfElseExpr.hpp>
|
||||
|
||||
|
|
@ -48,6 +51,7 @@ namespace xo {
|
|||
// +- Variable
|
||||
// +- DefineExpr
|
||||
// +- ApplyExpr
|
||||
// +- LambdaExpr
|
||||
// \- IfElseExpr
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DConstant>();
|
||||
|
|
@ -62,6 +66,9 @@ namespace xo {
|
|||
FacetRegistry::register_impl<AExpression, DApplyExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DApplyExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DLambdaExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DLambdaExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DIfElseExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DIfElseExpr>();
|
||||
|
||||
|
|
@ -70,6 +77,7 @@ namespace xo {
|
|||
log && log(xtag("DVariable.tseq", typeseq::id<DVariable>()));
|
||||
log && log(xtag("DConstant.tseq", typeseq::id<DConstant>()));
|
||||
log && log(xtag("DApplyExpr.tseq", typeseq::id<DApplyExpr>()));
|
||||
log && log(xtag("DLambdaExpr.tseq", typeseq::id<DLambdaExpr>()));
|
||||
log && log(xtag("DIfElseExpr.tseq", typeseq::id<DIfElseExpr>()));
|
||||
|
||||
log && log(xtag("AExpression.tqseq", typeseq::id<AExpression>()));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue