...
This commit is contained in:
blueloveTH 2023-09-22 00:09:03 +08:00
parent 5c69e1380a
commit bb96279e9b
2 changed files with 7 additions and 1 deletions

View File

@ -361,6 +361,8 @@ public:
void TypeError(const Str& msg){ _error("TypeError", msg); }
void IndexError(const Str& msg){ _error("IndexError", msg); }
void ValueError(const Str& msg){ _error("ValueError", msg); }
void ZeroDivisionError(const Str& msg){ _error("ZeroDivisionError", msg); }
void ZeroDivisionError(){ _error("ZeroDivisionError", "division by zero"); }
void NameError(StrName name){ _error("NameError", fmt("name ", name.escape() + " is not defined")); }
void UnboundLocalError(StrName name){ _error("UnboundLocalError", fmt("local variable ", name.escape() + " referenced before assignment")); }
void KeyError(PyObject* obj){ _error("KeyError", PK_OBJ_GET(Str, py_repr(obj))); }

View File

@ -383,7 +383,11 @@ void init_builtins(VM* _vm) {
i64 lhs, rhs;
if(try_cast_int(lhs_, &lhs) && try_cast_int(rhs_, &rhs)){
bool flag = false;
if(rhs < 0) {flag = true; rhs = -rhs;}
if(rhs < 0) {
if(lhs == 0) vm->ZeroDivisionError("0.0 cannot be raised to a negative power");
flag = true;
rhs = -rhs;
}
i64 ret = 1;
while(rhs){
if(rhs & 1) ret *= lhs;