<s> """<STR_LIT>""" <EOL> from pypy . objspace . std . model import W_ANY , W_Object <EOL> from pypy . interpreter import baseobjspace <EOL> from pypy . interpreter . argument import Arguments <EOL> from pypy . tool . sourcetools import func_with_new_name <EOL> def create_mm_names ( classname , mm , is_local ) : <EOL> s = "<STR_LIT>" <EOL> if is_local : <EOL> s += "<STR_LIT>" <EOL> s += mm . name + "<STR_LIT>" <EOL> s += "<STR_LIT:_>" . join ( [ classname ] + [ "<STR_LIT>" ] * ( mm . arity - <NUM_LIT:1> ) ) <EOL> if mm . specialnames : <EOL> return s , mm . specialnames [ <NUM_LIT:0> ] <EOL> return s , mm . name <EOL> def install_general_args_trampoline ( type_ , mm , is_local , op_name ) : <EOL> def function ( space , w_transparent_list , __args__ ) : <EOL> args = __args__ . prepend ( space . wrap ( op_name ) ) <EOL> return space . call_args ( w_transparent_list . w_controller , args ) <EOL> function = func_with_new_name ( function , mm . name ) <EOL> mm . register ( function , type_ ) <EOL> def install_w_args_trampoline ( type_ , mm , is_local , op_name ) : <EOL> def function ( space , w_transparent_list , * args_w ) : <EOL> args = Arguments ( space , [ space . wrap ( op_name ) ] + list ( args_w [ : - <NUM_LIT:1> ] ) , w_stararg = args_w [ - <NUM_LIT:1> ] ) <EOL> return space . call_args ( w_transparent_list . w_controller , args ) <EOL> function = func_with_new_name ( function , mm . name ) <EOL> mm . register ( function , type_ , * ( [ W_ANY ] * ( mm . arity - <NUM_LIT:1> ) ) ) <EOL> def install_mm_trampoline ( type_ , mm , is_local ) : <EOL> classname = type_ . __name__ [ <NUM_LIT:2> : ] <EOL> mm_name , op_name = create_mm_names ( classname , mm , is_local ) <EOL> if [ '<STR_LIT>' ] == mm . argnames_after : <EOL> return install_general_args_trampoline ( type_ , mm , is_local , op_name ) <EOL> if [ '<STR_LIT>' ] == mm . argnames_after : <EOL> return install_w_args_trampoline ( type_ , mm , is_local , op_name ) <EOL> assert not mm . argnames_after <EOL> def function ( space , w_transparent_list , * args_w ) : <EOL> return space . call_function ( w_transparent_list . w_controller , space . wrap ( op_name ) , * args_w ) <EOL> function = func_with_new_name ( function , mm_name ) <EOL> mm . register ( function , type_ , * ( [ W_ANY ] * ( mm . arity - <NUM_LIT:1> ) ) ) <EOL> def is_special_doublearg ( mm , type_ ) : <EOL> """<STR_LIT>""" <EOL> if mm . arity != <NUM_LIT:2> : <EOL> return False <EOL> if len ( mm . specialnames ) != <NUM_LIT:2> : <EOL> return False <EOL> for signature in mm . signatures ( ) : <EOL> if signature == ( type_ . original , type_ . original ) : <EOL> return True <EOL> return False <EOL> def install_mm_special ( type_ , mm , is_local ) : <EOL> classname = type_ . __name__ [ <NUM_LIT:2> : ] <EOL> def function ( space , w_any , w_transparent_list ) : <EOL> retval = space . call_function ( w_transparent_list . w_controller , space . wrap ( mm . specialnames [ <NUM_LIT:1> ] ) , <EOL> w_any ) <EOL> return retval <EOL> function = func_with_new_name ( function , mm . specialnames [ <NUM_LIT:0> ] ) <EOL> mm . register ( function , type_ . typedef . any , type_ ) <EOL> def register_type ( type_ ) : <EOL> from pypy . objspace . std . stdtypedef import multimethods_defined_on <EOL> for mm , is_local in multimethods_defined_on ( type_ . original ) : <EOL> if not mm . name . startswith ( '<STR_LIT>' ) : <EOL> install_mm_trampoline ( type_ , mm , is_local ) <EOL> if is_special_doublearg ( mm , type_ ) : <EOL> install_mm_special ( type_ , mm , is_local ) </s>
