Update vm.h

This commit is contained in:
blueloveTH 2023-02-23 08:52:42 +08:00
parent 8fd38d0c81
commit ab4fef8c00

View File

@ -333,7 +333,7 @@ public:
} }
PyVarOrNull getattr(const PyVar& obj, StrName name, bool throw_err=true) { PyVarOrNull getattr(const PyVar& obj, StrName name, bool throw_err=true) {
pkpy::NameDict::iterator it; PyVar* val;
PyObject* cls; PyObject* cls;
if(is_type(obj, tp_super)){ if(is_type(obj, tp_super)){
@ -347,23 +347,23 @@ public:
cls = _t(*root).get(); cls = _t(*root).get();
for(int i=0; i<depth; i++) cls = cls->attr(__base__).get(); for(int i=0; i<depth; i++) cls = cls->attr(__base__).get();
it = (*root)->attr().find(name); val = (*root)->attr().try_get(name);
if(it != (*root)->attr().end()) return it->second; if(val != nullptr) return *val;
}else{ }else{
if(!obj.is_tagged() && obj->is_attr_valid()){ if(!obj.is_tagged() && obj->is_attr_valid()){
it = obj->attr().find(name); val = obj->attr().try_get(name);
if(it != obj->attr().end()) return it->second; if(val != nullptr) return *val;
} }
cls = _t(obj).get(); cls = _t(obj).get();
} }
while(cls != None.get()) { while(cls != None.get()) {
it = cls->attr().find(name); val = cls->attr().try_get(name);
if(it != cls->attr().end()){ if(val != nullptr){
if(is_type(it->second, tp_function) || is_type(it->second, tp_native_function)){ if(is_type(*val, tp_function) || is_type(*val, tp_native_function)){
return PyBoundMethod({obj, it->second}); return PyBoundMethod({obj, *val});
}else{ }else{
return it->second; return *val;
} }
} }
cls = cls->attr(__base__).get(); cls = cls->attr(__base__).get();