|
|
@@ -40,29 +40,29 @@
|
|
|
// }
|
|
|
|
|
|
#define DEF_NUM_BINARY_OP(name, op, rint, rfloat) \
|
|
|
- static bool _py_int##name(int argc, py_Ref argv, py_Ref out) { \
|
|
|
+ static bool _py_int##name(int argc, py_Ref argv) { \
|
|
|
py_checkargc(2); \
|
|
|
if(py_isint(&argv[1])) { \
|
|
|
int64_t lhs = py_toint(&argv[0]); \
|
|
|
int64_t rhs = py_toint(&argv[1]); \
|
|
|
- rint(out, lhs op rhs); \
|
|
|
+ rint(py_lastretval(), lhs op rhs); \
|
|
|
} else if(py_isfloat(&argv[1])) { \
|
|
|
int64_t lhs = py_toint(&argv[0]); \
|
|
|
double rhs = py_tofloat(&argv[1]); \
|
|
|
- rfloat(out, lhs op rhs); \
|
|
|
+ rfloat(py_lastretval(), lhs op rhs); \
|
|
|
} else { \
|
|
|
- py_newnotimplemented(out); \
|
|
|
+ py_newnotimplemented(py_lastretval()); \
|
|
|
} \
|
|
|
return true; \
|
|
|
} \
|
|
|
- static bool _py_float##name(int argc, py_Ref argv, py_Ref out) { \
|
|
|
+ static bool _py_float##name(int argc, py_Ref argv) { \
|
|
|
py_checkargc(2); \
|
|
|
double lhs = py_tofloat(&argv[0]); \
|
|
|
double rhs; \
|
|
|
if(py_castfloat(&argv[1], &rhs)) { \
|
|
|
- rfloat(out, lhs op rhs); \
|
|
|
+ rfloat(py_lastretval(), lhs op rhs); \
|
|
|
} else { \
|
|
|
- py_newnotimplemented(out); \
|
|
|
+ py_newnotimplemented(py_lastretval()); \
|
|
|
} \
|
|
|
return true; \
|
|
|
}
|
|
|
@@ -80,47 +80,47 @@ DEF_NUM_BINARY_OP(__ge__, >=, py_newbool, py_newbool)
|
|
|
|
|
|
#undef DEF_NUM_BINARY_OP
|
|
|
|
|
|
-static bool _py_int__neg__(int argc, py_Ref argv, py_Ref out) {
|
|
|
+static bool _py_int__neg__(int argc, py_Ref argv) {
|
|
|
py_checkargc(1);
|
|
|
int64_t val = py_toint(&argv[0]);
|
|
|
- py_newint(out, -val);
|
|
|
+ py_newint(py_lastretval(), -val);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-static bool _py_float__neg__(int argc, py_Ref argv, py_Ref out) {
|
|
|
+static bool _py_float__neg__(int argc, py_Ref argv) {
|
|
|
py_checkargc(1);
|
|
|
double val = py_tofloat(&argv[0]);
|
|
|
- py_newfloat(out, -val);
|
|
|
+ py_newfloat(py_lastretval(), -val);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-static bool _py_int__truediv__(int argc, py_Ref argv, py_Ref out) {
|
|
|
+static bool _py_int__truediv__(int argc, py_Ref argv) {
|
|
|
py_checkargc(2);
|
|
|
int64_t lhs = py_toint(&argv[0]);
|
|
|
double rhs;
|
|
|
if(py_castfloat(&argv[1], &rhs)) {
|
|
|
- py_newfloat(out, lhs / rhs);
|
|
|
+ py_newfloat(py_lastretval(), lhs / rhs);
|
|
|
} else {
|
|
|
- py_newnotimplemented(out);
|
|
|
+ py_newnotimplemented(py_lastretval());
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-static bool _py_float__truediv__(int argc, py_Ref argv, py_Ref out) {
|
|
|
+static bool _py_float__truediv__(int argc, py_Ref argv) {
|
|
|
py_checkargc(2);
|
|
|
double lhs = py_tofloat(&argv[0]);
|
|
|
double rhs;
|
|
|
if(py_castfloat(&argv[1], &rhs)) {
|
|
|
- py_newfloat(out, lhs / rhs);
|
|
|
+ py_newfloat(py_lastretval(), lhs / rhs);
|
|
|
} else {
|
|
|
- py_newnotimplemented(out);
|
|
|
+ py_newnotimplemented(py_lastretval());
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
#define ZeroDivisionError(msg) false
|
|
|
|
|
|
-static bool _py_number__pow__(int argc, py_Ref argv, py_Ref out) {
|
|
|
+static bool _py_number__pow__(int argc, py_Ref argv) {
|
|
|
py_checkargc(2);
|
|
|
if(py_isint(&argv[0]) && py_isint(&argv[1])) {
|
|
|
int64_t lhs = py_toint(&argv[0]);
|
|
|
@@ -129,7 +129,7 @@ static bool _py_number__pow__(int argc, py_Ref argv, py_Ref out) {
|
|
|
if(lhs == 0) {
|
|
|
return ZeroDivisionError("0.0 cannot be raised to a negative power");
|
|
|
} else {
|
|
|
- py_newfloat(out, pow(lhs, rhs));
|
|
|
+ py_newfloat(py_lastretval(), pow(lhs, rhs));
|
|
|
}
|
|
|
} else {
|
|
|
int64_t ret = 1;
|
|
|
@@ -138,54 +138,54 @@ static bool _py_number__pow__(int argc, py_Ref argv, py_Ref out) {
|
|
|
lhs *= lhs;
|
|
|
rhs >>= 1;
|
|
|
}
|
|
|
- py_newint(out, ret);
|
|
|
+ py_newint(py_lastretval(), ret);
|
|
|
}
|
|
|
} else {
|
|
|
double lhs, rhs;
|
|
|
py_castfloat(&argv[0], &lhs);
|
|
|
if(py_castfloat(&argv[1], &rhs)) {
|
|
|
- py_newfloat(out, pow(lhs, rhs));
|
|
|
+ py_newfloat(py_lastretval(), pow(lhs, rhs));
|
|
|
} else {
|
|
|
- py_newnotimplemented(out);
|
|
|
+ py_newnotimplemented(py_lastretval());
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-static bool _py_int__floordiv__(int argc, py_Ref argv, py_Ref out) {
|
|
|
+static bool _py_int__floordiv__(int argc, py_Ref argv) {
|
|
|
py_checkargc(2);
|
|
|
int64_t lhs = py_toint(&argv[0]);
|
|
|
if(py_isint(&argv[1])) {
|
|
|
int64_t rhs = py_toint(&argv[1]);
|
|
|
if(rhs == 0) return -1;
|
|
|
- py_newint(out, lhs / rhs);
|
|
|
+ py_newint(py_lastretval(), lhs / rhs);
|
|
|
} else {
|
|
|
- py_newnotimplemented(out);
|
|
|
+ py_newnotimplemented(py_lastretval());
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-static bool _py_int__mod__(int argc, py_Ref argv, py_Ref out) {
|
|
|
+static bool _py_int__mod__(int argc, py_Ref argv) {
|
|
|
py_checkargc(2);
|
|
|
int64_t lhs = py_toint(&argv[0]);
|
|
|
if(py_isint(&argv[1])) {
|
|
|
int64_t rhs = py_toint(&argv[1]);
|
|
|
if(rhs == 0) return ZeroDivisionError("integer division or modulo by zero");
|
|
|
- py_newint(out, lhs % rhs);
|
|
|
+ py_newint(py_lastretval(), lhs % rhs);
|
|
|
} else {
|
|
|
- py_newnotimplemented(out);
|
|
|
+ py_newnotimplemented(py_lastretval());
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-static bool _py_int__invert__(int argc, py_Ref argv, py_Ref out) {
|
|
|
+static bool _py_int__invert__(int argc, py_Ref argv) {
|
|
|
py_checkargc(1);
|
|
|
int64_t val = py_toint(&argv[0]);
|
|
|
- py_newint(out, ~val);
|
|
|
+ py_newint(py_lastretval(), ~val);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-static bool _py_int__bit_length(int argc, py_Ref argv, py_Ref out) {
|
|
|
+static bool _py_int__bit_length(int argc, py_Ref argv) {
|
|
|
py_checkargc(1);
|
|
|
int64_t x = py_toint(py_arg(0));
|
|
|
if(x < 0) x = -x;
|
|
|
@@ -194,19 +194,19 @@ static bool _py_int__bit_length(int argc, py_Ref argv, py_Ref out) {
|
|
|
x >>= 1;
|
|
|
bits++;
|
|
|
}
|
|
|
- py_newint(out, bits);
|
|
|
+ py_newint(py_lastretval(), bits);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
#define DEF_INT_BITWISE_OP(name, op) \
|
|
|
- static bool _py_int##name(int argc, py_Ref argv, py_Ref out) { \
|
|
|
+ static bool _py_int##name(int argc, py_Ref argv) { \
|
|
|
py_checkargc(2); \
|
|
|
int64_t lhs = py_toint(&argv[0]); \
|
|
|
if(py_isint(&argv[1])) { \
|
|
|
int64_t rhs = py_toint(&argv[1]); \
|
|
|
- py_newint(out, lhs op rhs); \
|
|
|
+ py_newint(py_lastretval(), lhs op rhs); \
|
|
|
} else { \
|
|
|
- py_newnotimplemented(out); \
|
|
|
+ py_newnotimplemented(py_lastretval()); \
|
|
|
} \
|
|
|
return true; \
|
|
|
}
|