<s> from pypy . tool . pairtype import pairtype <EOL> from pypy . annotation import model as annmodel <EOL> from pypy . rpython . lltypesystem . lltype import PyObject , Ptr , Void , pyobjectptr , nullptr , Bool <EOL> from pypy . rpython . rmodel import Repr , VoidRepr , inputconst <EOL> from pypy . rpython import rclass <EOL> from pypy . tool . sourcetools import func_with_new_name <EOL> class __extend__ ( annmodel . SomeObject ) : <EOL> def rtyper_makerepr ( self , rtyper ) : <EOL> kind = getkind ( self ) <EOL> if kind == "<STR_LIT:type>" : <EOL> return rclass . get_type_repr ( rtyper ) <EOL> elif kind == "<STR_LIT>" : <EOL> return constpyobj_repr <EOL> else : <EOL> return pyobj_repr <EOL> def rtyper_makekey ( self ) : <EOL> return self . __class__ , getkind ( self ) <EOL> def getkind ( s_obj ) : <EOL> if s_obj . is_constant ( ) : <EOL> if getattr ( s_obj . const , '<STR_LIT>' , None ) == '<STR_LIT>' : <EOL> return "<STR_LIT>" <EOL> if s_obj . knowntype is type : <EOL> return "<STR_LIT:type>" <EOL> if s_obj . is_constant ( ) : <EOL> return "<STR_LIT>" <EOL> return "<STR_LIT>" <EOL> class PyObjRepr ( Repr ) : <EOL> def convert_const ( self , value ) : <EOL> return pyobjectptr ( value ) <EOL> def make_iterator_repr ( self ) : <EOL> return pyobj_repr <EOL> pyobj_repr = PyObjRepr ( ) <EOL> pyobj_repr . lowleveltype = Ptr ( PyObject ) <EOL> constpyobj_repr = PyObjRepr ( ) <EOL> constpyobj_repr . lowleveltype = Void <EOL> class __extend__ ( pairtype ( VoidRepr , PyObjRepr ) ) : <EOL> def convert_from_to ( _ , v , llops ) : <EOL> return inputconst ( Ptr ( PyObject ) , nullptr ( PyObject ) ) <EOL> def make_operation ( opname , cls = PyObjRepr ) : <EOL> def rtype_op ( _ , hop ) : <EOL> vlist = hop . inputargs ( * ( [ pyobj_repr ] * hop . nb_args ) ) <EOL> hop . exception_is_here ( ) <EOL> v = hop . genop ( opname , vlist , resulttype = pyobj_repr ) <EOL> if not isinstance ( hop . r_result , VoidRepr ) : <EOL> return hop . llops . convertvar ( v , pyobj_repr , hop . r_result ) <EOL> funcname = '<STR_LIT>' + opname <EOL> func = func_with_new_name ( rtype_op , funcname ) <EOL> assert funcname not in cls . __dict__ <EOL> setattr ( cls , funcname , func ) <EOL> for opname in annmodel . UNARY_OPERATIONS : <EOL> make_operation ( opname ) <EOL> for opname in annmodel . BINARY_OPERATIONS : <EOL> make_operation ( opname , pairtype ( PyObjRepr , Repr ) ) <EOL> make_operation ( opname , pairtype ( Repr , PyObjRepr ) ) <EOL> class __extend__ ( pairtype ( PyObjRepr , PyObjRepr ) ) : <EOL> def rtype_contains ( ( r_seq , r_item ) , hop ) : <EOL> v_seq , v_item = hop . inputargs ( r_seq , r_item ) <EOL> return hop . llops . gencapicall ( '<STR_LIT>' , <EOL> [ v_seq , v_item ] , resulttype = Bool ) </s>
