@@ -112,8 +112,8 @@ PyVar VM::run_frame(Frame* frame){
case OP_POP_TOP: frame->_pop(); continue;
case OP_BINARY_OP: {
pkpy::Args args(2);
- args[1] = frame->pop();
- args[0] = frame->top();
+ args[1] = frame->pop_value(this);
+ args[0] = frame->top_value(this);
frame->top() = fast_call(BINARY_SPECIAL_METHODS[byte.arg], std::move(args));
} continue;
case OP_BITWISE_OP: {
@@ -39,13 +39,9 @@
#if defined(__EMSCRIPTEN__) || defined(__arm__) || defined(__i386__)
typedef int32_t i64;
typedef float f64;
-const i64 kMinSafeInt = -((i64)1 << 30);
-const i64 kMaxSafeInt = ((i64)1 << 30) - 1;
#else
typedef int64_t i64;
typedef double f64;
-const i64 kMinSafeInt = -((i64)1 << 62);
-const i64 kMaxSafeInt = ((i64)1 << 62) - 1;
#endif
struct Dummy { char _; };
@@ -86,7 +86,7 @@ void init_builtins(VM* _vm) {
_vm->bind_builtin_func<1>("hash", [](VM* vm, pkpy::Args& args){
i64 value = vm->hash(args[0]);
- if(value < kMinSafeInt || value > kMaxSafeInt) value >>= 2;
+ if(((value << 2) >> 2) != value) value >>= 2;
return vm->PyInt(value);
});
@@ -551,7 +551,7 @@ public:
}
inline PyVar PyInt(i64 value) {
- if(value < kMinSafeInt || value > kMaxSafeInt){
+ if(((value << 2) >> 2) != value){
_error("OverflowError", std::to_string(value) + " is out of range");
value = (value << 2) | 0b01;
@@ -120,9 +120,8 @@ assert round(-23.8) == -24
assert 7**21 == 558545864083284007
-assert 7**22 == 3909821048582988049
-assert 2**61 == 2305843009213693952
-assert -2**61 == -2305843009213693952
+assert 2**60 == 1152921504606846976
+assert -2**60 == -1152921504606846976
assert eq(2**-2, 0.25)
assert 0**0 == 1
assert 0**1 == 0