|
|
@@ -1,10 +1,8 @@
|
|
|
#include "pocketpy/interpreter/vm.h"
|
|
|
#include "pocketpy/pocketpy.h"
|
|
|
|
|
|
-bool py_isidentical(const py_Ref lhs, const py_Ref rhs){
|
|
|
- if(lhs->is_ptr && rhs->is_ptr){
|
|
|
- return lhs->_obj == rhs->_obj;
|
|
|
- }
|
|
|
+bool py_isidentical(const py_Ref lhs, const py_Ref rhs) {
|
|
|
+ if(lhs->is_ptr && rhs->is_ptr) { return lhs->_obj == rhs->_obj; }
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -24,38 +22,16 @@ bool py_setitem(py_Ref self, const py_Ref key, const py_Ref val) { return -1; }
|
|
|
|
|
|
bool py_delitem(py_Ref self, const py_Ref key) { return -1; }
|
|
|
|
|
|
-int py_eq(const py_Ref lhs, const py_Ref rhs) {
|
|
|
- bool ok = py_binaryop(lhs, rhs, __eq__, __eq__);
|
|
|
- if(!ok) return -1;
|
|
|
- return py_tobool(py_lastretval());
|
|
|
-}
|
|
|
-
|
|
|
-int py_ne(const py_Ref lhs, const py_Ref rhs) {
|
|
|
- bool ok = py_binaryop(lhs, rhs, __ne__, __ne__);
|
|
|
- if(!ok) return -1;
|
|
|
- return py_tobool(py_lastretval());
|
|
|
-}
|
|
|
-
|
|
|
-int py_lt(const py_Ref lhs, const py_Ref rhs) {
|
|
|
- bool ok = py_binaryop(lhs, rhs, __lt__, __gt__);
|
|
|
- if(!ok) return -1;
|
|
|
- return py_tobool(py_lastretval());
|
|
|
-}
|
|
|
-
|
|
|
-int py_gt(const py_Ref lhs, const py_Ref rhs) {
|
|
|
- bool ok = py_binaryop(lhs, rhs, __gt__, __lt__);
|
|
|
- if(!ok) return -1;
|
|
|
- return py_tobool(py_lastretval());
|
|
|
-}
|
|
|
-
|
|
|
-int py_ge(const py_Ref lhs, const py_Ref rhs) {
|
|
|
- bool ok = py_binaryop(lhs, rhs, __ge__, __le__);
|
|
|
- if(!ok) return -1;
|
|
|
- return py_tobool(py_lastretval());
|
|
|
-}
|
|
|
+#define COMPARE_OP_IMPL(name, op, rop) \
|
|
|
+ int py_##name(const py_Ref lhs, const py_Ref rhs) { \
|
|
|
+ bool ok = py_binaryop(lhs, rhs, op, rop); \
|
|
|
+ if(!ok) return -1; \
|
|
|
+ return py_tobool(py_lastretval()); \
|
|
|
+ }
|
|
|
|
|
|
-int py_le(const py_Ref lhs, const py_Ref rhs) {
|
|
|
- bool ok = py_binaryop(lhs, rhs, __le__, __ge__);
|
|
|
- if(!ok) return -1;
|
|
|
- return py_tobool(py_lastretval());
|
|
|
-}
|
|
|
+COMPARE_OP_IMPL(eq, __eq__, __eq__)
|
|
|
+COMPARE_OP_IMPL(ne, __ne__, __ne__)
|
|
|
+COMPARE_OP_IMPL(lt, __lt__, __gt__)
|
|
|
+COMPARE_OP_IMPL(le, __le__, __ge__)
|
|
|
+COMPARE_OP_IMPL(gt, __gt__, __lt__)
|
|
|
+COMPARE_OP_IMPL(ge, __ge__, __le__)
|