<s> from pypy . rpython . rmodel import inputconst <EOL> from pypy . rpython . rtuple import AbstractTupleRepr , AbstractTupleIteratorRepr <EOL> from pypy . rpython . ootypesystem import ootype <EOL> from pypy . rpython . ootypesystem import rstr <EOL> from pypy . rpython . ootypesystem . rtupletype import TUPLE_TYPE <EOL> class TupleRepr ( AbstractTupleRepr ) : <EOL> rstr_ll = rstr . LLHelpers <EOL> def __init__ ( self , rtyper , items_r ) : <EOL> AbstractTupleRepr . __init__ ( self , rtyper , items_r ) <EOL> self . lowleveltype = TUPLE_TYPE ( self . lltypes ) <EOL> def newtuple ( cls , llops , r_tuple , items_v ) : <EOL> if len ( r_tuple . items_r ) == <NUM_LIT:0> : <EOL> return inputconst ( r_tuple , ( ) ) <EOL> c1 = inputconst ( ootype . Void , r_tuple . lowleveltype ) <EOL> v_result = llops . genop ( "<STR_LIT>" , [ c1 ] , resulttype = r_tuple . lowleveltype ) <EOL> for i in range ( len ( r_tuple . items_r ) ) : <EOL> cname = inputconst ( ootype . Void , r_tuple . fieldnames [ i ] ) <EOL> llops . genop ( "<STR_LIT>" , [ v_result , cname , items_v [ i ] ] ) <EOL> return v_result <EOL> newtuple = classmethod ( newtuple ) <EOL> def instantiate ( self ) : <EOL> return ootype . new ( self . lowleveltype ) <EOL> def getitem_internal ( self , llops , v_tuple , index ) : <EOL> name = self . fieldnames [ index ] <EOL> llresult = self . lltypes [ index ] <EOL> cname = inputconst ( ootype . Void , name ) <EOL> return llops . genop ( "<STR_LIT>" , [ v_tuple , cname ] , resulttype = llresult ) <EOL> def rtype_bltn_list ( self , hop ) : <EOL> from pypy . rpython . ootypesystem import rlist <EOL> v_tup = hop . inputarg ( self , <NUM_LIT:0> ) <EOL> RESULT = hop . r_result . lowleveltype <EOL> c_resulttype = inputconst ( ootype . Void , RESULT ) <EOL> c_length = inputconst ( ootype . Signed , len ( self . items_r ) ) <EOL> if isinstance ( RESULT , ootype . Array ) : <EOL> v_list = hop . genop ( '<STR_LIT>' , [ c_resulttype , c_length ] , resulttype = RESULT ) <EOL> else : <EOL> assert isinstance ( RESULT , ootype . List ) <EOL> v_list = hop . genop ( '<STR_LIT>' , [ c_resulttype ] , resulttype = RESULT ) <EOL> c_resize = inputconst ( ootype . Void , '<STR_LIT>' ) <EOL> hop . genop ( '<STR_LIT>' , [ c_resize , v_list , c_length ] , resulttype = ootype . Void ) <EOL> c_setitem = inputconst ( ootype . Void , '<STR_LIT>' ) <EOL> for index in range ( len ( self . items_r ) ) : <EOL> name = self . fieldnames [ index ] <EOL> r_item = self . items_r [ index ] <EOL> c_name = hop . inputconst ( ootype . Void , name ) <EOL> v_item = hop . genop ( "<STR_LIT>" , [ v_tup , c_name ] , resulttype = r_item ) <EOL> v_item = hop . llops . convertvar ( v_item , r_item , hop . r_result . item_repr ) <EOL> c_index = inputconst ( ootype . Signed , index ) <EOL> hop . genop ( '<STR_LIT>' , [ c_setitem , v_list , c_index , v_item ] , resulttype = ootype . Void ) <EOL> return v_list <EOL> def rtype_newtuple ( hop ) : <EOL> return TupleRepr . _rtype_newtuple ( hop ) <EOL> newtuple = TupleRepr . newtuple <EOL> class Length1TupleIteratorRepr ( AbstractTupleIteratorRepr ) : <EOL> def __init__ ( self , r_tuple ) : <EOL> self . r_tuple = r_tuple <EOL> self . lowleveltype = ootype . Record ( <EOL> { "<STR_LIT>" : r_tuple . lowleveltype , "<STR_LIT:index>" : ootype . Signed } ) <EOL> self . ll_tupleiter = ll_tupleiter <EOL> self . ll_tuplenext = ll_tuplenext <EOL> TupleRepr . IteratorRepr = Length1TupleIteratorRepr <EOL> def ll_tupleiter ( ITERINST , tuple ) : <EOL> iter = ootype . new ( ITERINST ) <EOL> iter . iterable = tuple <EOL> return iter <EOL> def ll_tuplenext ( iter ) : <EOL> t = iter . iterable <EOL> if t : <EOL> iter . iterable = ootype . null ( ootype . typeOf ( t ) ) <EOL> return t . item0 <EOL> else : <EOL> raise StopIteration </s>
