<s> from pypy . rpython . lltypesystem import lltype , rffi <EOL> from pypy . jit . backend . llsupport . descr import * <EOL> from pypy . jit . backend . llsupport import symbolic <EOL> from pypy . rlib . objectmodel import Symbolic <EOL> def test_get_size_descr ( ) : <EOL> c0 = GcCache ( False ) <EOL> c1 = GcCache ( True ) <EOL> T = lltype . GcStruct ( '<STR_LIT:T>' ) <EOL> S = lltype . GcStruct ( '<STR_LIT:S>' , ( '<STR_LIT:x>' , lltype . Char ) , <EOL> ( '<STR_LIT:y>' , lltype . Ptr ( T ) ) ) <EOL> descr_s = get_size_descr ( c0 , S ) <EOL> descr_t = get_size_descr ( c0 , T ) <EOL> assert descr_s . size == symbolic . get_size ( S , False ) <EOL> assert descr_t . size == symbolic . get_size ( T , False ) <EOL> assert descr_s == get_size_descr ( c0 , S ) <EOL> assert descr_s != get_size_descr ( c1 , S ) <EOL> descr_s = get_size_descr ( c1 , S ) <EOL> assert isinstance ( descr_s . size , Symbolic ) <EOL> def test_get_field_descr ( ) : <EOL> U = lltype . Struct ( '<STR_LIT>' ) <EOL> T = lltype . GcStruct ( '<STR_LIT:T>' ) <EOL> S = lltype . GcStruct ( '<STR_LIT:S>' , ( '<STR_LIT:x>' , lltype . Char ) , <EOL> ( '<STR_LIT:y>' , lltype . Ptr ( T ) ) , <EOL> ( '<STR_LIT:z>' , lltype . Ptr ( U ) ) , <EOL> ( '<STR_LIT:f>' , lltype . Float ) ) <EOL> assert getFieldDescrClass ( lltype . Ptr ( T ) ) is GcPtrFieldDescr <EOL> assert getFieldDescrClass ( lltype . Ptr ( U ) ) is NonGcPtrFieldDescr <EOL> cls = getFieldDescrClass ( lltype . Char ) <EOL> assert cls != getFieldDescrClass ( lltype . Signed ) <EOL> assert cls == getFieldDescrClass ( lltype . Char ) <EOL> clsf = getFieldDescrClass ( lltype . Float ) <EOL> assert clsf != cls <EOL> assert clsf == getFieldDescrClass ( lltype . Float ) <EOL> c0 = GcCache ( False ) <EOL> c1 = GcCache ( True ) <EOL> assert get_field_descr ( c0 , S , '<STR_LIT:y>' ) == get_field_descr ( c0 , S , '<STR_LIT:y>' ) <EOL> assert get_field_descr ( c0 , S , '<STR_LIT:y>' ) != get_field_descr ( c1 , S , '<STR_LIT:y>' ) <EOL> for tsc in [ False , True ] : <EOL> c2 = GcCache ( tsc ) <EOL> descr_x = get_field_descr ( c2 , S , '<STR_LIT:x>' ) <EOL> descr_y = get_field_descr ( c2 , S , '<STR_LIT:y>' ) <EOL> descr_z = get_field_descr ( c2 , S , '<STR_LIT:z>' ) <EOL> descr_f = get_field_descr ( c2 , S , '<STR_LIT:f>' ) <EOL> assert descr_x . __class__ is cls <EOL> assert descr_y . __class__ is GcPtrFieldDescr <EOL> assert descr_z . __class__ is NonGcPtrFieldDescr <EOL> assert descr_f . __class__ is clsf <EOL> if not tsc : <EOL> assert descr_x . offset < descr_y . offset < descr_z . offset <EOL> assert descr_x . sort_key ( ) < descr_y . sort_key ( ) < descr_z . sort_key ( ) <EOL> assert descr_x . get_field_size ( False ) == rffi . sizeof ( lltype . Char ) <EOL> assert descr_y . get_field_size ( False ) == rffi . sizeof ( lltype . Ptr ( T ) ) <EOL> assert descr_z . get_field_size ( False ) == rffi . sizeof ( lltype . Ptr ( U ) ) <EOL> assert descr_f . get_field_size ( False ) == rffi . sizeof ( lltype . Float ) <EOL> else : <EOL> assert isinstance ( descr_x . offset , Symbolic ) <EOL> assert isinstance ( descr_y . offset , Symbolic ) <EOL> assert isinstance ( descr_z . offset , Symbolic ) <EOL> assert isinstance ( descr_f . offset , Symbolic ) <EOL> assert isinstance ( descr_x . get_field_size ( True ) , Symbolic ) <EOL> assert isinstance ( descr_y . get_field_size ( True ) , Symbolic ) <EOL> assert isinstance ( descr_z . get_field_size ( True ) , Symbolic ) <EOL> assert isinstance ( descr_f . get_field_size ( True ) , Symbolic ) <EOL> assert not descr_x . is_pointer_field ( ) <EOL> assert descr_y . is_pointer_field ( ) <EOL> assert not descr_z . is_pointer_field ( ) <EOL> assert not descr_f . is_pointer_field ( ) <EOL> assert not descr_x . is_float_field ( ) <EOL> assert not descr_y . is_float_field ( ) <EOL> assert not descr_z . is_float_field ( ) <EOL> assert descr_f . is_float_field ( ) <EOL> def test_get_array_descr ( ) : <EOL> U = lltype . Struct ( '<STR_LIT>' ) <EOL> T = lltype . GcStruct ( '<STR_LIT:T>' ) <EOL> A1 = lltype . GcArray ( lltype . Char ) <EOL> A2 = lltype . GcArray ( lltype . Ptr ( T ) ) <EOL> A3 = lltype . GcArray ( lltype . Ptr ( U ) ) <EOL> A4 = lltype . GcArray ( lltype . Float ) <EOL> assert getArrayDescrClass ( A2 ) is GcPtrArrayDescr <EOL> assert getArrayDescrClass ( A3 ) is NonGcPtrArrayDescr <EOL> cls = getArrayDescrClass ( A1 ) <EOL> assert cls != getArrayDescrClass ( lltype . GcArray ( lltype . Signed ) ) <EOL> assert cls == getArrayDescrClass ( lltype . GcArray ( lltype . Char ) ) <EOL> clsf = getArrayDescrClass ( A4 ) <EOL> assert clsf != cls <EOL> assert clsf == getArrayDescrClass ( lltype . GcArray ( lltype . Float ) ) <EOL> c0 = GcCache ( False ) <EOL> descr1 = get_array_descr ( c0 , A1 ) <EOL> descr2 = get_array_descr ( c0 , A2 ) <EOL> descr3 = get_array_descr ( c0 , A3 ) <EOL> descr4 = get_array_descr ( c0 , A4 ) <EOL> assert descr1 . __class__ is cls <EOL> assert descr2 . __class__ is GcPtrArrayDescr <EOL> assert descr3 . __class__ is NonGcPtrArrayDescr <EOL> assert descr4 . __class__ is clsf <EOL> assert descr1 == get_array_descr ( c0 , lltype . GcArray ( lltype . Char ) ) <EOL> assert not descr1 . is_array_of_pointers ( ) <EOL> assert descr2 . is_array_of_pointers ( ) <EOL> assert not descr3 . is_array_of_pointers ( ) <EOL> assert not descr4 . is_array_of_pointers ( ) <EOL> assert not descr1 . is_array_of_floats ( ) <EOL> assert not descr2 . is_array_of_floats ( ) <EOL> assert not descr3 . is_array_of_floats ( ) <EOL> assert descr4 . is_array_of_floats ( ) <EOL> WORD = rffi . sizeof ( lltype . Signed ) <EOL> assert descr1 . get_base_size ( False ) == WORD <EOL> assert descr2 . get_base_size ( False ) == WORD <EOL> assert descr3 . get_base_size ( False ) == WORD <EOL> assert descr4 . get_base_size ( False ) == WORD <EOL> assert descr1 . get_ofs_length ( False ) == <NUM_LIT:0> <EOL> assert descr2 . get_ofs_length ( False ) == <NUM_LIT:0> <EOL> assert descr3 . get_ofs_length ( False ) == <NUM_LIT:0> <EOL> assert descr4 . get_ofs_length ( False ) == <NUM_LIT:0> <EOL> assert descr1 . get_item_size ( False ) == rffi . sizeof ( lltype . Char ) <EOL> assert descr2 . get_item_size ( False ) == rffi . sizeof ( lltype . Ptr ( T ) ) <EOL> assert descr3 . get_item_size ( False ) == rffi . sizeof ( lltype . Ptr ( U ) ) <EOL> assert descr4 . get_item_size ( False ) == rffi . sizeof ( lltype . Float ) <EOL> assert isinstance ( descr1 . get_base_size ( True ) , Symbolic ) <EOL> assert isinstance ( descr2 . get_base_size ( True ) , Symbolic ) <EOL> assert isinstance ( descr3 . get_base_size ( True ) , Symbolic ) <EOL> assert isinstance ( descr4 . get_base_size ( True ) , Symbolic ) <EOL> assert isinstance ( descr1 . get_ofs_length ( True ) , Symbolic ) <EOL> assert isinstance ( descr2 . get_ofs_length ( True ) , Symbolic ) <EOL> assert isinstance ( descr3 . get_ofs_length ( True ) , Symbolic ) <EOL> assert isinstance ( descr4 . get_ofs_length ( True ) , Symbolic ) <EOL> assert isinstance ( descr1 . get_item_size ( True ) , Symbolic ) <EOL> assert isinstance ( descr2 . get_item_size ( True ) , Symbolic ) <EOL> assert isinstance ( descr3 . get_item_size ( True ) , Symbolic ) <EOL> assert isinstance ( descr4 . get_item_size ( True ) , Symbolic ) <EOL> def test_get_call_descr_not_translated ( ) : <EOL> c0 = GcCache ( False ) <EOL> descr1 = get_call_descr ( c0 , [ lltype . Char , lltype . Signed ] , lltype . Char ) <EOL> assert descr1 . get_result_size ( False ) == rffi . sizeof ( lltype . Char ) <EOL> assert not descr1 . returns_a_pointer ( ) <EOL> assert not descr1 . returns_a_float ( ) <EOL> assert descr1 . arg_classes == "<STR_LIT>" <EOL> T = lltype . GcStruct ( '<STR_LIT:T>' ) <EOL> descr2 = get_call_descr ( c0 , [ lltype . Ptr ( T ) ] , lltype . Ptr ( T ) ) <EOL> assert descr2 . get_result_size ( False ) == rffi . sizeof ( lltype . Ptr ( T ) ) <EOL> assert descr2 . returns_a_pointer ( ) <EOL> assert not descr2 . returns_a_float ( ) <EOL> assert descr2 . arg_classes == "<STR_LIT:r>" <EOL> U = lltype . GcStruct ( '<STR_LIT>' , ( '<STR_LIT:x>' , lltype . Signed ) ) <EOL> assert descr2 == get_call_descr ( c0 , [ lltype . Ptr ( U ) ] , lltype . Ptr ( U ) ) <EOL> descr4 = get_call_descr ( c0 , [ lltype . Float , lltype . Float ] , lltype . Float ) <EOL> assert descr4 . get_result_size ( False ) == rffi . sizeof ( lltype . Float ) <EOL> assert not descr4 . returns_a_pointer ( ) <EOL> assert descr4 . returns_a_float ( ) <EOL> assert descr4 . arg_classes == "<STR_LIT>" <EOL> def test_get_call_descr_translated ( ) : <EOL> c1 = GcCache ( True ) <EOL> T = lltype . GcStruct ( '<STR_LIT:T>' ) <EOL> U = lltype . GcStruct ( '<STR_LIT>' , ( '<STR_LIT:x>' , lltype . Signed ) ) <EOL> descr3 = get_call_descr ( c1 , [ lltype . Ptr ( T ) ] , lltype . Ptr ( U ) ) <EOL> assert isinstance ( descr3 . get_result_size ( True ) , Symbolic ) <EOL> assert descr3 . returns_a_pointer ( ) <EOL> assert not descr3 . returns_a_float ( ) <EOL> assert descr3 . arg_classes == "<STR_LIT:r>" <EOL> descr4 = get_call_descr ( c1 , [ lltype . Float , lltype . Float ] , lltype . Float ) <EOL> assert isinstance ( descr4 . get_result_size ( True ) , Symbolic ) <EOL> assert not descr4 . returns_a_pointer ( ) <EOL> assert descr4 . returns_a_float ( ) <EOL> assert descr4 . arg_classes == "<STR_LIT>" <EOL> def test_repr_of_descr ( ) : <EOL> c0 = GcCache ( False ) <EOL> T = lltype . GcStruct ( '<STR_LIT:T>' ) <EOL> S = lltype . GcStruct ( '<STR_LIT:S>' , ( '<STR_LIT:x>' , lltype . Char ) , <EOL> ( '<STR_LIT:y>' , lltype . Ptr ( T ) ) , <EOL> ( '<STR_LIT:z>' , lltype . Ptr ( T ) ) ) <EOL> descr1 = get_size_descr ( c0 , S ) <EOL> s = symbolic . get_size ( S , False ) <EOL> assert descr1 . repr_of_descr ( ) == '<STR_LIT>' % s <EOL> descr2 = get_field_descr ( c0 , S , '<STR_LIT:y>' ) <EOL> o , _ = symbolic . get_field_token ( S , '<STR_LIT:y>' , False ) <EOL> assert descr2 . repr_of_descr ( ) == '<STR_LIT>' % o <EOL> descr2i = get_field_descr ( c0 , S , '<STR_LIT:x>' ) <EOL> o , _ = symbolic . get_field_token ( S , '<STR_LIT:x>' , False ) <EOL> assert descr2i . repr_of_descr ( ) == '<STR_LIT>' % o <EOL> descr3 = get_array_descr ( c0 , lltype . GcArray ( lltype . Ptr ( S ) ) ) <EOL> assert descr3 . repr_of_descr ( ) == '<STR_LIT>' <EOL> descr3i = get_array_descr ( c0 , lltype . GcArray ( lltype . Char ) ) <EOL> assert descr3i . repr_of_descr ( ) == '<STR_LIT>' <EOL> cache = { } <EOL> descr4 = get_call_descr ( c0 , [ lltype . Char , lltype . Ptr ( S ) ] , lltype . Ptr ( S ) ) <EOL> assert '<STR_LIT>' in descr4 . repr_of_descr ( ) <EOL> descr4i = get_call_descr ( c0 , [ lltype . Char , lltype . Ptr ( S ) ] , lltype . Char ) <EOL> assert '<STR_LIT>' in descr4i . repr_of_descr ( ) <EOL> descr4f = get_call_descr ( c0 , [ lltype . Char , lltype . Ptr ( S ) ] , lltype . Float ) <EOL> assert '<STR_LIT>' in descr4f . repr_of_descr ( ) </s>
