diff --git a/include/xo/interpreter2/DGlobalEnv.hpp b/include/xo/interpreter2/DGlobalEnv.hpp index e68ad55d..e2df166b 100644 --- a/include/xo/interpreter2/DGlobalEnv.hpp +++ b/include/xo/interpreter2/DGlobalEnv.hpp @@ -25,6 +25,7 @@ namespace xo { **/ class DGlobalEnv { public: + using TypeDescr = xo::reflect::TypeDescr; using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; using AGCObject = xo::mm::AGCObject; @@ -57,6 +58,14 @@ namespace xo { **/ void assign_value(obj mm, Binding ix, obj x); + /** create/establish global for symbol @p sym with resolved type @p td + * and associate with @p value. + **/ + DVariable * _upsert_value(obj mm, + const DUniqueString * sym, + TypeDescr td, + obj value); + ///@} /** @defgroup scm-globalenv-gcobject-facet **/ ///@{ diff --git a/src/interpreter2/DGlobalEnv.cpp b/src/interpreter2/DGlobalEnv.cpp index a9285b73..2ad6c1ba 100644 --- a/src/interpreter2/DGlobalEnv.cpp +++ b/src/interpreter2/DGlobalEnv.cpp @@ -88,6 +88,23 @@ namespace xo { (*values_)[ix.j_slot()] = x; } + DVariable * + DGlobalEnv::_upsert_value(obj mm, + const DUniqueString * sym, + TypeDescr td, + obj value) + { + DVariable * var + = DVariable::make(mm, sym, TypeRef::resolved(td)); + + assert(var); + + symtab_->upsert_variable(mm, var); + this->assign_value(mm, var->path(), value); + + return var; + } + // ----- AGCObject facet ----- std::size_t