some cleanup

This commit is contained in:
blueloveTH 2024-01-15 12:55:49 +08:00
parent 139093df3a
commit 3362c23e53
3 changed files with 3 additions and 22 deletions

View File

@ -221,9 +221,6 @@ public:
PyObject* new_type_object(PyObject* mod, StrName name, Type base, bool subclass_enabled=true); PyObject* new_type_object(PyObject* mod, StrName name, Type base, bool subclass_enabled=true);
Type _new_type_object(StrName name, Type base=0, bool subclass_enabled=false); Type _new_type_object(StrName name, Type base=0, bool subclass_enabled=false);
PyObject* _find_type_object(const Str& type);
Type _type(const Str& type);
PyTypeInfo* _type_info(Type type); PyTypeInfo* _type_info(Type type);
const PyTypeInfo* _inst_type_info(PyObject* obj); const PyTypeInfo* _inst_type_info(PyObject* obj);

View File

@ -347,7 +347,7 @@ void init_builtins(VM* _vm) {
_vm->bind__iter__(VM::tp_range, [](VM* vm, PyObject* obj) { return VAR_T(RangeIter, PK_OBJ_GET(Range, obj)); }); _vm->bind__iter__(VM::tp_range, [](VM* vm, PyObject* obj) { return VAR_T(RangeIter, PK_OBJ_GET(Range, obj)); });
// tp_nonetype // tp_nonetype
_vm->bind__repr__(_vm->_type("NoneType"), [](VM* vm, PyObject* obj) { _vm->bind__repr__(_vm->_tp(_vm->None), [](VM* vm, PyObject* obj) {
return VAR("None"); return VAR("None");
}); });
@ -951,10 +951,10 @@ void init_builtins(VM* _vm) {
}); });
// tp_ellipsis / tp_NotImplementedType // tp_ellipsis / tp_NotImplementedType
_vm->bind__repr__(_vm->_type("ellipsis"), [](VM* vm, PyObject* self) { _vm->bind__repr__(_vm->_tp(_vm->Ellipsis), [](VM* vm, PyObject* self) {
return VAR("..."); return VAR("...");
}); });
_vm->bind__repr__(_vm->_type("NotImplementedType"), [](VM* vm, PyObject* self) { _vm->bind__repr__(_vm->_tp(_vm->NotImplemented), [](VM* vm, PyObject* self) {
return VAR("NotImplemented"); return VAR("NotImplemented");
}); });

View File

@ -219,22 +219,6 @@ namespace pkpy{
return PK_OBJ_GET(Type, obj); return PK_OBJ_GET(Type, obj);
} }
PyObject* VM::_find_type_object(const Str& type){
PyObject* obj = builtins->attr().try_get_likely_found(type);
if(obj == nullptr){
for(auto& t: _all_types) if(t.name == type) return t.obj;
throw std::runtime_error(fmt("type not found: ", type).str());
}
check_non_tagged_type(obj, tp_type);
return obj;
}
Type VM::_type(const Str& type){
PyObject* obj = _find_type_object(type);
return PK_OBJ_GET(Type, obj);
}
PyTypeInfo* VM::_type_info(Type type){ PyTypeInfo* VM::_type_info(Type type){
return &_all_types[type]; return &_all_types[type];
} }