xo-interpreter2 stack: work on apply for closures [WIP]

This commit is contained in:
Roland Conybeare 2026-02-12 20:09:22 -05:00
commit fd0e5613dd
8 changed files with 47 additions and 27 deletions

View file

@ -26,15 +26,15 @@ namespace xo {
/** @defgroup scm-localenv-constructors constructors **/
///@{
/** empty instance with parent @p p for variables in @p symtab **/
/** create instance with parent @p p for variables in @p symtab **/
DLocalEnv(DLocalEnv * parent,
DLocalSymtab * symtab,
DArray * args);
static DLocalEnv * _make_empty(obj<AAllocator> mm,
DLocalEnv * parent,
DLocalSymtab * symtab,
DArray * args);
static DLocalEnv * _make(obj<AAllocator> mm,
DLocalEnv * parent,
DLocalSymtab * symtab,
DArray * args);
///@}
/** @defgroup scm-local-env-methods methods **/

View file

@ -24,6 +24,7 @@ namespace xo {
DVsmRcx(VirtualSchematikaMachine * vsm);
obj<AAllocator> allocator() const noexcept;
obj<AAllocator> error_allocator() const noexcept;
private:
/** schematika interpreter **/

View file

@ -31,7 +31,7 @@ namespace xo {
/** Configuration for error allocator
* TODO: may want to make ArenaConfig polymorphic
**/
ArenaConfig error_config_ = ArenaConfig().with_size(64*1024);
ArenaConfig error_config_ = ArenaConfig().with_name("error-reserve").with_size(64*1024);
};
} /*namespace scm*/
} /*namespace xo*/

View file

@ -7,6 +7,7 @@
#include "LambdaExpr.hpp"
#include "LocalEnv.hpp"
#include "VsmRcx.hpp"
#include <xo/object2/RuntimeError.hpp>
#include <xo/indentlog/scope.hpp>
#include <cstddef>
@ -35,6 +36,8 @@ namespace xo {
DClosure::apply_nocheck(obj<ARuntimeContext> rcx,
const DArray * args)
{
(void)args;
scope log(XO_DEBUG(true));
auto vsm_rcx
@ -42,26 +45,31 @@ namespace xo {
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
// we already checked this stuff before calling apply_nocheck()
// assert (n_args == args->size());
#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()) {
//
}
auto local_env
= DLocalEnv::_make(vsm_rcx->allocator(),
env_,
lambda_->local_symtab(),
args);
#endif
// plan:
// 1. push current local environment to vsm stack_
// 2. set expr_ to lambda body
// 2. set pc_ to eval
// 3. set cont_ to restore local_env_
(void)args;
auto err_mm
= vsm_rcx->error_allocator();
assert(false);
auto err
= DRuntimeError::make(err_mm,
"DClosure::apply_nocheck",
"not implemented");
return err;
}
size_t

View file

@ -22,10 +22,10 @@ namespace xo {
{}
DLocalEnv *
DLocalEnv::_make_empty(obj<AAllocator> mm,
DLocalEnv * parent,
DLocalSymtab * symtab,
DArray * args)
DLocalEnv::_make(obj<AAllocator> mm,
DLocalEnv * parent,
DLocalSymtab * symtab,
DArray * args)
{
assert(symtab);

View file

@ -19,6 +19,12 @@ namespace xo {
return vsm_->allocator();
}
obj<AAllocator>
DVsmRcx::error_allocator() const noexcept
{
return vsm_->error_allocator();
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -82,6 +82,7 @@ namespace xo {
VirtualSchematikaMachine::visit_pools(const MemorySizeVisitor & visitor) const
{
mm_.visit_pools(visitor);
error_mm_.visit_pools(visitor);
reader_.visit_pools(visitor);
}

View file

@ -6,9 +6,8 @@
#include <xo/interpreter2/VirtualSchematikaMachine.hpp>
#include <xo/interpreter2/Closure.hpp>
#include <xo/object2/Float.hpp>
//#include <xo/object2/number/IGCObject_DFloat.hpp>
#include <xo/object2/Integer.hpp>
//#include <xo/object2/number/IGCObject_DInteger.hpp>
#include <xo/object2/RuntimeError.hpp>
#ifdef NOT_YET
#include <xo/reader2/SchematikaParser.hpp>
@ -32,6 +31,7 @@ namespace xo {
using xo::scm::DClosure;
using xo::scm::DFloat;
using xo::scm::DInteger;
using xo::scm::DRuntimeError;
using xo::mm::AGCObject;
using xo::mm::MemorySizeInfo;
using xo::facet::FacetRegistry;
@ -245,9 +245,13 @@ namespace xo {
log && log(xtag("res.tseq", res.value()->_typeseq()));
auto x = obj<AGCObject,DClosure>::from(*res.value());
// currently get not-implemented error
auto x = obj<AGCObject,DRuntimeError>::from(*res.value());
REQUIRE(x);
log && log("runtime-error", xtag("ex.src", x->src_function()), xtag("ex.descr", x->error_descr()));
//REQUIRE(x.data()->value() == 1.570796325);
REQUIRE(res.remaining_.size() == 1);