xo-reader2: + assemble lambda function type in DLambdaSsm

This commit is contained in:
Roland Conybeare 2026-01-30 12:41:09 -05:00
commit dd64b61e51
2 changed files with 37 additions and 0 deletions

View file

@ -47,6 +47,14 @@ namespace xo {
const DUniqueString * name,
DLocalSymtab * local_symtab,
obj<AExpression> body);
/** create type description for lambda with arguments described by @p symtab
* and return type @p return_td.
* Load-bearing for DLambdaSsm in xo-reader2/
**/
static TypeDescr assemble_lambda_td(DLocalSymtab * symtab,
TypeDescr return_td);
///@}
/** @defgroup scm-lambdaexpr-methods **/
///@{

View file

@ -14,6 +14,8 @@ namespace xo {
using xo::print::APrintable;
using xo::facet::FacetRegistry;
using xo::reflect::TypeDescr;
using xo::reflect::TypeDescrBase;
using xo::reflect::FunctionTdxInfo;
using xo::reflect::typeseq;
namespace scm {
@ -82,6 +84,33 @@ namespace xo {
body);
}
TypeDescr
DLambdaExpr::assemble_lambda_td(DLocalSymtab * symtab,
TypeDescr return_td)
{
assert(return_td);
std::vector<TypeDescr> arg_td_v;
{
DLocalSymtab::size_type z = symtab->size();
arg_td_v.reserve(z);
for (DLocalSymtab::size_type i = 0; i < z; ++i) {
auto param = symtab->lookup_var(Binding::local(i));
assert(param);
arg_td_v.push_back(param->valuetype());
}
}
auto function_tdx = FunctionTdxInfo(return_td, arg_td_v, false /*!is_noexcept*/);
TypeDescr lambda_td = TypeDescrBase::require_by_fn_info(function_tdx);
return lambda_td;
}
exprtype
DLambdaExpr::extype() const noexcept {
return exprtype::lambda;