mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some fix
This commit is contained in:
parent
63e869df0c
commit
9bfe8c1bad
@ -11,15 +11,15 @@ namespace pkpy{
|
|||||||
// weak reference fast locals
|
// weak reference fast locals
|
||||||
struct FastLocals{
|
struct FastLocals{
|
||||||
// this is a weak reference
|
// this is a weak reference
|
||||||
const NameDictInt* varnames_inv;
|
const CodeObject* co;
|
||||||
PyObject** a;
|
PyObject** a;
|
||||||
|
|
||||||
int size() const{ return varnames_inv->size();}
|
int size() const{ return co->varnames.size();}
|
||||||
|
|
||||||
PyObject*& operator[](int i){ return a[i]; }
|
PyObject*& operator[](int i){ return a[i]; }
|
||||||
PyObject* operator[](int i) const { return a[i]; }
|
PyObject* operator[](int i) const { return a[i]; }
|
||||||
|
|
||||||
FastLocals(const CodeObject* co, PyObject** a): varnames_inv(&co->varnames_inv), a(a) {}
|
FastLocals(const CodeObject* co, PyObject** a): co(co), a(a) {}
|
||||||
|
|
||||||
PyObject** try_get_name(StrName name);
|
PyObject** try_get_name(StrName name);
|
||||||
NameDict_ to_namedict();
|
NameDict_ to_namedict();
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
namespace pkpy{
|
namespace pkpy{
|
||||||
PyObject** FastLocals::try_get_name(StrName name){
|
PyObject** FastLocals::try_get_name(StrName name){
|
||||||
int index = varnames_inv->try_get(name);
|
int index = co->varnames_inv.try_get(name);
|
||||||
if(index == -1) return nullptr;
|
if(index == -1) return nullptr;
|
||||||
return &a[index];
|
return &a[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
NameDict_ FastLocals::to_namedict(){
|
NameDict_ FastLocals::to_namedict(){
|
||||||
NameDict_ dict = std::make_shared<NameDict>();
|
NameDict_ dict = std::make_shared<NameDict>();
|
||||||
varnames_inv->apply([&](StrName name, int index){
|
co->varnames_inv.apply([&](StrName name, int index){
|
||||||
PyObject* value = a[index];
|
PyObject* value = a[index];
|
||||||
if(value != PY_NULL) dict->set(name, value);
|
if(value != PY_NULL) dict->set(name, value);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user