OLD | NEW |
1 # Python bindings for Yasm: Pyrex input file for expr.h | 1 # Python bindings for Yasm: Pyrex input file for expr.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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 __op[op] = operation | 52 __op[op] = operation |
53 | 53 |
54 del operator, op, ops, operation | 54 del operator, op, ops, operation |
55 | 55 |
56 cdef object __make_expression(yasm_expr *expr): | 56 cdef object __make_expression(yasm_expr *expr): |
57 return Expression(__pass_voidp(expr, Expression)) | 57 return Expression(__pass_voidp(expr, Expression)) |
58 | 58 |
59 cdef class Expression: | 59 cdef class Expression: |
60 cdef yasm_expr *expr | 60 cdef yasm_expr *expr |
61 | 61 |
62 def __new__(self, op, *args, **kwargs): | 62 def __cinit__(self, op, *args, **kwargs): |
63 self.expr = NULL | 63 self.expr = NULL |
64 | 64 |
65 if isinstance(op, Expression): | 65 if isinstance(op, Expression): |
66 self.expr = yasm_expr_copy((<Expression>op).expr) | 66 self.expr = yasm_expr_copy((<Expression>op).expr) |
67 return | 67 return |
68 if PyCObject_Check(op): | 68 if PyCObject_Check(op): |
69 self.expr = <yasm_expr *>__get_voidp(op, Expression) | 69 self.expr = <yasm_expr *>__get_voidp(op, Expression) |
70 return | 70 return |
71 | 71 |
72 cdef size_t numargs | 72 cdef size_t numargs |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 raise ValueError("not a WRT expression") | 127 raise ValueError("not a WRT expression") |
128 return __make_expression(retval) | 128 return __make_expression(retval) |
129 | 129 |
130 def get_intnum(self, calc_bc_dist=False): | 130 def get_intnum(self, calc_bc_dist=False): |
131 cdef yasm_intnum *retval | 131 cdef yasm_intnum *retval |
132 retval = yasm_expr_get_intnum(&self.expr, calc_bc_dist) | 132 retval = yasm_expr_get_intnum(&self.expr, calc_bc_dist) |
133 if retval == NULL: | 133 if retval == NULL: |
134 raise ValueError("not an intnum expression") | 134 raise ValueError("not an intnum expression") |
135 return __make_intnum(yasm_intnum_copy(retval)) | 135 return __make_intnum(yasm_intnum_copy(retval)) |
136 | 136 |
OLD | NEW |