<s> from pypy . translator . c . test . test_typed import CompilationTestCase <EOL> from pypy . translator . tool . staticsizereport import group_static_size , guess_size <EOL> from pypy . rpython . lltypesystem import llmemory , lltype , rffi <EOL> class TestStaticSizeReport ( CompilationTestCase ) : <EOL> def test_simple ( self ) : <EOL> class A : <EOL> def __init__ ( self , n ) : <EOL> if n : <EOL> self . next = A ( n - <NUM_LIT:1> ) <EOL> else : <EOL> self . next = None <EOL> self . key = repr ( self ) <EOL> a = A ( <NUM_LIT:100> ) <EOL> def f ( x ) : <EOL> if x : <EOL> return a . key <EOL> return a . next . key <EOL> func = self . getcompiled ( f , [ int ] ) <EOL> size , num = group_static_size ( self . builder . db , self . builder . db . globalcontainers ( ) ) <EOL> for key , value in num . iteritems ( ) : <EOL> if "<STR_LIT>" in str ( key ) and "<STR_LIT>" not in str ( key ) : <EOL> assert value == <NUM_LIT> <EOL> def test_large_dict ( self ) : <EOL> d = { } <EOL> d_small = { <NUM_LIT:1> : <NUM_LIT:2> } <EOL> fixlist = [ x for x in range ( <NUM_LIT:100> ) ] <EOL> dynlist = [ x for x in range ( <NUM_LIT:100> ) ] <EOL> test_dict = dict ( map ( lambda x : ( x , hex ( x ) ) , range ( <NUM_LIT> , <NUM_LIT> ) ) ) <EOL> reverse_dict = dict ( map ( lambda ( x , y ) : ( y , x ) , test_dict . items ( ) ) ) <EOL> class wrap : <EOL> pass <EOL> for x in xrange ( <NUM_LIT:100> ) : <EOL> i = wrap ( ) <EOL> i . x = x <EOL> d [ x ] = i <EOL> def f ( x ) : <EOL> if x > <NUM_LIT> : <EOL> dynlist . append ( x ) <EOL> return d [ x ] . x + fixlist [ x ] + d_small [ x ] + reverse_dict [ test_dict [ x ] ] <EOL> func = self . getcompiled ( f , [ int ] ) <EOL> db = self . builder . db <EOL> gcontainers = list ( db . globalcontainers ( ) ) <EOL> t = db . translator <EOL> rtyper = t . rtyper <EOL> get_container = lambda x : rtyper . getrepr ( t . annotator . bookkeeper . immutablevalue ( x ) ) . convert_const ( x ) . _obj <EOL> dictvalnode = db . getcontainernode ( get_container ( d ) ) <EOL> dictvalnode2 = db . getcontainernode ( get_container ( d_small ) ) <EOL> fixarrayvalnode = db . getcontainernode ( get_container ( fixlist ) ) <EOL> dynarrayvalnode = db . getcontainernode ( get_container ( dynlist ) ) <EOL> test_dictnode = db . getcontainernode ( get_container ( test_dict ) ) <EOL> reverse_dictnode = db . getcontainernode ( get_container ( reverse_dict ) ) <EOL> S = rffi . sizeof ( lltype . Signed ) <EOL> P = rffi . sizeof ( rffi . VOIDP ) <EOL> B = <NUM_LIT:1> <EOL> assert guess_size ( self . builder . db , dictvalnode , set ( ) ) > <NUM_LIT:100> <EOL> assert guess_size ( self . builder . db , dictvalnode2 , set ( ) ) == <NUM_LIT:2> * S + <NUM_LIT:1> * P + <NUM_LIT:1> * S + <NUM_LIT:8> * ( <NUM_LIT:2> * S + <NUM_LIT:1> * B ) <EOL> r_set = set ( ) <EOL> dictnode_size = guess_size ( db , test_dictnode , r_set ) <EOL> assert dictnode_size == <NUM_LIT:2> * S + <NUM_LIT:1> * P + <NUM_LIT:1> * S + ( <NUM_LIT> - <NUM_LIT> ) * ( <NUM_LIT:1> * S + <NUM_LIT:1> * P + ( <NUM_LIT:1> * S + <NUM_LIT:1> * P + <NUM_LIT:5> ) ) + ( <NUM_LIT> - <NUM_LIT> + <NUM_LIT> ) * ( <NUM_LIT:1> * S + <NUM_LIT:1> * P ) <EOL> assert guess_size ( self . builder . db , fixarrayvalnode , set ( ) ) == <NUM_LIT:100> * rffi . sizeof ( lltype . Signed ) + <NUM_LIT:1> * rffi . sizeof ( lltype . Signed ) <EOL> assert guess_size ( self . builder . db , dynarrayvalnode , set ( ) ) == <NUM_LIT:100> * rffi . sizeof ( lltype . Signed ) + <NUM_LIT:2> * rffi . sizeof ( lltype . Signed ) + <NUM_LIT:1> * rffi . sizeof ( rffi . VOIDP ) </s>
