summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-03-30 02:29:59 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-03-31 01:05:03 +0300
commit1bc534247cfe585afeba41b58b25a21af158ae4e (patch)
treedd2cf6ff831114dfbce8380224f85152d1fd1e98 /py
parentfdaac1dbf8109ec42b6bf63bfea9627ddc3e4920 (diff)
downloadmicropython-1bc534247cfe585afeba41b58b25a21af158ae4e.tar.gz
micropython-1bc534247cfe585afeba41b58b25a21af158ae4e.zip
objtype: Add special unary methods __pos__, __neg__, __invert__.
Conditional on MICROPY_PY_ALL_SPECIAL_METHODS.
Diffstat (limited to 'py')
-rw-r--r--py/objtype.c8
-rw-r--r--py/qstrdefs.h3
2 files changed, 8 insertions, 3 deletions
diff --git a/py/objtype.c b/py/objtype.c
index c08a6357cf..8624a4ff32 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -330,9 +330,11 @@ mp_obj_t instance_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, c
const qstr mp_unary_op_method_name[] = {
[MP_UNARY_OP_BOOL] = MP_QSTR___bool__,
[MP_UNARY_OP_LEN] = MP_QSTR___len__,
- //[MP_UNARY_OP_POSITIVE,
- //[MP_UNARY_OP_NEGATIVE,
- //[MP_UNARY_OP_INVERT,
+ #if MICROPY_PY_ALL_SPECIAL_METHODS
+ [MP_UNARY_OP_POSITIVE] = MP_QSTR___pos__,
+ [MP_UNARY_OP_NEGATIVE] = MP_QSTR___neg__,
+ [MP_UNARY_OP_INVERT] = MP_QSTR___invert__,
+ #endif
[MP_UNARY_OP_NOT] = MP_QSTR_, // don't need to implement this, used to make sure array has full size
};
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index 3c4106e853..560b16d6a8 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -85,6 +85,9 @@ Q(__truediv__)
Q(__floordiv__)
Q(__iadd__)
Q(__isub__)
+Q(__invert__)
+Q(__neg__)
+Q(__pos__)
#endif
Q(micropython)