/** @file DLocalEnv.cpp * * @author Roland Conybeare, Feb 2026 **/ #include "DLocalEnv.hpp" #include namespace xo { using xo::mm::AGCObject; using xo::reflect::typeseq; namespace scm { DLocalEnv::DLocalEnv(DLocalEnv * parent, DLocalSymtab * symtab, DArray * args) : parent_{parent}, symtab_{symtab}, args_{args} {} DLocalEnv * DLocalEnv::_make_empty(obj mm, DLocalEnv * parent, DLocalSymtab * symtab, DArray * args) { assert(symtab); void * mem = mm.alloc_for(); return new (mem) DLocalEnv(parent, symtab, args); } obj DLocalEnv::lookup_value(Binding ix) const noexcept { assert(!ix.is_global()); const DLocalEnv * env = this; for (auto i = ix.i_link(); i > 0; --i) { env = env->parent(); } if (env) { auto j = ix.j_slot(); if (j < static_cast(env->size())) { return (*(env->args_))[j]; } else { assert(false); } } else { assert(false); } /* something terribly wrong if control here */ return obj(); } void DLocalEnv::assign_value(Binding ix, obj x) { assert(!ix.is_global()); const DLocalEnv * env = this; for (auto i = ix.i_link(); i > 0; --i) { env = env->parent(); } if (env) { auto j = ix.j_slot(); if (j < static_cast(env->size())) { (*(env->args_))[j] = x; } else { assert(false); } } else { assert(false); } /* something terribly wrong if control here */ } } /*namespace scm*/ } /*namespace xo*/ /* end DLocalEnv.cpp */