xo-expression2: + LambdaExpr ++ LocalSymtab
This commit is contained in:
parent
a69023096d
commit
666482a945
15 changed files with 621 additions and 9 deletions
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 */
|
||||
Loading…
Add table
Add a link
Reference in a new issue