OLD | NEW |
1 # Python bindings for Yasm: Pyrex input file for intnum.h | 1 # Python bindings for Yasm: Pyrex input file for intnum.h |
2 # | 2 # |
3 # Copyright (C) 2006 Michael Urman, Peter Johnson | 3 # Copyright (C) 2006 Michael Urman, Peter Johnson |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions | 6 # modification, are permitted provided that the following conditions |
7 # are met: | 7 # are met: |
8 # 1. Redistributions of source code must retain the above copyright | 8 # 1. Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # 2. Redistributions in binary form must reproduce the above copyright | 10 # 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 return result | 50 return result |
51 else: | 51 else: |
52 raise NotImplementedError | 52 raise NotImplementedError |
53 | 53 |
54 cdef object __make_intnum(yasm_intnum *intn): | 54 cdef object __make_intnum(yasm_intnum *intn): |
55 return IntNum(__pass_voidp(intn, IntNum)) | 55 return IntNum(__pass_voidp(intn, IntNum)) |
56 | 56 |
57 cdef class IntNum: | 57 cdef class IntNum: |
58 cdef yasm_intnum *intn | 58 cdef yasm_intnum *intn |
59 | 59 |
60 def __new__(self, value, base=None): | 60 def __cinit__(self, value, base=None): |
61 cdef unsigned char buf[16] | 61 cdef unsigned char buf[16] |
62 | 62 |
63 self.intn = NULL | 63 self.intn = NULL |
64 | 64 |
65 if isinstance(value, IntNum): | 65 if isinstance(value, IntNum): |
66 self.intn = yasm_intnum_copy((<IntNum>value).intn) | 66 self.intn = yasm_intnum_copy((<IntNum>value).intn) |
67 return | 67 return |
68 if PyCObject_Check(value): | 68 if PyCObject_Check(value): |
69 self.intn = <yasm_intnum *>__get_voidp(value, IntNum) | 69 self.intn = <yasm_intnum *>__get_voidp(value, IntNum) |
70 return | 70 return |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 def __add__(x, y): return __intnum_op(x, YASM_EXPR_ADD, y) | 109 def __add__(x, y): return __intnum_op(x, YASM_EXPR_ADD, y) |
110 def __sub__(x, y): return __intnum_op(x, YASM_EXPR_SUB, y) | 110 def __sub__(x, y): return __intnum_op(x, YASM_EXPR_SUB, y) |
111 def __mul__(x, y): return __intnum_op(x, YASM_EXPR_MUL, y) | 111 def __mul__(x, y): return __intnum_op(x, YASM_EXPR_MUL, y) |
112 def __div__(x, y): return __intnum_op_ex(x, YASM_EXPR_SIGNDIV, y) | 112 def __div__(x, y): return __intnum_op_ex(x, YASM_EXPR_SIGNDIV, y) |
113 def __floordiv__(x, y): return __intnum_op_ex(x, YASM_EXPR_SIGNDIV, y) | 113 def __floordiv__(x, y): return __intnum_op_ex(x, YASM_EXPR_SIGNDIV, y) |
114 def __mod__(x, y): return __intnum_op_ex(x, YASM_EXPR_SIGNMOD, y) | 114 def __mod__(x, y): return __intnum_op_ex(x, YASM_EXPR_SIGNMOD, y) |
115 def __neg__(self): return __intnum_op(self, YASM_EXPR_NEG, None) | 115 def __neg__(self): return __intnum_op(self, YASM_EXPR_NEG, None) |
116 def __pos__(self): return self | 116 def __pos__(self): return self |
117 def __abs__(self): | 117 def __abs__(self): |
118 if yasm_intnum_sign(self.intn) >= 0: return self | 118 if yasm_intnum_sign(self.intn) >= 0: return IntNum(self) |
119 else: return __intnum_op(self, YASM_EXPR_NEG, None) | 119 else: return __intnum_op(self, YASM_EXPR_NEG, None) |
120 def __nonzero__(self): return not yasm_intnum_is_zero(self.intn) | 120 def __nonzero__(self): return not yasm_intnum_is_zero(self.intn) |
121 def __invert__(self): return __intnum_op(self, YASM_EXPR_NOT, None) | 121 def __invert__(self): return __intnum_op(self, YASM_EXPR_NOT, None) |
122 def __lshift__(x, y): return __intnum_op(x, YASM_EXPR_SHL, y) | 122 def __lshift__(x, y): return __intnum_op(x, YASM_EXPR_SHL, y) |
123 def __rshift__(x, y): return __intnum_op(x, YASM_EXPR_SHR, y) | 123 def __rshift__(x, y): return __intnum_op(x, YASM_EXPR_SHR, y) |
124 def __and__(x, y): return __intnum_op(x, YASM_EXPR_AND, y) | 124 def __and__(x, y): return __intnum_op(x, YASM_EXPR_AND, y) |
125 def __or__(x, y): return __intnum_op(x, YASM_EXPR_OR, y) | 125 def __or__(x, y): return __intnum_op(x, YASM_EXPR_OR, y) |
126 def __xor__(x, y): return __intnum_op(x, YASM_EXPR_XOR, y) | 126 def __xor__(x, y): return __intnum_op(x, YASM_EXPR_XOR, y) |
127 | 127 |
128 cdef object __op(self, yasm_expr_op op, object x): | 128 cdef object __op(self, yasm_expr_op op, object x): |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 cdef yasm_expr_op aop | 161 cdef yasm_expr_op aop |
162 if op == 0: aop = YASM_EXPR_LT | 162 if op == 0: aop = YASM_EXPR_LT |
163 elif op == 1: aop = YASM_EXPR_LE | 163 elif op == 1: aop = YASM_EXPR_LE |
164 elif op == 2: aop = YASM_EXPR_EQ | 164 elif op == 2: aop = YASM_EXPR_EQ |
165 elif op == 3: aop = YASM_EXPR_NE | 165 elif op == 3: aop = YASM_EXPR_NE |
166 elif op == 4: aop = YASM_EXPR_GT | 166 elif op == 4: aop = YASM_EXPR_GT |
167 elif op == 5: aop = YASM_EXPR_GE | 167 elif op == 5: aop = YASM_EXPR_GE |
168 else: raise NotImplementedError | 168 else: raise NotImplementedError |
169 v = __intnum_op(x, aop, y) | 169 v = __intnum_op(x, aop, y) |
170 return bool(not yasm_intnum_is_zero((<IntNum>v).intn)) | 170 return bool(not yasm_intnum_is_zero((<IntNum>v).intn)) |
OLD | NEW |