summaryrefslogtreecommitdiffstatshomepage
path: root/py/runtime.c
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-11 16:34:56 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-11 16:34:56 +0000
commit813edf63a3e4c0bab3dd5edd4e7295462386c2f3 (patch)
tree17d126927d8a7d01a05bb9dda7bc1732c3ba9f5b /py/runtime.c
parentc1bef21920d7fa03484647f2c339f53663fe0180 (diff)
parentbcbeea0a477ed977a668e67f6f5402260d26ceb9 (diff)
downloadmicropython-813edf63a3e4c0bab3dd5edd4e7295462386c2f3.tar.gz
micropython-813edf63a3e4c0bab3dd5edd4e7295462386c2f3.zip
Merge remote-tracking branch 'upstream/master' into containment
Conflicts: py/runtime.c
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c58
1 files changed, 29 insertions, 29 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 53aea4cbb1..63cb83da56 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -467,6 +467,35 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
// then fail
// note that list does not implement + or +=, so that inplace_concat is reached first for +=
+ // deal with == and != for all types
+ if (op == RT_COMPARE_OP_EQUAL || op == RT_COMPARE_OP_NOT_EQUAL) {
+ if (mp_obj_equal(lhs, rhs)) {
+ if (op == RT_COMPARE_OP_EQUAL) {
+ return mp_const_true;
+ } else {
+ return mp_const_false;
+ }
+ } else {
+ if (op == RT_COMPARE_OP_EQUAL) {
+ return mp_const_false;
+ } else {
+ return mp_const_true;
+ }
+ }
+ }
+
+ // deal with exception_match for all types
+ if (op == RT_COMPARE_OP_EXCEPTION_MATCH) {
+ // TODO properly! at the moment it just compares the exception identifier for equality
+ if (MP_OBJ_IS_TYPE(lhs, &exception_type) && MP_OBJ_IS_TYPE(rhs, &exception_type)) {
+ if (mp_obj_exception_get_type(lhs) == mp_obj_exception_get_type(rhs)) {
+ return mp_const_true;
+ } else {
+ return mp_const_false;
+ }
+ }
+ }
+
if (MP_OBJ_IS_SMALL_INT(lhs)) {
mp_small_int_t lhs_val = MP_OBJ_SMALL_INT_VALUE(lhs);
if (MP_OBJ_IS_SMALL_INT(rhs)) {
@@ -529,35 +558,6 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
} else if (MP_OBJ_IS_TYPE(rhs, &complex_type)) {
return mp_obj_complex_binary_op(op, lhs_val, 0, rhs);
}
- } else {
- // deal with == and !=
- if (op == RT_COMPARE_OP_EQUAL || op == RT_COMPARE_OP_NOT_EQUAL) {
- if (mp_obj_equal(lhs, rhs)) {
- if (op == RT_COMPARE_OP_EQUAL) {
- return mp_const_true;
- } else {
- return mp_const_false;
- }
- } else {
- if (op == RT_COMPARE_OP_EQUAL) {
- return mp_const_false;
- } else {
- return mp_const_true;
- }
- }
- }
-
- // deal with exception_match
- if (op == RT_COMPARE_OP_EXCEPTION_MATCH) {
- // TODO properly! at the moment it just compares the exception identifier for equality
- if (MP_OBJ_IS_TYPE(lhs, &exception_type) && MP_OBJ_IS_TYPE(rhs, &exception_type)) {
- if (mp_obj_exception_get_type(lhs) == mp_obj_exception_get_type(rhs)) {
- return mp_const_true;
- } else {
- return mp_const_false;
- }
- }
- }
}
/* deal with `in` and `not in`