exception_value = exc_val, exception_check = exc_check,
nogil = nogil or ctx.nogil or with_gil, with_gil = with_gil)
-supported_overloaded_operators = set(['+', '-', '*', '/', '%', '++', '--', '~', '<<', '>>' ])
+supported_overloaded_operators = set(['+', '-', '*', '/', '%', '++', '--', '~', '|', '&', '^', '<<', '>>' ])
def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
assignable, nonempty):
s.expect(']')
op = '[]'
s.next()
- if op in ['-', '+'] and s.sy == op:
+ if op in ['-', '+', '|', '&'] and s.sy == op:
op = op*2
s.next()
+ if s.sy == '=':
+ op += s.sy
+ s.next()
if op not in supported_overloaded_operators:
s.error("Overloading operator '%s' not yet supported." % op)
name = name+op
char* operator/(int)
char* operator%(int)
+ char* operator|(int)
+ char* operator&(int)
+ char* operator^(int)
+
+ char* operator<<(int)
+ char* operator>>(int)
+
def test_unops():
"""
>>> test_unops()
- unary+
- unary-
- unary~
- unary*
+ unary +
+ unary -
+ unary ~
+ unary *
"""
cdef TestOps* t = new TestOps()
print +t[0]
def test_incdec():
"""
>>> test_incdec()
- unary++
- unary--
- post++
- post--
+ unary ++
+ unary --
+ post ++
+ post --
"""
cdef TestOps* t = new TestOps()
print cython.preincrement(t[0])
def test_binop():
"""
>>> test_binop()
- binary+
- binary-
- binary*
- binary/
- binary%
+ binary +
+ binary -
+ binary *
+ binary /
+ binary %
+ binary &
+ binary |
+ binary ^
+ binary <<
+ binary >>
"""
cdef TestOps* t = new TestOps()
print t[0] + 1
print t[0] * 1
print t[0] / 1
print t[0] % 1
+
+ print t[0] & 1
+ print t[0] | 1
+ print t[0] ^ 1
+
+ print t[0] << 1
+ print t[0] >> 1
del t
-#define UN_OP(op) const char* operator op () { return "unary"#op; }
-#define POST_UN_OP(op) const char* operator op (int x) { return "post"#op; }
-#define BIN_OP(op) const char* operator op (int x) { return "binary"#op; }
+#define UN_OP(op) const char* operator op () { return "unary "#op; }
+#define POST_UN_OP(op) const char* operator op (int x) { return "post "#op; }
+#define BIN_OP(op) const char* operator op (int x) { return "binary "#op; }
class TestOps {
BIN_OP(*);
BIN_OP(/);
BIN_OP(%);
+
+ BIN_OP(<<);
+ BIN_OP(>>);
+
+ BIN_OP(|);
+ BIN_OP(&);
+ BIN_OP(^);
};