<s> from pypy . rpython . lltypesystem . lltype import typeOf , Void <EOL> from pypy . translator . c . support import USESLOTS <EOL> from pypy . translator . c . support import cdecl , somelettersfrom <EOL> class CExternalFunctionCodeGenerator ( object ) : <EOL> if USESLOTS : <EOL> __slots__ = """<STR_LIT>""" . split ( ) <EOL> def __init__ ( self , fnptr , db ) : <EOL> self . fnptr = fnptr <EOL> self . db = db <EOL> self . FUNCTYPE = typeOf ( fnptr ) <EOL> assert Void not in self . FUNCTYPE . ARGS <EOL> self . argtypenames = [ db . gettype ( T ) for T in self . FUNCTYPE . ARGS ] <EOL> self . resulttypename = db . gettype ( self . FUNCTYPE . RESULT ) <EOL> def graphs_to_patch ( self ) : <EOL> return [ ] <EOL> def name ( self , cname ) : <EOL> return cname <EOL> def argnames ( self ) : <EOL> return [ '<STR_LIT>' % ( somelettersfrom ( self . argtypenames [ i ] ) , i ) <EOL> for i in range ( len ( self . argtypenames ) ) ] <EOL> def allconstantvalues ( self ) : <EOL> return [ ] <EOL> def implementation_begin ( self ) : <EOL> pass <EOL> def cfunction_declarations ( self ) : <EOL> if self . FUNCTYPE . RESULT is not Void : <EOL> yield '<STR_LIT>' % cdecl ( self . resulttypename , '<STR_LIT:result>' ) <EOL> def cfunction_body ( self ) : <EOL> try : <EOL> convert_params = self . fnptr . convert_params <EOL> except AttributeError : <EOL> convert_params = lambda backend , args : [ arg for _ , arg in args ] <EOL> call = '<STR_LIT>' % ( self . fnptr . _name , '<STR_LIT:U+002CU+0020>' . join ( convert_params ( "<STR_LIT:c>" , zip ( self . FUNCTYPE . ARGS , self . argnames ( ) ) ) ) ) <EOL> if self . FUNCTYPE . RESULT is not Void : <EOL> yield '<STR_LIT>' % call <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> else : <EOL> yield '<STR_LIT>' % call <EOL> yield '<STR_LIT>' <EOL> def implementation_end ( self ) : <EOL> pass <EOL> assert not USESLOTS or '<STR_LIT>' not in dir ( CExternalFunctionCodeGenerator ) </s>
