xo-interpreter: ObjectConverter + VirtualSchmatikaMachineFlyweight

This commit is contained in:
Roland Conybeare 2025-11-19 21:34:13 -05:00
commit ce6fa08abb

View file

@ -14,21 +14,24 @@ namespace xo {
template<typename Value> template<typename Value>
class TypeDrivenMap { class TypeDrivenMap {
public: public:
Value const * lookup(TypeId id) const { return this->lookup_slot(id); } TypeDrivenMap() = default;
const Value * lookup(TypeId id) const { return this->lookup_slot(id); }
const Value * lookup(TypeDescr td) { return this->lookup_slot(td->id()); }
Value * require(TypeId id) { return this->require_slot(id); } Value * require(TypeId id) { return this->require_slot(id); }
Value * require(TypeDescr td) { return this->require_slot(td->id()); } Value * require(TypeDescr td) { return this->require_slot(td->id()); }
private: private:
Value const * lookup_slot(TypeId id) const { const Value * lookup_slot(TypeId id) const {
if (this->contents_v_.size() <= id.id()) if (contents_v_.size() <= id.id())
return nullptr; return nullptr;
return &(this->contents_v_[id.id()]); return &(this->contents_v_[id.id()]);
} /*lookup_slot*/ } /*lookup_slot*/
Value * require_slot(TypeId id) { Value * require_slot(TypeId id) {
if (this->contents_v_.size() <= id.id()) if (contents_v_.size() <= id.id())
this->contents_v_.resize(id.id() + 1); this->contents_v_.resize(id.id() + 1);
return &(this->contents_v_[id.id()]); return &(this->contents_v_[id.id()]);