mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
This commit is contained in:
parent
4faed9dbf0
commit
de41c27cfa
@ -343,9 +343,14 @@ public:
|
|||||||
void NameError(StrName name){ _builtin_error("NameError", fmt("name ", name.escape() + " is not defined")); }
|
void NameError(StrName name){ _builtin_error("NameError", fmt("name ", name.escape() + " is not defined")); }
|
||||||
void UnboundLocalError(StrName name){ _builtin_error("UnboundLocalError", fmt("local variable ", name.escape() + " referenced before assignment")); }
|
void UnboundLocalError(StrName name){ _builtin_error("UnboundLocalError", fmt("local variable ", name.escape() + " referenced before assignment")); }
|
||||||
void KeyError(PyObject* obj){ _builtin_error("KeyError", obj); }
|
void KeyError(PyObject* obj){ _builtin_error("KeyError", obj); }
|
||||||
void BinaryOptError(const char* op) { TypeError(fmt("unsupported operand type(s) for ", op)); }
|
|
||||||
void ImportError(const Str& msg){ _builtin_error("ImportError", msg); }
|
void ImportError(const Str& msg){ _builtin_error("ImportError", msg); }
|
||||||
|
|
||||||
|
void BinaryOptError(const char* op, PyObject* _0, PyObject* _1) {
|
||||||
|
StrName name_0 = _type_name(vm, _tp(_0));
|
||||||
|
StrName name_1 = _type_name(vm, _tp(_1));
|
||||||
|
TypeError(fmt("unsupported operand type(s) for ", op, ": ", name_0.escape(), " and ", name_1.escape()));
|
||||||
|
}
|
||||||
|
|
||||||
void AttributeError(PyObject* obj, StrName name){
|
void AttributeError(PyObject* obj, StrName name){
|
||||||
if(isinstance(obj, vm->tp_type)){
|
if(isinstance(obj, vm->tp_type)){
|
||||||
_builtin_error("AttributeError", fmt("type object ", _type_name(vm, PK_OBJ_GET(Type, obj)).escape(), " has no attribute ", name.escape()));
|
_builtin_error("AttributeError", fmt("type object ", _type_name(vm, PK_OBJ_GET(Type, obj)).escape(), " has no attribute ", name.escape()));
|
||||||
|
@ -17,8 +17,8 @@ namespace pkpy{
|
|||||||
PyObject* self; \
|
PyObject* self; \
|
||||||
PyObject* _2 = get_unbound_method(_1, rfunc, &self, false); \
|
PyObject* _2 = get_unbound_method(_1, rfunc, &self, false); \
|
||||||
if(_2 != nullptr) ret = call_method(self, _2, _0); \
|
if(_2 != nullptr) ret = call_method(self, _2, _0); \
|
||||||
else BinaryOptError(op); \
|
else BinaryOptError(op, _0, _1); \
|
||||||
if(ret == NotImplemented) BinaryOptError(op); \
|
if(ret == NotImplemented) BinaryOptError(op, _0, _1); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -44,9 +44,9 @@ bool VM::py_ge(PyObject* _0, PyObject* _1){
|
|||||||
|
|
||||||
#undef BINARY_F_COMPARE
|
#undef BINARY_F_COMPARE
|
||||||
|
|
||||||
static i64 _py_sint(PyObject* obj) noexcept {
|
// static i64 _py_sint(PyObject* obj) noexcept {
|
||||||
return (i64)(PK_BITS(obj) >> 2);
|
// return (i64)(PK_BITS(obj) >> 2);
|
||||||
}
|
// }
|
||||||
|
|
||||||
PyObject* VM::_run_top_frame(){
|
PyObject* VM::_run_top_frame(){
|
||||||
FrameId frame = top_frame();
|
FrameId frame = top_frame();
|
||||||
@ -388,19 +388,19 @@ __NEXT_STEP:;
|
|||||||
PyObject* self; \
|
PyObject* self; \
|
||||||
PyObject* _2 = get_unbound_method(_1, func, &self, false); \
|
PyObject* _2 = get_unbound_method(_1, func, &self, false); \
|
||||||
if(_2 != nullptr) TOP() = call_method(self, _2, _0); \
|
if(_2 != nullptr) TOP() = call_method(self, _2, _0); \
|
||||||
else BinaryOptError(op); \
|
else BinaryOptError(op, _0, _1); \
|
||||||
if(TOP() == NotImplemented) BinaryOptError(op); \
|
if(TOP() == NotImplemented) BinaryOptError(op, _0, _1); \
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(BINARY_TRUEDIV){
|
TARGET(BINARY_TRUEDIV){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
BINARY_OP_SPECIAL(__truediv__);
|
BINARY_OP_SPECIAL(__truediv__);
|
||||||
if(TOP() == NotImplemented) BinaryOptError("/");
|
if(TOP() == NotImplemented) BinaryOptError("/", _0, _1);
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
TARGET(BINARY_POW){
|
TARGET(BINARY_POW){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
BINARY_OP_SPECIAL(__pow__);
|
BINARY_OP_SPECIAL(__pow__);
|
||||||
if(TOP() == NotImplemented) BinaryOptError("**");
|
if(TOP() == NotImplemented) BinaryOptError("**", _0, _1);
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
TARGET(BINARY_ADD){
|
TARGET(BINARY_ADD){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
@ -420,12 +420,12 @@ __NEXT_STEP:;
|
|||||||
TARGET(BINARY_FLOORDIV){
|
TARGET(BINARY_FLOORDIV){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
BINARY_OP_SPECIAL(__floordiv__);
|
BINARY_OP_SPECIAL(__floordiv__);
|
||||||
if(TOP() == NotImplemented) BinaryOptError("//");
|
if(TOP() == NotImplemented) BinaryOptError("//", _0, _1);
|
||||||
} DISPATCH()
|
} DISPATCH()
|
||||||
TARGET(BINARY_MOD){
|
TARGET(BINARY_MOD){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
BINARY_OP_SPECIAL(__mod__);
|
BINARY_OP_SPECIAL(__mod__);
|
||||||
if(TOP() == NotImplemented) BinaryOptError("%");
|
if(TOP() == NotImplemented) BinaryOptError("%", _0, _1);
|
||||||
} DISPATCH()
|
} DISPATCH()
|
||||||
TARGET(COMPARE_LT){
|
TARGET(COMPARE_LT){
|
||||||
PyObject* _1 = POPX();
|
PyObject* _1 = POPX();
|
||||||
@ -460,32 +460,32 @@ __NEXT_STEP:;
|
|||||||
TARGET(BITWISE_LSHIFT){
|
TARGET(BITWISE_LSHIFT){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
BINARY_OP_SPECIAL(__lshift__);
|
BINARY_OP_SPECIAL(__lshift__);
|
||||||
if(TOP() == NotImplemented) BinaryOptError("<<");
|
if(TOP() == NotImplemented) BinaryOptError("<<", _0, _1);
|
||||||
} DISPATCH()
|
} DISPATCH()
|
||||||
TARGET(BITWISE_RSHIFT){
|
TARGET(BITWISE_RSHIFT){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
BINARY_OP_SPECIAL(__rshift__);
|
BINARY_OP_SPECIAL(__rshift__);
|
||||||
if(TOP() == NotImplemented) BinaryOptError(">>");
|
if(TOP() == NotImplemented) BinaryOptError(">>", _0, _1);
|
||||||
} DISPATCH()
|
} DISPATCH()
|
||||||
TARGET(BITWISE_AND){
|
TARGET(BITWISE_AND){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
BINARY_OP_SPECIAL(__and__);
|
BINARY_OP_SPECIAL(__and__);
|
||||||
if(TOP() == NotImplemented) BinaryOptError("&");
|
if(TOP() == NotImplemented) BinaryOptError("&", _0, _1);
|
||||||
} DISPATCH()
|
} DISPATCH()
|
||||||
TARGET(BITWISE_OR){
|
TARGET(BITWISE_OR){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
BINARY_OP_SPECIAL(__or__);
|
BINARY_OP_SPECIAL(__or__);
|
||||||
if(TOP() == NotImplemented) BinaryOptError("|");
|
if(TOP() == NotImplemented) BinaryOptError("|", _0, _1);
|
||||||
} DISPATCH()
|
} DISPATCH()
|
||||||
TARGET(BITWISE_XOR){
|
TARGET(BITWISE_XOR){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
BINARY_OP_SPECIAL(__xor__);
|
BINARY_OP_SPECIAL(__xor__);
|
||||||
if(TOP() == NotImplemented) BinaryOptError("^");
|
if(TOP() == NotImplemented) BinaryOptError("^", _0, _1);
|
||||||
} DISPATCH()
|
} DISPATCH()
|
||||||
TARGET(BINARY_MATMUL){
|
TARGET(BINARY_MATMUL){
|
||||||
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
PyObject* _0; PyObject* _1; const PyTypeInfo* _ti;
|
||||||
BINARY_OP_SPECIAL(__matmul__);
|
BINARY_OP_SPECIAL(__matmul__);
|
||||||
if(TOP() == NotImplemented) BinaryOptError("@");
|
if(TOP() == NotImplemented) BinaryOptError("@", _0, _1);
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
|
|
||||||
#undef BINARY_OP_SPECIAL
|
#undef BINARY_OP_SPECIAL
|
||||||
|
@ -337,8 +337,8 @@ test_mat_copy = test_mat.copy()
|
|||||||
test_mat_copy @ vec3(83,-9.12, 0.2983)
|
test_mat_copy @ vec3(83,-9.12, 0.2983)
|
||||||
try:
|
try:
|
||||||
test_mat_copy @ 12345
|
test_mat_copy @ 12345
|
||||||
raise Exception('未能拦截错误 BinaryOptError("@") 在处理表达式 test_mat_copy @ 12345')
|
exit(1)
|
||||||
except:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user