| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #pragma once
- #include "obj.h"
- namespace pkpy {
- struct BaseRef {
- virtual PyVar get(VM*, Frame*) const = 0;
- virtual void set(VM*, Frame*, PyVar) const = 0;
- virtual void del(VM*, Frame*) const = 0;
- virtual ~BaseRef() = default;
- };
- enum NameScope {
- NAME_LOCAL = 0,
- NAME_GLOBAL,
- NAME_ATTR,
- NAME_SPECIAL,
- };
- struct NameRef : BaseRef {
- const std::pair<StrName, NameScope> pair;
- inline StrName name() const { return pair.first; }
- inline NameScope scope() const { return pair.second; }
- NameRef(const std::pair<StrName, NameScope>& pair) : pair(pair) {}
- PyVar get(VM* vm, Frame* frame) const;
- void set(VM* vm, Frame* frame, PyVar val) const;
- void del(VM* vm, Frame* frame) const;
- };
- struct AttrRef : BaseRef {
- mutable PyVar obj;
- NameRef attr;
- AttrRef(PyVar obj, NameRef attr) : obj(obj), attr(attr) {}
- PyVar get(VM* vm, Frame* frame) const;
- void set(VM* vm, Frame* frame, PyVar val) const;
- void del(VM* vm, Frame* frame) const;
- };
- struct IndexRef : BaseRef {
- mutable PyVar obj;
- PyVar index;
- IndexRef(PyVar obj, PyVar index) : obj(obj), index(index) {}
- PyVar get(VM* vm, Frame* frame) const;
- void set(VM* vm, Frame* frame, PyVar val) const;
- void del(VM* vm, Frame* frame) const;
- };
- struct TupleRef : BaseRef {
- Tuple objs;
- TupleRef(Tuple&& objs) : objs(std::move(objs)) {}
- PyVar get(VM* vm, Frame* frame) const;
- void set(VM* vm, Frame* frame, PyVar val) const;
- void del(VM* vm, Frame* frame) const;
- };
- } // namespace pkpy
|