<s> import py <EOL> from pypy . rpython . lltypesystem . lloperation import LL_OPERATIONS , llop , void <EOL> from pypy . rpython . lltypesystem import lltype , opimpl <EOL> from pypy . rpython . ootypesystem import ootype , ooopimpl <EOL> from pypy . rpython . llinterp import LLFrame <EOL> from pypy . rpython . test . test_llinterp import interpret <EOL> from pypy . rpython import rclass <EOL> LL_INTERP_OPERATIONS = [ name [ <NUM_LIT:3> : ] for name in LLFrame . __dict__ . keys ( ) <EOL> if name . startswith ( '<STR_LIT>' ) ] <EOL> def test_canfold_opimpl_complete ( ) : <EOL> for opname , llop in LL_OPERATIONS . items ( ) : <EOL> assert opname == llop . opname <EOL> if llop . canfold : <EOL> if llop . oo : <EOL> func = ooopimpl . get_op_impl ( opname ) <EOL> else : <EOL> func = opimpl . get_op_impl ( opname ) <EOL> assert callable ( func ) <EOL> def test_llop_fold ( ) : <EOL> assert llop . int_add ( lltype . Signed , <NUM_LIT:10> , <NUM_LIT:2> ) == <NUM_LIT:12> <EOL> assert llop . int_add ( lltype . Signed , - <NUM_LIT:6> , - <NUM_LIT:7> ) == - <NUM_LIT> <EOL> S1 = lltype . GcStruct ( '<STR_LIT>' , ( '<STR_LIT:x>' , lltype . Signed ) , hints = { '<STR_LIT>' : True } ) <EOL> s1 = lltype . malloc ( S1 ) <EOL> s1 . x = <NUM_LIT> <EOL> assert llop . getfield ( lltype . Signed , s1 , '<STR_LIT:x>' ) == <NUM_LIT> <EOL> S2 = lltype . GcStruct ( '<STR_LIT>' , ( '<STR_LIT:x>' , lltype . Signed ) ) <EOL> s2 = lltype . malloc ( S2 ) <EOL> s2 . x = <NUM_LIT> <EOL> py . test . raises ( TypeError , "<STR_LIT>" ) <EOL> def test_llop_interp ( ) : <EOL> from pypy . rpython . annlowlevel import LowLevelAnnotatorPolicy <EOL> def llf ( x , y ) : <EOL> return llop . int_add ( lltype . Signed , x , y ) <EOL> res = interpret ( llf , [ <NUM_LIT:5> , <NUM_LIT:7> ] , policy = LowLevelAnnotatorPolicy ( ) ) <EOL> assert res == <NUM_LIT:12> <EOL> def test_llop_with_voids_interp ( ) : <EOL> from pypy . rpython . annlowlevel import LowLevelAnnotatorPolicy <EOL> S = lltype . GcStruct ( '<STR_LIT:S>' , ( '<STR_LIT:x>' , lltype . Signed ) , ( '<STR_LIT:y>' , lltype . Signed ) ) <EOL> name_y = void ( '<STR_LIT:y>' ) <EOL> def llf ( ) : <EOL> s = lltype . malloc ( S ) <EOL> llop . bare_setfield ( lltype . Void , s , void ( '<STR_LIT:x>' ) , <NUM_LIT:3> ) <EOL> llop . bare_setfield ( lltype . Void , s , name_y , <NUM_LIT:2> ) <EOL> return s . x + s . y <EOL> res = interpret ( llf , [ ] , policy = LowLevelAnnotatorPolicy ( ) ) <EOL> assert res == <NUM_LIT:5> <EOL> def test_is_pure ( ) : <EOL> from pypy . objspace . flow . model import Variable , Constant <EOL> assert llop . bool_not . is_pure ( [ Variable ( ) ] ) <EOL> assert llop . debug_assert . is_pure ( [ Variable ( ) ] ) <EOL> assert not llop . int_add_ovf . is_pure ( [ Variable ( ) , Variable ( ) ] ) <EOL> S1 = lltype . GcStruct ( '<STR_LIT:S>' , ( '<STR_LIT:x>' , lltype . Signed ) , ( '<STR_LIT:y>' , lltype . Signed ) ) <EOL> v_s1 = Variable ( ) <EOL> v_s1 . concretetype = lltype . Ptr ( S1 ) <EOL> assert not llop . setfield . is_pure ( [ v_s1 , Constant ( '<STR_LIT:x>' ) , Variable ( ) ] ) <EOL> assert not llop . getfield . is_pure ( [ v_s1 , Constant ( '<STR_LIT:y>' ) ] ) <EOL> A1 = lltype . GcArray ( lltype . Signed ) <EOL> v_a1 = Variable ( ) <EOL> v_a1 . concretetype = lltype . Ptr ( A1 ) <EOL> assert not llop . setarrayitem . is_pure ( [ v_a1 , Variable ( ) , Variable ( ) ] ) <EOL> assert not llop . getarrayitem . is_pure ( [ v_a1 , Variable ( ) ] ) <EOL> assert llop . getarraysize . is_pure ( [ v_a1 ] ) <EOL> S2 = lltype . GcStruct ( '<STR_LIT:S>' , ( '<STR_LIT:x>' , lltype . Signed ) , ( '<STR_LIT:y>' , lltype . Signed ) , <EOL> hints = { '<STR_LIT>' : True } ) <EOL> v_s2 = Variable ( ) <EOL> v_s2 . concretetype = lltype . Ptr ( S2 ) <EOL> assert not llop . setfield . is_pure ( [ v_s2 , Constant ( '<STR_LIT:x>' ) , Variable ( ) ] ) <EOL> assert llop . getfield . is_pure ( [ v_s2 , Constant ( '<STR_LIT:y>' ) ] ) <EOL> A2 = lltype . GcArray ( lltype . Signed , hints = { '<STR_LIT>' : True } ) <EOL> v_a2 = Variable ( ) <EOL> v_a2 . concretetype = lltype . Ptr ( A2 ) <EOL> assert not llop . setarrayitem . is_pure ( [ v_a2 , Variable ( ) , Variable ( ) ] ) <EOL> assert llop . getarrayitem . is_pure ( [ v_a2 , Variable ( ) ] ) <EOL> assert llop . getarraysize . is_pure ( [ v_a2 ] ) <EOL> accessor = rclass . FieldListAccessor ( ) <EOL> S3 = lltype . GcStruct ( '<STR_LIT:S>' , ( '<STR_LIT:x>' , lltype . Signed ) , ( '<STR_LIT:y>' , lltype . Signed ) , <EOL> hints = { '<STR_LIT>' : accessor } ) <EOL> accessor . initialize ( S3 , [ '<STR_LIT:x>' ] ) <EOL> v_s3 = Variable ( ) <EOL> v_s3 . concretetype = lltype . Ptr ( S3 ) <EOL> assert not llop . setfield . is_pure ( [ v_s3 , Constant ( '<STR_LIT:x>' ) , Variable ( ) ] ) <EOL> assert not llop . setfield . is_pure ( [ v_s3 , Constant ( '<STR_LIT:y>' ) , Variable ( ) ] ) <EOL> assert llop . getfield . is_pure ( [ v_s3 , Constant ( '<STR_LIT:x>' ) ] ) <EOL> assert not llop . getfield . is_pure ( [ v_s3 , Constant ( '<STR_LIT:y>' ) ] ) <EOL> def test_getfield_pure ( ) : <EOL> S1 = lltype . GcStruct ( '<STR_LIT:S>' , ( '<STR_LIT:x>' , lltype . Signed ) , ( '<STR_LIT:y>' , lltype . Signed ) ) <EOL> S2 = lltype . GcStruct ( '<STR_LIT:S>' , ( '<STR_LIT:x>' , lltype . Signed ) , ( '<STR_LIT:y>' , lltype . Signed ) , <EOL> hints = { '<STR_LIT>' : True } ) <EOL> accessor = rclass . FieldListAccessor ( ) <EOL> S3 = lltype . GcStruct ( '<STR_LIT:S>' , ( '<STR_LIT:x>' , lltype . Signed ) , ( '<STR_LIT:y>' , lltype . Signed ) , <EOL> hints = { '<STR_LIT>' : accessor } ) <EOL> accessor . initialize ( S3 , [ '<STR_LIT:x>' ] ) <EOL> s1 = lltype . malloc ( S1 ) ; s1 . x = <NUM_LIT> <EOL> py . test . raises ( TypeError , llop . getfield , lltype . Signed , s1 , '<STR_LIT:x>' ) <EOL> s2 = lltype . malloc ( S2 ) ; s2 . x = <NUM_LIT> <EOL> assert llop . getfield ( lltype . Signed , s2 , '<STR_LIT:x>' ) == <NUM_LIT> <EOL> s3 = lltype . malloc ( S3 ) ; s3 . x = <NUM_LIT> ; s3 . y = <NUM_LIT> <EOL> assert llop . getfield ( lltype . Signed , s3 , '<STR_LIT:x>' ) == <NUM_LIT> <EOL> py . test . raises ( TypeError , llop . getfield , lltype . Signed , s3 , '<STR_LIT:y>' ) <EOL> py . test . raises ( TypeError , llop . getinteriorfield , lltype . Signed , s1 , '<STR_LIT:x>' ) <EOL> assert llop . getinteriorfield ( lltype . Signed , s2 , '<STR_LIT:x>' ) == <NUM_LIT> <EOL> assert llop . getinteriorfield ( lltype . Signed , s3 , '<STR_LIT:x>' ) == <NUM_LIT> <EOL> py . test . raises ( TypeError , llop . getinteriorfield , lltype . Signed , s3 , '<STR_LIT:y>' ) <EOL> def test_table_complete ( ) : <EOL> for opname in LL_INTERP_OPERATIONS : <EOL> assert opname in LL_OPERATIONS <EOL> def test_llinterp_complete ( ) : <EOL> for opname , llop in LL_OPERATIONS . items ( ) : <EOL> if llop . canfold : <EOL> continue <EOL> if opname . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> assert opname in LL_INTERP_OPERATIONS </s>
