xo-interpreter2: + DGlobalEnv::_upsert_value()

This commit is contained in:
Roland Conybeare 2026-02-28 13:22:59 +11:00
commit 5675e12d97
2 changed files with 26 additions and 0 deletions

View file

@ -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<AAllocator> mm, Binding ix, obj<AGCObject> x);
/** create/establish global for symbol @p sym with resolved type @p td
* and associate with @p value.
**/
DVariable * _upsert_value(obj<AAllocator> mm,
const DUniqueString * sym,
TypeDescr td,
obj<AGCObject> value);
///@}
/** @defgroup scm-globalenv-gcobject-facet **/
///@{

View file

@ -88,6 +88,23 @@ namespace xo {
(*values_)[ix.j_slot()] = x;
}
DVariable *
DGlobalEnv::_upsert_value(obj<AAllocator> mm,
const DUniqueString * sym,
TypeDescr td,
obj<AGCObject> 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