This commit is contained in:
blueloveTH 2023-02-27 18:32:33 +08:00
parent 2d26f836ae
commit f13caf5c48
2 changed files with 5 additions and 5 deletions

View File

@ -173,7 +173,7 @@ private:
if(base == 16) SyntaxError("hex literal should not contain a dot"); if(base == 16) SyntaxError("hex literal should not contain a dot");
parser->set_next_token(TK("@num"), vm->PyFloat(S_TO_FLOAT(m[0], &size))); parser->set_next_token(TK("@num"), vm->PyFloat(S_TO_FLOAT(m[0], &size)));
} else { } else {
parser->set_next_token(TK("@num"), vm->PyInt(S_TO_INT(m[0], &size, base))); parser->set_next_token(TK("@num"), py_object(vm, S_TO_INT(m[0], &size, base)));
} }
if (size != m.length()) UNREACHABLE(); if (size != m.length()) UNREACHABLE();
} }

View File

@ -955,10 +955,10 @@ void CodeObject::optimize(VM* vm){
} }
} }
PyVar py_object(VM* vm, i64 val){ template<typename T>
if(((val << 2) >> 2) != val){ std::enable_if_t<std::is_integral_v<T>, PyVar> py_object(VM* vm, T _val){
vm->_error("OverflowError", std::to_string(val) + " is out of range"); i64 val = static_cast<i64>(_val);
} if(((val << 2) >> 2) != val) vm->_error("OverflowError", std::to_string(val));
val = (val << 2) | 0b01; val = (val << 2) | 0b01;
return PyVar(reinterpret_cast<int*>(val)); return PyVar(reinterpret_cast<int*>(val));
} }