<s> from pypy . rpython . ootypesystem import ootype <EOL> class A : <EOL> pass <EOL> class BaseTestConstant : <EOL> def test_char ( self ) : <EOL> const = '<STR_LIT:a>' <EOL> def fn ( ) : <EOL> return const <EOL> assert self . interpret ( fn , [ ] ) == '<STR_LIT:a>' <EOL> def test_void ( self ) : <EOL> def fn ( ) : <EOL> pass <EOL> assert self . interpret ( fn , [ ] ) is None <EOL> def test_tuple ( self ) : <EOL> const = <NUM_LIT:1> , <NUM_LIT:2> <EOL> def fn ( ) : <EOL> return const <EOL> res = self . interpret ( fn , [ ] ) <EOL> assert res . item0 == <NUM_LIT:1> <EOL> assert res . item1 == <NUM_LIT:2> <EOL> def test_tuples_of_different_types ( self ) : <EOL> const = "<STR_LIT:1>" , "<STR_LIT:2>" <EOL> def fn ( ) : <EOL> return const <EOL> res = self . interpret ( fn , [ ] ) <EOL> assert res . item0 == "<STR_LIT:1>" <EOL> assert res . item1 == "<STR_LIT:2>" <EOL> def test_list ( self ) : <EOL> const = [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> def fn ( ) : <EOL> return const <EOL> res = self . ll_to_list ( self . interpret ( fn , [ ] ) ) <EOL> assert res == [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> def test_compound_const ( self ) : <EOL> const = ( [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> def fn ( ) : <EOL> return const <EOL> res = self . interpret ( fn , [ ] ) <EOL> assert self . ll_to_list ( res . item0 ) == [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> assert self . ll_to_list ( res . item1 ) == [ <NUM_LIT:3> , <NUM_LIT:4> ] <EOL> def test_instance ( self ) : <EOL> const = A ( ) <EOL> def fn ( ) : <EOL> return const <EOL> res = self . interpret ( fn , [ ] ) <EOL> assert self . class_name ( res ) == '<STR_LIT:A>' <EOL> def test_list_of_zeroes ( self ) : <EOL> const = [ <NUM_LIT:0> ] * <NUM_LIT:10> <EOL> def fn ( ) : <EOL> return const <EOL> res = self . ll_to_list ( self . interpret ( fn , [ ] ) ) <EOL> assert res == const <EOL> def test_list_of_instances ( self ) : <EOL> const = [ A ( ) ] <EOL> def fn ( ) : <EOL> return const <EOL> res = self . ll_to_list ( self . interpret ( fn , [ ] ) ) <EOL> assert self . class_name ( res [ <NUM_LIT:0> ] ) == '<STR_LIT:A>' <EOL> def test_mix_string_and_char ( self ) : <EOL> def fn ( x ) : <EOL> if x < <NUM_LIT:0> : <EOL> return '<STR_LIT:a>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> assert self . ll_to_string ( self . interpret ( fn , [ - <NUM_LIT:1> ] ) ) == '<STR_LIT:a>' <EOL> assert self . ll_to_string ( self . interpret ( fn , [ <NUM_LIT:0> ] ) ) == '<STR_LIT>' <EOL> def test_string_literal ( self ) : <EOL> def fn ( ) : <EOL> return '<STR_LIT>' <EOL> assert self . ll_to_string ( self . interpret ( fn , [ ] ) ) == '<STR_LIT>' <EOL> def test_string_literal2 ( self ) : <EOL> literals = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def fn ( i ) : <EOL> s = literals [ i ] <EOL> return len ( s ) , ord ( s [ <NUM_LIT:0> ] ) + ord ( s [ <NUM_LIT:1> ] ) + ord ( s [ <NUM_LIT:2> ] ) <EOL> res = self . interpret ( fn , [ <NUM_LIT:0> ] ) <EOL> assert res . item0 == <NUM_LIT:3> <EOL> assert res . item1 == <NUM_LIT:6> <EOL> res = self . interpret ( fn , [ <NUM_LIT:1> ] ) <EOL> assert res . item0 == <NUM_LIT:3> <EOL> assert res . item1 == <NUM_LIT:15> <EOL> def test_float_special ( self ) : <EOL> self . _skip_win ( '<STR_LIT>' ) <EOL> self . _skip_powerpc ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> c = [ float ( "<STR_LIT>" ) , float ( "<STR_LIT>" ) ] <EOL> def fn ( i ) : <EOL> return c [ i ] * <NUM_LIT:2> == c [ i ] <EOL> def fn2 ( i ) : <EOL> return c [ i ] != c [ i ] <EOL> assert self . interpret ( fn , [ <NUM_LIT:0> ] ) == True <EOL> assert self . interpret ( fn2 , [ <NUM_LIT:1> ] ) == True <EOL> def test_customdict_circular ( self ) : <EOL> from pypy . rlib . objectmodel import r_dict <EOL> def key_eq ( a , b ) : <EOL> return a . x [ <NUM_LIT:0> ] == b . x [ <NUM_LIT:0> ] <EOL> def key_hash ( a ) : <EOL> return ord ( a . x [ <NUM_LIT:0> ] ) <EOL> class A : <EOL> def __init__ ( self , x ) : <EOL> self . x = x <EOL> a = A ( '<STR_LIT:foo>' ) <EOL> a . dict = r_dict ( key_eq , key_hash ) <EOL> a . dict [ a ] = <NUM_LIT> <EOL> def fn ( b ) : <EOL> if b : <EOL> s = A ( '<STR_LIT:foo>' ) <EOL> else : <EOL> s = A ( '<STR_LIT:bar>' ) <EOL> return a . dict [ s ] <EOL> assert self . interpret ( fn , [ True ] ) == <NUM_LIT> <EOL> def test_multiple_step ( self ) : <EOL> from pypy . translator . oosupport import constant <EOL> constant . MAX_CONST_PER_STEP = <NUM_LIT:2> <EOL> c1 = [ <NUM_LIT:1> ] <EOL> c2 = [ <NUM_LIT:2> ] <EOL> def fn ( x , y ) : <EOL> return c1 [ x ] + c2 [ y ] <EOL> assert self . interpret ( fn , [ <NUM_LIT:0> , <NUM_LIT:0> ] ) == <NUM_LIT:3> <EOL> def test_many_constants ( self ) : <EOL> N = <NUM_LIT> <EOL> class A : <EOL> pass <EOL> mylist = [ A ( ) for i in range ( N ) ] <EOL> def fn ( x ) : <EOL> return mylist [ x ] <EOL> res = self . interpret ( fn , [ <NUM_LIT:0> ] ) <EOL> assert self . class_name ( res ) == '<STR_LIT:A>' <EOL> def test_convert_string_to_object ( self ) : <EOL> s = self . string_to_ll ( "<STR_LIT>" ) <EOL> obj = ootype . cast_to_object ( s ) <EOL> def fn ( ) : <EOL> s1 = ootype . cast_from_object ( ootype . String , obj ) <EOL> return s1 <EOL> res = self . interpret ( fn , [ ] , backendopt = False ) <EOL> assert res == '<STR_LIT>' <EOL> def test_unwrap_object ( self ) : <EOL> A = ootype . Instance ( "<STR_LIT:A>" , ootype . ROOT , { } ) <EOL> a1 = ootype . new ( A ) <EOL> a2 = ootype . new ( A ) <EOL> obj1 = ootype . cast_to_object ( a1 ) <EOL> obj2 = ootype . cast_to_object ( a2 ) <EOL> def fn ( flag ) : <EOL> if flag : <EOL> obj = obj1 <EOL> else : <EOL> obj = obj2 <EOL> a3 = ootype . cast_from_object ( A , obj ) <EOL> return a3 is a1 <EOL> res = self . interpret ( fn , [ True ] , backendopt = False ) <EOL> assert res is True </s>
