diff --git a/xo-interpreter2/include/xo/interpreter2/DLocalEnv.hpp b/xo-interpreter2/include/xo/interpreter2/DLocalEnv.hpp index 234db71f..c99aaad1 100644 --- a/xo-interpreter2/include/xo/interpreter2/DLocalEnv.hpp +++ b/xo-interpreter2/include/xo/interpreter2/DLocalEnv.hpp @@ -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 mm, - DLocalEnv * parent, - DLocalSymtab * symtab, - DArray * args); + static DLocalEnv * _make(obj mm, + DLocalEnv * parent, + DLocalSymtab * symtab, + DArray * args); ///@} /** @defgroup scm-local-env-methods methods **/ diff --git a/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp b/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp index 3d6632a3..eeeb7289 100644 --- a/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp +++ b/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp @@ -24,6 +24,7 @@ namespace xo { DVsmRcx(VirtualSchematikaMachine * vsm); obj allocator() const noexcept; + obj error_allocator() const noexcept; private: /** schematika interpreter **/ diff --git a/xo-interpreter2/include/xo/interpreter2/VsmConfig.hpp b/xo-interpreter2/include/xo/interpreter2/VsmConfig.hpp index 63c4b365..f05ac449 100644 --- a/xo-interpreter2/include/xo/interpreter2/VsmConfig.hpp +++ b/xo-interpreter2/include/xo/interpreter2/VsmConfig.hpp @@ -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*/ diff --git a/xo-interpreter2/src/interpreter2/DClosure.cpp b/xo-interpreter2/src/interpreter2/DClosure.cpp index 7fa3698c..8aa7997b 100644 --- a/xo-interpreter2/src/interpreter2/DClosure.cpp +++ b/xo-interpreter2/src/interpreter2/DClosure.cpp @@ -7,6 +7,7 @@ #include "LambdaExpr.hpp" #include "LocalEnv.hpp" #include "VsmRcx.hpp" +#include #include #include @@ -35,6 +36,8 @@ namespace xo { DClosure::apply_nocheck(obj 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 diff --git a/xo-interpreter2/src/interpreter2/DLocalEnv.cpp b/xo-interpreter2/src/interpreter2/DLocalEnv.cpp index 9ee0911a..6866fda7 100644 --- a/xo-interpreter2/src/interpreter2/DLocalEnv.cpp +++ b/xo-interpreter2/src/interpreter2/DLocalEnv.cpp @@ -22,10 +22,10 @@ namespace xo { {} DLocalEnv * - DLocalEnv::_make_empty(obj mm, - DLocalEnv * parent, - DLocalSymtab * symtab, - DArray * args) + DLocalEnv::_make(obj mm, + DLocalEnv * parent, + DLocalSymtab * symtab, + DArray * args) { assert(symtab); diff --git a/xo-interpreter2/src/interpreter2/DVsmRcx.cpp b/xo-interpreter2/src/interpreter2/DVsmRcx.cpp index 92e153bc..71916771 100644 --- a/xo-interpreter2/src/interpreter2/DVsmRcx.cpp +++ b/xo-interpreter2/src/interpreter2/DVsmRcx.cpp @@ -19,6 +19,12 @@ namespace xo { return vsm_->allocator(); } + obj + DVsmRcx::error_allocator() const noexcept + { + return vsm_->error_allocator(); + } + } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp b/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp index abdfb168..641723f9 100644 --- a/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp +++ b/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp @@ -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); } diff --git a/xo-interpreter2/utest/VirtualSchematikaMachine.test.cpp b/xo-interpreter2/utest/VirtualSchematikaMachine.test.cpp index 5ccef226..22b50194 100644 --- a/xo-interpreter2/utest/VirtualSchematikaMachine.test.cpp +++ b/xo-interpreter2/utest/VirtualSchematikaMachine.test.cpp @@ -6,9 +6,8 @@ #include #include #include -//#include #include -//#include +#include #ifdef NOT_YET #include @@ -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::from(*res.value()); + // currently get not-implemented error + auto x = obj::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); diff --git a/xo-object2/include/xo/object2/DRuntimeError.hpp b/xo-object2/include/xo/object2/DRuntimeError.hpp index 9da75c68..c59de59d 100644 --- a/xo-object2/include/xo/object2/DRuntimeError.hpp +++ b/xo-object2/include/xo/object2/DRuntimeError.hpp @@ -6,6 +6,7 @@ #pragma once #include "String.hpp" +#include #include namespace xo { @@ -15,20 +16,29 @@ namespace xo { **/ class DRuntimeError { public: + using AGCObject = xo::mm::AGCObject; using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; using ppindentinfo = xo::print::ppindentinfo; public: + /** convenience shortcut.**/ + static obj make(obj mm, + const char * src_fn, + const char * error_descr); + /** create instance using memory from allocator @p mm * @p src_fn identifies the (c++) function/method in which * error detercted. * @p error_descr contains human-readable error message; * will be copied by this function. **/ - DRuntimeError * _make(obj mm, - DString * src_fn, - DString * error_descr); + static DRuntimeError * _make(obj mm, + DString * src_fn, + DString * error_descr); + + DString * src_function() const noexcept { return src_function_; } + DString * error_descr() const noexcept { return error_descr_; } /** @defgroup scm-runtimeerror-printable-facet printable facet **/ ///@{ diff --git a/xo-object2/src/object2/DRuntimeError.cpp b/xo-object2/src/object2/DRuntimeError.cpp index 972bd0c8..2b9fa62f 100644 --- a/xo-object2/src/object2/DRuntimeError.cpp +++ b/xo-object2/src/object2/DRuntimeError.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, Feb 2026 **/ -#include "DRuntimeError.hpp" +#include "RuntimeError.hpp" namespace xo { using xo::mm::AGCObject; @@ -11,6 +11,24 @@ namespace xo { namespace scm { + obj + DRuntimeError::make(obj mm, + const char * src_fn, + const char * error_descr) + { + DRuntimeError * err = DRuntimeError::_make(mm, nullptr, nullptr); + + // pedantic: allocate strings after allocating DRuntimeError instance + + DString * src = DString::from_cstr(mm, src_fn); + DString * err_descr = DString::from_cstr(mm, error_descr); + + err->src_function_ = src; + err->error_descr_ = err_descr; + + return obj(err); + } + DRuntimeError * DRuntimeError::_make(obj mm, DString * src_fn,