| 1 | |
| 2 | """ simple non-constant constant. Ie constant which does not get annotated as constant |
| 3 | """ |
| 4 | |
| 5 | from rpython.rtyper.extregistry import ExtRegistryEntry |
| 6 | from rpython.flowspace.model import Constant |
| 7 | from rpython.annotator.model import not_const |
| 8 | |
| 9 | class NonConstant(object): |
| 10 | def __init__(self, _constant): |
| 11 | self.__dict__['constant'] = _constant |
| 12 | |
| 13 | def __getattr__(self, attr): |
| 14 | return getattr(self.__dict__['constant'], attr) |
| 15 | |
| 16 | def __setattr__(self, attr, value): |
| 17 | setattr(self.__dict__['constant'], attr, value) |
| 18 | |
| 19 | def __nonzero__(self): |
| 20 | return bool(self.__dict__['constant']) |
| 21 | |
| 22 | def __eq__(self, other): |
| 23 | return self.__dict__['constant'] == other |
| 24 | |
| 25 | def __add__(self, other): |
| 26 | return self.__dict__['constant'] + other |
| 27 | |
| 28 | def __radd__(self, other): |
| 29 | return other + self.__dict__['constant'] |
| 30 | |
| 31 | def __mul__(self, other): |
| 32 | return self.__dict__['constant'] * other |
| 33 | |
| 34 | class EntryNonConstant(ExtRegistryEntry): |
| 35 | _about_ = NonConstant |
| 36 | |
| 37 | def compute_result_annotation(self, s_arg): |
| 38 | return not_const(s_arg) |
| 39 | |
| 40 | def specialize_call(self, hop): |
| 41 | hop.exception_cannot_occur() |
| 42 | return hop.inputarg(hop.r_result, arg=0) |