/** @file DClosure.cpp * * @author Roland Conybeare, Feb 2026 **/ #include "Closure.hpp" #include "LambdaExpr.hpp" #include "LocalEnv.hpp" #include "VsmRcx.hpp" #include #include namespace xo { using xo::mm::AGCObject; using xo::print::APrintable; namespace scm { DClosure::DClosure(const DLambdaExpr * lm, const DLocalEnv * env) : lambda_{lm}, env_{env} {} DClosure * DClosure::make(obj mm, const DLambdaExpr * lm, const DLocalEnv * env) { void * mem = mm.alloc_for(); return new (mem) DClosure(lm, env); } obj DClosure::apply_nocheck(obj rcx, const DArray * args) { scope log(XO_DEBUG(true)); auto vsm_rcx = obj::from(rcx); log && log(xtag("vsm_rcx.data", (void*)vsm_rcx.data())); // let's try a not-implemented error // don't want to clutter Procedure facet, since it's // lower-level than xo-interpreter2 #ifdef NOT_YET // TODO: verify arguments against type signature. // unless we have evidence that program is type correct int32_t n_args = this->n_args(); if (n_args != args->size()) { // } #endif (void)args; assert(false); } size_t DClosure::shallow_size() const noexcept { return sizeof(DClosure); } DClosure * DClosure::shallow_copy(obj mm) const noexcept { DClosure * copy = (DClosure *)mm.alloc_copy((std::byte *)this); if (copy) *copy = *this; return copy; } std::size_t DClosure::forward_children(obj gc) noexcept { { auto iface = xo::facet::impl_for(); gc.forward_inplace(&iface, (void **)(&lambda_)); } { auto iface = xo::facet::impl_for(); gc.forward_inplace(&iface, (void **)(&env_)); } return shallow_size(); } // ----- printable facet ----- bool DClosure::pretty(const ppindentinfo & ppii) const { obj lambda_pr(const_cast(lambda_)); obj env_pr(const_cast(env_)); bool lambda_present = lambda_pr; bool env_present = env_pr; return ppii.pps()->pretty_struct (ppii, "DClosure", refrtag("lambda", lambda_pr, lambda_present), refrtag("env", env_pr, env_present)); } } /*namespace scm*/ } /*namespace xo*/ /* end DClosure.cpp */