<s> from pypy . tool . pairtype import pairtype <EOL> from pypy . annotation import model as annmodel <EOL> from pypy . objspace . flow import model as flowmodel <EOL> from pypy . rpython . lltypesystem import lltype <EOL> from pypy . rpython . error import TyperError <EOL> from pypy . rpython . rmodel import Repr , IntegerRepr <EOL> from pypy . rlib . rarithmetic import r_uint <EOL> class __extend__ ( annmodel . SomePtr ) : <EOL> def rtyper_makerepr ( self , rtyper ) : <EOL> return PtrRepr ( self . ll_ptrtype ) <EOL> def rtyper_makekey ( self ) : <EOL> return self . __class__ , self . ll_ptrtype <EOL> class __extend__ ( annmodel . SomeInteriorPtr ) : <EOL> def rtyper_makerepr ( self , rtyper ) : <EOL> return InteriorPtrRepr ( self . ll_ptrtype ) <EOL> class PtrRepr ( Repr ) : <EOL> def __init__ ( self , ptrtype ) : <EOL> assert isinstance ( ptrtype , lltype . Ptr ) <EOL> self . lowleveltype = ptrtype <EOL> def ll_str ( self , p ) : <EOL> from pypy . rpython . lltypesystem . rstr import ll_str <EOL> id = lltype . cast_ptr_to_int ( p ) <EOL> return ll_str . ll_int2hex ( r_uint ( id ) , True ) <EOL> def rtype_getattr ( self , hop ) : <EOL> attr = hop . args_s [ <NUM_LIT:1> ] . const <EOL> if isinstance ( hop . s_result , annmodel . SomeLLADTMeth ) : <EOL> return hop . inputarg ( hop . r_result , arg = <NUM_LIT:0> ) <EOL> FIELD_TYPE = getattr ( self . lowleveltype . TO , attr ) <EOL> if isinstance ( FIELD_TYPE , lltype . ContainerType ) : <EOL> if ( attr , FIELD_TYPE ) == self . lowleveltype . TO . _first_struct ( ) : <EOL> return hop . genop ( '<STR_LIT>' , [ hop . inputarg ( self , <NUM_LIT:0> ) ] , <EOL> resulttype = hop . r_result . lowleveltype ) <EOL> elif isinstance ( hop . r_result , InteriorPtrRepr ) : <EOL> return hop . inputarg ( self , <NUM_LIT:0> ) <EOL> else : <EOL> newopname = '<STR_LIT>' <EOL> else : <EOL> newopname = '<STR_LIT>' <EOL> vlist = hop . inputargs ( self , lltype . Void ) <EOL> return hop . genop ( newopname , vlist , <EOL> resulttype = hop . r_result . lowleveltype ) <EOL> def rtype_setattr ( self , hop ) : <EOL> attr = hop . args_s [ <NUM_LIT:1> ] . const <EOL> FIELD_TYPE = getattr ( self . lowleveltype . TO , attr ) <EOL> assert not isinstance ( FIELD_TYPE , lltype . ContainerType ) <EOL> vlist = hop . inputargs ( self , lltype . Void , hop . args_r [ <NUM_LIT:2> ] ) <EOL> hop . genop ( '<STR_LIT>' , vlist ) <EOL> def rtype_len ( self , hop ) : <EOL> ARRAY = hop . args_r [ <NUM_LIT:0> ] . lowleveltype . TO <EOL> if isinstance ( ARRAY , lltype . FixedSizeArray ) : <EOL> return hop . inputconst ( lltype . Signed , ARRAY . length ) <EOL> else : <EOL> vlist = hop . inputargs ( self ) <EOL> return hop . genop ( '<STR_LIT>' , vlist , <EOL> resulttype = hop . r_result . lowleveltype ) <EOL> def rtype_is_true ( self , hop ) : <EOL> vlist = hop . inputargs ( self ) <EOL> return hop . genop ( '<STR_LIT>' , vlist , resulttype = lltype . Bool ) <EOL> def rtype_simple_call ( self , hop ) : <EOL> if not isinstance ( self . lowleveltype . TO , lltype . FuncType ) : <EOL> raise TyperError ( "<STR_LIT>" , self . lowleveltype . TO ) <EOL> vlist = hop . inputargs ( * hop . args_r ) <EOL> nexpected = len ( self . lowleveltype . TO . ARGS ) <EOL> nactual = len ( vlist ) - <NUM_LIT:1> <EOL> if nactual != nexpected : <EOL> raise TyperError ( "<STR_LIT>" % <EOL> ( nexpected , nactual ) ) <EOL> if isinstance ( vlist [ <NUM_LIT:0> ] , flowmodel . Constant ) : <EOL> if hasattr ( vlist [ <NUM_LIT:0> ] . value , '<STR_LIT>' ) : <EOL> hop . llops . record_extra_call ( vlist [ <NUM_LIT:0> ] . value . graph ) <EOL> opname = '<STR_LIT>' <EOL> else : <EOL> opname = '<STR_LIT>' <EOL> vlist . append ( hop . inputconst ( lltype . Void , None ) ) <EOL> hop . exception_is_here ( ) <EOL> return hop . genop ( opname , vlist , <EOL> resulttype = self . lowleveltype . TO . RESULT ) <EOL> def rtype_call_args ( self , hop ) : <EOL> from pypy . rpython . rbuiltin import call_args_expand <EOL> hop , _ = call_args_expand ( hop , takes_kwds = False ) <EOL> hop . swap_fst_snd_args ( ) <EOL> hop . r_s_popfirstarg ( ) <EOL> return self . rtype_simple_call ( hop ) <EOL> class __extend__ ( pairtype ( PtrRepr , IntegerRepr ) ) : <EOL> def rtype_getitem ( ( r_ptr , r_int ) , hop ) : <EOL> ARRAY = r_ptr . lowleveltype . TO <EOL> ITEM_TYPE = ARRAY . OF <EOL> if isinstance ( ITEM_TYPE , lltype . ContainerType ) : <EOL> if isinstance ( hop . r_result , InteriorPtrRepr ) : <EOL> v_array , v_index = hop . inputargs ( r_ptr , lltype . Signed ) <EOL> INTERIOR_PTR_TYPE = r_ptr . lowleveltype . _interior_ptr_type_with_index ( ITEM_TYPE ) <EOL> cflags = hop . inputconst ( lltype . Void , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> args = [ flowmodel . Constant ( INTERIOR_PTR_TYPE , lltype . Void ) , <EOL> cflags ] <EOL> v_interior_ptr = hop . genop ( '<STR_LIT>' , args , <EOL> resulttype = lltype . Ptr ( INTERIOR_PTR_TYPE ) ) <EOL> hop . genop ( '<STR_LIT>' , <EOL> [ v_interior_ptr , flowmodel . Constant ( '<STR_LIT>' , lltype . Void ) , v_array ] ) <EOL> hop . genop ( '<STR_LIT>' , <EOL> [ v_interior_ptr , flowmodel . Constant ( '<STR_LIT:index>' , lltype . Void ) , v_index ] ) <EOL> return v_interior_ptr <EOL> else : <EOL> newopname = '<STR_LIT>' <EOL> else : <EOL> newopname = '<STR_LIT>' <EOL> vlist = hop . inputargs ( r_ptr , lltype . Signed ) <EOL> return hop . genop ( newopname , vlist , <EOL> resulttype = hop . r_result . lowleveltype ) <EOL> def rtype_setitem ( ( r_ptr , r_int ) , hop ) : <EOL> ARRAY = r_ptr . lowleveltype . TO <EOL> ITEM_TYPE = ARRAY . OF <EOL> assert not isinstance ( ITEM_TYPE , lltype . ContainerType ) <EOL> vlist = hop . inputargs ( r_ptr , lltype . Signed , hop . args_r [ <NUM_LIT:2> ] ) <EOL> hop . genop ( '<STR_LIT>' , vlist ) <EOL> class __extend__ ( pairtype ( PtrRepr , Repr ) ) : <EOL> def rtype_eq ( ( r_ptr , r_any ) , hop ) : <EOL> vlist = hop . inputargs ( r_ptr , r_ptr ) <EOL> return hop . genop ( '<STR_LIT>' , vlist , resulttype = lltype . Bool ) <EOL> def rtype_ne ( ( r_ptr , r_any ) , hop ) : <EOL> vlist = hop . inputargs ( r_ptr , r_ptr ) <EOL> return hop . genop ( '<STR_LIT>' , vlist , resulttype = lltype . Bool ) <EOL> class __extend__ ( pairtype ( Repr , PtrRepr ) ) : <EOL> def rtype_eq ( ( r_any , r_ptr ) , hop ) : <EOL> vlist = hop . inputargs ( r_ptr , r_ptr ) <EOL> return hop . genop ( '<STR_LIT>' , vlist , resulttype = lltype . Bool ) <EOL> def rtype_ne ( ( r_any , r_ptr ) , hop ) : <EOL> vlist = hop . inputargs ( r_ptr , r_ptr ) <EOL> return hop . genop ( '<STR_LIT>' , vlist , resulttype = lltype . Bool ) <EOL> class __extend__ ( annmodel . SomeLLADTMeth ) : <EOL> def rtyper_makerepr ( self , rtyper ) : <EOL> return LLADTMethRepr ( self , rtyper ) <EOL> def rtyper_makekey ( self ) : <EOL> return self . __class__ , self . ll_ptrtype , self . func <EOL> class LLADTMethRepr ( Repr ) : <EOL> def __init__ ( self , adtmeth , rtyper ) : <EOL> self . func = adtmeth . func <EOL> self . lowleveltype = adtmeth . ll_ptrtype <EOL> self . ll_ptrtype = adtmeth . ll_ptrtype <EOL> self . lowleveltype = rtyper . getrepr ( annmodel . lltype_to_annotation ( adtmeth . ll_ptrtype ) ) . lowleveltype <EOL> def rtype_simple_call ( self , hop ) : <EOL> hop2 = hop . copy ( ) <EOL> func = self . func <EOL> s_func = hop . rtyper . annotator . bookkeeper . immutablevalue ( func ) <EOL> v_ptr = hop2 . args_v [ <NUM_LIT:0> ] <EOL> hop2 . r_s_popfirstarg ( ) <EOL> hop2 . v_s_insertfirstarg ( <EOL> v_ptr , annmodel . lltype_to_annotation ( self . ll_ptrtype ) ) <EOL> hop2 . v_s_insertfirstarg ( flowmodel . Constant ( func ) , s_func ) <EOL> return hop2 . dispatch ( ) <EOL> class __extend__ ( pairtype ( PtrRepr , LLADTMethRepr ) ) : <EOL> def convert_from_to ( ( r_from , r_to ) , v , llops ) : <EOL> if r_from . lowleveltype == r_to . lowleveltype : <EOL> return v <EOL> return NotImplemented <EOL> class InteriorPtrRepr ( Repr ) : <EOL> def __init__ ( self , ptrtype ) : <EOL> assert isinstance ( ptrtype , lltype . InteriorPtr ) <EOL> self . v_offsets = [ ] <EOL> numitemoffsets = <NUM_LIT:0> <EOL> for i , offset in enumerate ( ptrtype . offsets ) : <EOL> if isinstance ( offset , int ) : <EOL> numitemoffsets += <NUM_LIT:1> <EOL> self . v_offsets . append ( None ) <EOL> else : <EOL> assert isinstance ( offset , str ) <EOL> self . v_offsets . append ( flowmodel . Constant ( offset , lltype . Void ) ) <EOL> self . parentptrtype = lltype . Ptr ( ptrtype . PARENTTYPE ) <EOL> self . resulttype = lltype . Ptr ( ptrtype . TO ) <EOL> assert numitemoffsets <= <NUM_LIT:1> <EOL> if numitemoffsets > <NUM_LIT:0> : <EOL> self . lowleveltype = lltype . Ptr ( self . parentptrtype . _interior_ptr_type_with_index ( self . resulttype . TO ) ) <EOL> else : <EOL> self . lowleveltype = self . parentptrtype <EOL> def getinteriorfieldargs ( self , hop , v_self ) : <EOL> vlist = [ ] <EOL> if None in self . v_offsets : <EOL> INTERIOR_TYPE = v_self . concretetype . TO <EOL> nameiter = iter ( INTERIOR_TYPE . _names ) <EOL> name = nameiter . next ( ) <EOL> vlist . append ( <EOL> hop . genop ( '<STR_LIT>' , <EOL> [ v_self , flowmodel . Constant ( name , lltype . Void ) ] , <EOL> resulttype = INTERIOR_TYPE . _flds [ name ] ) ) <EOL> else : <EOL> vlist . append ( v_self ) <EOL> for v_offset in self . v_offsets : <EOL> if v_offset is None : <EOL> name = nameiter . next ( ) <EOL> vlist . append ( <EOL> hop . genop ( '<STR_LIT>' , <EOL> [ v_self , flowmodel . Constant ( name , lltype . Void ) ] , <EOL> resulttype = INTERIOR_TYPE . _flds [ name ] ) ) <EOL> else : <EOL> vlist . append ( v_offset ) <EOL> if None in self . v_offsets : <EOL> try : <EOL> nameiter . next ( ) <EOL> except StopIteration : <EOL> pass <EOL> else : <EOL> assert False <EOL> return vlist <EOL> def rtype_len ( self , hop ) : <EOL> v_self , = hop . inputargs ( self ) <EOL> vlist = self . getinteriorfieldargs ( hop , v_self ) <EOL> return hop . genop ( '<STR_LIT>' , vlist , <EOL> resulttype = lltype . Signed ) <EOL> def rtype_getattr ( self , hop ) : <EOL> attr = hop . args_s [ <NUM_LIT:1> ] . const <EOL> if isinstance ( hop . s_result , annmodel . SomeLLADTMeth ) : <EOL> return hop . inputarg ( hop . r_result , arg = <NUM_LIT:0> ) <EOL> FIELD_TYPE = getattr ( self . resulttype . TO , attr ) <EOL> if isinstance ( FIELD_TYPE , lltype . ContainerType ) : <EOL> return hop . inputarg ( self , <NUM_LIT:0> ) <EOL> else : <EOL> v_self , v_attr = hop . inputargs ( self , lltype . Void ) <EOL> vlist = self . getinteriorfieldargs ( hop , v_self ) + [ v_attr ] <EOL> return hop . genop ( '<STR_LIT>' , vlist , <EOL> resulttype = hop . r_result . lowleveltype ) <EOL> def rtype_setattr ( self , hop ) : <EOL> attr = hop . args_s [ <NUM_LIT:1> ] . const <EOL> FIELD_TYPE = getattr ( self . resulttype . TO , attr ) <EOL> assert not isinstance ( FIELD_TYPE , lltype . ContainerType ) <EOL> v_self , v_fieldname , v_value = hop . inputargs ( self , lltype . Void , hop . args_r [ <NUM_LIT:2> ] ) <EOL> vlist = self . getinteriorfieldargs ( hop , v_self ) + [ v_fieldname , v_value ] <EOL> return hop . genop ( '<STR_LIT>' , vlist ) <EOL> class __extend__ ( pairtype ( InteriorPtrRepr , IntegerRepr ) ) : <EOL> def rtype_getitem ( ( r_ptr , r_item ) , hop ) : <EOL> ARRAY = r_ptr . resulttype . TO <EOL> ITEM_TYPE = ARRAY . OF <EOL> if isinstance ( ITEM_TYPE , lltype . ContainerType ) : <EOL> v_array , v_index = hop . inputargs ( r_ptr , lltype . Signed ) <EOL> INTERIOR_PTR_TYPE = r_ptr . lowleveltype . _interior_ptr_type_with_index ( ITEM_TYPE ) <EOL> cflags = hop . inputconst ( lltype . Void , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> args = [ flowmodel . Constant ( INTERIOR_PTR_TYPE , lltype . Void ) , cflags ] <EOL> v_interior_ptr = hop . genop ( '<STR_LIT>' , args , <EOL> resulttype = lltype . Ptr ( INTERIOR_PTR_TYPE ) ) <EOL> hop . genop ( '<STR_LIT>' , <EOL> [ v_interior_ptr , flowmodel . Constant ( '<STR_LIT>' , lltype . Void ) , v_array ] ) <EOL> hop . genop ( '<STR_LIT>' , <EOL> [ v_interior_ptr , flowmodel . Constant ( '<STR_LIT:index>' , lltype . Void ) , v_index ] ) <EOL> return v_interior_ptr <EOL> else : <EOL> v_self , v_index = hop . inputargs ( r_ptr , lltype . Signed ) <EOL> vlist = r_ptr . getinteriorfieldargs ( hop , v_self ) + [ v_index ] <EOL> return hop . genop ( '<STR_LIT>' , vlist , <EOL> resulttype = ITEM_TYPE ) <EOL> def rtype_setitem ( ( r_ptr , r_index ) , hop ) : <EOL> ARRAY = r_ptr . resulttype . TO <EOL> ITEM_TYPE = ARRAY . OF <EOL> assert not isinstance ( ITEM_TYPE , lltype . ContainerType ) <EOL> v_self , v_index , v_value = hop . inputargs ( r_ptr , lltype . Signed , hop . args_r [ <NUM_LIT:2> ] ) <EOL> vlist = r_ptr . getinteriorfieldargs ( hop , v_self ) + [ v_index , v_value ] <EOL> hop . genop ( '<STR_LIT>' , vlist ) <EOL> class __extend__ ( pairtype ( InteriorPtrRepr , LLADTMethRepr ) ) : <EOL> def convert_from_to ( ( r_from , r_to ) , v , llops ) : <EOL> if r_from . lowleveltype == r_to . lowleveltype : <EOL> return v <EOL> return NotImplemented </s>
