This commit is contained in:
blueloveTH 2024-05-05 10:55:51 +08:00
parent 0f47105b27
commit 9943516d79
2 changed files with 5 additions and 8 deletions

View File

@ -356,10 +356,12 @@ public:
bool issubclass(Type cls, Type base); bool issubclass(Type cls, Type base);
void check_type(PyObject* obj, Type type){ if(!is_type(obj, type)) TypeError(type, _tp(obj)); } void check_type(PyObject* obj, Type type){ if(!is_type(obj, type)) TypeError(type, _tp(obj)); }
void check_compatible_type(PyObject* obj, Type type){ if(!isinstance(obj, type)) TypeError(type, _tp(obj)); } void check_compatible_type(PyObject* obj, Type type){ if(!isinstance(obj, type)) TypeError(type, _tp(obj)); }
PyObject* _t(PyObject* obj){ return _all_types[_tp(obj)].obj; }
PyObject* _t(Type t){ return _all_types[t.index].obj; }
Type _tp(PyObject* obj){ return is_small_int(obj) ? tp_int : obj->type; } Type _tp(PyObject* obj){ return is_small_int(obj) ? tp_int : obj->type; }
const PyTypeInfo* _tp_info(PyObject* obj); const PyTypeInfo* _tp_info(PyObject* obj) { return &_all_types[_tp(obj)]; }
const PyTypeInfo* _tp_info(Type type) { return &_all_types[type]; }
PyObject* _t(PyObject* obj){ return _all_types[_tp(obj)].obj; }
PyObject* _t(Type type){ return _all_types[type].obj; }
#endif #endif
#if PK_REGION("User Type Registration") #if PK_REGION("User Type Registration")

View File

@ -212,11 +212,6 @@ namespace pkpy{
return obj; return obj;
} }
const PyTypeInfo* VM::_tp_info(PyObject* obj){
if(is_small_int(obj)) return &_all_types[tp_int];
return &_all_types[obj->type];
}
bool VM::py_eq(PyObject* lhs, PyObject* rhs){ bool VM::py_eq(PyObject* lhs, PyObject* rhs){
if(lhs == rhs) return true; if(lhs == rhs) return true;
const PyTypeInfo* ti = _tp_info(lhs); const PyTypeInfo* ti = _tp_info(lhs);