summaryrefslogtreecommitdiffstatshomepage
path: root/py/runtime.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-15 00:31:28 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-15 00:32:09 +0200
commit8bc96471f0219b9d3f24ae879f60b509927e1df4 (patch)
treeb14f198545074bc505b452e617abf2a643b1d84d /py/runtime.c
parent8eec8bcad95d5e60485635a2dbfd97886698d954 (diff)
downloadmicropython-8bc96471f0219b9d3f24ae879f60b509927e1df4.tar.gz
micropython-8bc96471f0219b9d3f24ae879f60b509927e1df4.zip
Implement "is" and "is not" operators.
So far, don't work for strings as expected.
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/py/runtime.c b/py/runtime.c
index f43e804b40..b2d9c7e960 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -461,6 +461,18 @@ 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 is, is not
+ if (op == RT_COMPARE_OP_IS) {
+ // TODO: may need to handle strings specially, CPython appears to
+ // assume all strings are interned (so "is" == "==" for strings)
+ return MP_BOOL(lhs == rhs);
+ }
+ if (op == RT_COMPARE_OP_IS_NOT) {
+ // TODO: may need to handle strings specially, CPython appears to
+ // assume all strings are interned (so "is" == "==" for strings)
+ return MP_BOOL(lhs != rhs);
+ }
+
// deal with == and != for all types
if (op == RT_COMPARE_OP_EQUAL || op == RT_COMPARE_OP_NOT_EQUAL) {
if (mp_obj_equal(lhs, rhs)) {