<s> import py <EOL> from pycket import config <EOL> from pycket . util import add_copy_method <EOL> from rpython . rlib . unroll import unrolling_iterable <EOL> from rpython . rlib import jit , debug , objectmodel <EOL> add_clone_method = add_copy_method ( "<STR_LIT>" ) <EOL> def inline_small_list ( sizemax = <NUM_LIT:11> , sizemin = <NUM_LIT:0> , immutable = False , unbox_num = False , nonull = False , <EOL> attrname = "<STR_LIT:list>" , factoryname = "<STR_LIT>" , listgettername = "<STR_LIT>" , <EOL> listsizename = "<STR_LIT>" , gettername = "<STR_LIT>" , <EOL> settername = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if not config . type_size_specialization : <EOL> sizemin = sizemax = <NUM_LIT:0> <EOL> unbox_num = False <EOL> def wrapper ( cls ) : <EOL> def make_class ( size ) : <EOL> attrs = [ "<STR_LIT>" % ( attrname , i ) for i in range ( size ) ] <EOL> unrolling_enumerate_attrs = unrolling_iterable ( enumerate ( attrs ) ) <EOL> def _get_size_list ( self ) : <EOL> return size <EOL> def _get_list ( self , i ) : <EOL> for j , attr in unrolling_enumerate_attrs : <EOL> if j == i : <EOL> return getattr ( self , attr ) <EOL> raise IndexError <EOL> def _get_full_list ( self ) : <EOL> res = [ None ] * size <EOL> for i , attr in unrolling_enumerate_attrs : <EOL> res [ i ] = getattr ( self , attr ) <EOL> return res <EOL> def _set_list ( self , i , val ) : <EOL> for j , attr in unrolling_enumerate_attrs : <EOL> if j == i : <EOL> if nonull : <EOL> assert val is not None <EOL> setattr ( self , attr , val ) <EOL> return <EOL> raise IndexError <EOL> def _init ( self , elems , * args ) : <EOL> assert len ( elems ) == size <EOL> for i , attr in unrolling_enumerate_attrs : <EOL> val = elems [ i ] <EOL> if nonull : <EOL> assert val is not None <EOL> setattr ( self , attr , elems [ i ] ) <EOL> cls . __init__ ( self , * args ) <EOL> methods = { <EOL> gettername : _get_list , <EOL> listsizename : _get_size_list , <EOL> listgettername : _get_full_list , <EOL> settername : _set_list , <EOL> "<STR_LIT>" : _init , <EOL> } <EOL> newcls = type ( cls ) ( "<STR_LIT>" % ( cls . __name__ , size ) , ( cls , ) , methods ) <EOL> if immutable : <EOL> setattr ( newcls , "<STR_LIT>" , attrs ) <EOL> newcls = add_clone_method ( newcls ) <EOL> return newcls <EOL> classes = map ( make_class , range ( sizemin , sizemax ) ) <EOL> def _get_arbitrary ( self , i ) : <EOL> return getattr ( self , attrname ) [ i ] <EOL> def _get_size_list_arbitrary ( self ) : <EOL> return len ( getattr ( self , attrname ) ) <EOL> def _get_list_arbitrary ( self ) : <EOL> return getattr ( self , attrname ) <EOL> def _set_arbitrary ( self , i , val ) : <EOL> if nonull : <EOL> assert val is not None <EOL> getattr ( self , attrname ) [ i ] = val <EOL> def _init ( self , elems , * args ) : <EOL> debug . make_sure_not_resized ( elems ) <EOL> setattr ( self , attrname , elems ) <EOL> cls . __init__ ( self , * args ) <EOL> methods = { <EOL> gettername : _get_arbitrary , <EOL> listsizename : _get_size_list_arbitrary , <EOL> listgettername : _get_list_arbitrary , <EOL> settername : _set_arbitrary , <EOL> "<STR_LIT>" : _init , <EOL> } <EOL> cls_arbitrary = type ( cls ) ( "<STR_LIT>" % cls . __name__ , ( cls , ) , methods ) <EOL> if immutable : <EOL> setattr ( cls_arbitrary , "<STR_LIT>" , [ "<STR_LIT>" % ( attrname , ) ] ) <EOL> cls_arbitrary = add_clone_method ( cls_arbitrary ) <EOL> def make ( elems , * args ) : <EOL> if classes : <EOL> if ( elems is None or len ( elems ) == <NUM_LIT:0> ) : <EOL> return make0 ( * args ) <EOL> else : <EOL> if elems is None : <EOL> elems = [ ] <EOL> if sizemin <= len ( elems ) < sizemax : <EOL> cls = classes [ len ( elems ) - sizemin ] <EOL> else : <EOL> cls = cls_arbitrary <EOL> return cls ( elems , * args ) <EOL> def make0 ( * args ) : <EOL> if not classes : <EOL> return make ( [ ] , * args ) <EOL> result = objectmodel . instantiate ( classes [ <NUM_LIT:0> ] ) <EOL> cls . __init__ ( result , * args ) <EOL> return result <EOL> def make1 ( elem , * args ) : <EOL> if not classes : <EOL> return make ( [ elem ] , * args ) <EOL> result = objectmodel . instantiate ( classes [ <NUM_LIT:1> ] ) <EOL> result . _set_list ( <NUM_LIT:0> , elem ) <EOL> cls . __init__ ( result , * args ) <EOL> return result <EOL> def make2 ( elem1 , elem2 , * args ) : <EOL> if not classes : <EOL> return make ( [ elem1 , elem2 ] , * args ) <EOL> result = objectmodel . instantiate ( classes [ <NUM_LIT:2> ] ) <EOL> result . _set_list ( <NUM_LIT:0> , elem1 ) <EOL> result . _set_list ( <NUM_LIT:1> , elem2 ) <EOL> cls . __init__ ( result , * args ) <EOL> return result <EOL> def make_n ( size , * args ) : <EOL> if sizemin <= size < sizemax : <EOL> subcls = classes [ size - sizemin ] <EOL> else : <EOL> subcls = cls_arbitrary <EOL> result = objectmodel . instantiate ( subcls ) <EOL> if subcls is cls_arbitrary : <EOL> assert isinstance ( result , subcls ) <EOL> setattr ( result , attrname , [ None ] * size ) <EOL> cls . __init__ ( result , * args ) <EOL> return result <EOL> if unbox_num : <EOL> assert immutable , "<STR_LIT>" <EOL> make , make1 , make2 = _add_num_classes ( cls , make , make0 , make1 , make2 ) <EOL> setattr ( cls , factoryname , staticmethod ( make ) ) <EOL> setattr ( cls , factoryname + "<STR_LIT:0>" , staticmethod ( make0 ) ) <EOL> setattr ( cls , factoryname + "<STR_LIT:1>" , staticmethod ( make1 ) ) <EOL> setattr ( cls , factoryname + "<STR_LIT:2>" , staticmethod ( make2 ) ) <EOL> setattr ( cls , factoryname + "<STR_LIT>" , staticmethod ( make_n ) ) <EOL> return cls <EOL> return wrapper <EOL> def _add_num_classes ( cls , orig_make , orig_make0 , orig_make1 , orig_make2 ) : <EOL> def make ( vals , * args ) : <EOL> from pycket . values import W_Fixnum <EOL> if vals is None or len ( vals ) == <NUM_LIT:0> : <EOL> return orig_make0 ( * args ) <EOL> if len ( vals ) == <NUM_LIT:1> : <EOL> return make1 ( vals [ <NUM_LIT:0> ] , * args ) <EOL> if len ( vals ) == <NUM_LIT:2> : <EOL> return make2 ( vals [ <NUM_LIT:0> ] , vals [ <NUM_LIT:1> ] , * args ) <EOL> return orig_make ( vals , * args ) <EOL> def make1 ( w_a , * args ) : <EOL> from pycket . values import W_Fixnum , W_Flonum <EOL> if isinstance ( w_a , W_Fixnum ) : <EOL> return Size1Fixed ( w_a . value , * args ) <EOL> if isinstance ( w_a , W_Flonum ) : <EOL> return Size1Flo ( w_a . value , * args ) <EOL> return orig_make1 ( w_a , * args ) <EOL> def make2 ( w_a , w_b , * args ) : <EOL> from pycket . values import W_Fixnum <EOL> if isinstance ( w_a , W_Fixnum ) : <EOL> if isinstance ( w_b , W_Fixnum ) : <EOL> return Size2Fixed11 ( w_a . value , w_b . value , * args ) <EOL> else : <EOL> return Size2Fixed10 ( w_a . value , w_b , * args ) <EOL> elif isinstance ( w_b , W_Fixnum ) : <EOL> return Size2Fixed01 ( w_a , w_b . value , * args ) <EOL> return orig_make2 ( w_a , w_b , * args ) <EOL> class Size1Fixed ( cls ) : <EOL> _immutable_fields_ = [ '<STR_LIT>' ] <EOL> def __init__ ( self , vals_fixed_0 , * args ) : <EOL> self . vals_fixed_0 = vals_fixed_0 <EOL> cls . __init__ ( self , * args ) <EOL> def _get_size_list ( self ) : <EOL> return <NUM_LIT:1> <EOL> def _get_full_list ( self ) : <EOL> return [ self . _get_list ( <NUM_LIT:0> ) ] <EOL> def _get_list ( self , i ) : <EOL> from pycket . values import W_Fixnum <EOL> assert i == <NUM_LIT:0> <EOL> return W_Fixnum ( self . vals_fixed_0 ) <EOL> def _set_list ( self , i , val ) : <EOL> raise NotImplementedError ( ) <EOL> Size1Fixed . __name__ = cls . __name__ + Size1Fixed . __name__ <EOL> add_clone_method ( Size1Fixed ) <EOL> class Size1Flo ( cls ) : <EOL> _immutable_fields_ = [ '<STR_LIT>' ] <EOL> def __init__ ( self , vals_flo_0 , * args ) : <EOL> self . vals_flo_0 = vals_flo_0 <EOL> cls . __init__ ( self , * args ) <EOL> def _get_size_list ( self ) : <EOL> return <NUM_LIT:1> <EOL> def _get_full_list ( self ) : <EOL> return [ self . _get_list ( <NUM_LIT:0> ) ] <EOL> def _get_list ( self , i ) : <EOL> from pycket . values import W_Flonum <EOL> assert i == <NUM_LIT:0> <EOL> return W_Flonum ( self . vals_flo_0 ) <EOL> def _set_list ( self , i , val ) : <EOL> raise NotImplementedError ( ) <EOL> Size1Flo . __name__ = cls . __name__ + Size1Flo . __name__ <EOL> add_clone_method ( Size1Flo ) <EOL> class Size2Fixed10 ( cls ) : <EOL> _immutable_fields_ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , vals_fixed_0 , w_val1 , * args ) : <EOL> self . vals_fixed_0 = vals_fixed_0 <EOL> self . w_val1 = w_val1 <EOL> cls . __init__ ( self , * args ) <EOL> def _get_size_list ( self ) : <EOL> return <NUM_LIT:2> <EOL> def _get_full_list ( self ) : <EOL> return [ self . _get_list ( <NUM_LIT:0> ) , self . _get_list ( <NUM_LIT:1> ) ] <EOL> def _get_list ( self , i ) : <EOL> from pycket . values import W_Fixnum <EOL> if i == <NUM_LIT:0> : <EOL> return W_Fixnum ( self . vals_fixed_0 ) <EOL> else : <EOL> assert i == <NUM_LIT:1> <EOL> return self . w_val1 <EOL> def _set_list ( self , i , val ) : <EOL> raise NotImplementedError ( ) <EOL> Size2Fixed10 . __name__ = cls . __name__ + Size2Fixed10 . __name__ <EOL> add_clone_method ( Size2Fixed10 ) <EOL> class Size2Fixed01 ( cls ) : <EOL> _immutable_fields_ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , w_val0 , vals_fixed_1 , * args ) : <EOL> self . w_val0 = w_val0 <EOL> self . vals_fixed_1 = vals_fixed_1 <EOL> cls . __init__ ( self , * args ) <EOL> def _get_size_list ( self ) : <EOL> return <NUM_LIT:2> <EOL> def _get_full_list ( self ) : <EOL> return [ self . _get_list ( <NUM_LIT:0> ) , self . _get_list ( <NUM_LIT:1> ) ] <EOL> def _get_list ( self , i ) : <EOL> from pycket . values import W_Fixnum <EOL> if i == <NUM_LIT:0> : <EOL> return self . w_val0 <EOL> else : <EOL> assert i == <NUM_LIT:1> <EOL> return W_Fixnum ( self . vals_fixed_1 ) <EOL> def _set_list ( self , i , val ) : <EOL> raise NotImplementedError ( ) <EOL> Size2Fixed01 . __name__ = cls . __name__ + Size2Fixed01 . __name__ <EOL> add_clone_method ( Size2Fixed01 ) <EOL> class Size2Fixed11 ( cls ) : <EOL> _immutable_fields_ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , vals_fixed_0 , vals_fixed_1 , * args ) : <EOL> self . vals_fixed_0 = vals_fixed_0 <EOL> self . vals_fixed_1 = vals_fixed_1 <EOL> cls . __init__ ( self , * args ) <EOL> def _get_size_list ( self ) : <EOL> return <NUM_LIT:2> <EOL> def _get_full_list ( self ) : <EOL> return [ self . _get_list ( <NUM_LIT:0> ) , self . _get_list ( <NUM_LIT:1> ) ] <EOL> def _get_list ( self , i ) : <EOL> from pycket . values import W_Fixnum <EOL> if i == <NUM_LIT:0> : <EOL> return W_Fixnum ( self . vals_fixed_0 ) <EOL> else : <EOL> assert i == <NUM_LIT:1> <EOL> return W_Fixnum ( self . vals_fixed_1 ) <EOL> def _set_list ( self , i , val ) : <EOL> raise NotImplementedError ( ) <EOL> Size2Fixed11 . __name__ = cls . __name__ + Size2Fixed11 . __name__ <EOL> add_clone_method ( Size2Fixed11 ) <EOL> return make , make1 , make2 </s>
