1.1 --- a/lib/__builtins__/int.py Tue Nov 22 01:28:58 2016 +0100
1.2 +++ b/lib/__builtins__/int.py Tue Nov 22 17:20:56 2016 +0100
1.3 @@ -131,8 +131,14 @@
1.4 return _negate(self.__eq__(other))
1.5
1.6 def __invert__(self): pass
1.7 - def __neg__(self): pass
1.8 - def __pos__(self): pass
1.9 +
1.10 + def __neg__(self):
1.11 + "Apply the unary negation operator."
1.12 + return native._int_neg(self)
1.13 +
1.14 + def __pos__(self):
1.15 + "Apply the unary positive operator."
1.16 + return self
1.17
1.18 def __str__(self):
1.19 "Return a string representation."
2.1 --- a/lib/native.py Tue Nov 22 01:28:58 2016 +0100
2.2 +++ b/lib/native.py Tue Nov 22 17:20:56 2016 +0100
2.3 @@ -30,6 +30,7 @@
2.4 def _int_div(self, other): pass
2.5 def _int_mod(self, other): pass
2.6 def _int_mul(self, other): pass
2.7 +def _int_neg(self): pass
2.8 def _int_pow(self, other): pass
2.9 def _int_sub(self, other): pass
2.10
3.1 --- a/templates/native.c Tue Nov 22 01:28:58 2016 +0100
3.2 +++ b/templates/native.c Tue Nov 22 17:20:56 2016 +0100
3.3 @@ -153,6 +153,17 @@
3.4 #undef other
3.5 }
3.6
3.7 +__attr __fn_native__int_neg(__attr __args[])
3.8 +{
3.9 + #define self (__args[1])
3.10 + /* self.__data__ interpreted as int */
3.11 + int i = __load_via_object(self.value, __pos___data__).intvalue;
3.12 +
3.13 + /* Return the new integer. */
3.14 + return __new_int(-i);
3.15 + #undef self
3.16 +}
3.17 +
3.18 __attr __fn_native__int_pow(__attr __args[])
3.19 {
3.20 #define self (__args[1])
4.1 --- a/templates/native.h Tue Nov 22 01:28:58 2016 +0100
4.2 +++ b/templates/native.h Tue Nov 22 17:20:56 2016 +0100
4.3 @@ -14,6 +14,7 @@
4.4 __attr __fn_native__int_div(__attr __args[]);
4.5 __attr __fn_native__int_mod(__attr __args[]);
4.6 __attr __fn_native__int_mul(__attr __args[]);
4.7 +__attr __fn_native__int_neg(__attr __args[]);
4.8 __attr __fn_native__int_pow(__attr __args[]);
4.9 __attr __fn_native__int_sub(__attr __args[]);
4.10
5.1 --- a/tests/list.py Tue Nov 22 01:28:58 2016 +0100
5.2 +++ b/tests/list.py Tue Nov 22 17:20:56 2016 +0100
5.3 @@ -5,3 +5,7 @@
5.4 print l[1]
5.5 print l[2]
5.6 print l[3]
5.7 +print l[-1]
5.8 +print l[-2]
5.9 +print l[-3]
5.10 +print l[-4]