#NEWLINE# def get_dynamic_module( self ) : #NEWLINE# #INDENT# '\n        Return a cmodule.DynamicModule instance full of the code for our fgraph.\n\n        This method is cached on the first call so it can be called\n        multiple times without penalty.\n\n        ' #NEWLINE# if ( not hasattr ( self , '_mod' ) ) : #NEWLINE# #INDENT# self . code_gen ( ) #NEWLINE# mod = cmodule . DynamicModule ( ) #NEWLINE# code = self . instantiate_code ( ( 1 + len ( self . args ) ) ) #NEWLINE# instantiate = cmodule . ExtFunction ( 'instantiate' , code , method = cmodule . METH_VARARGS ) #NEWLINE# if PY3 : #NEWLINE# #INDENT# static = '\n        static int {struct_name}_executor({struct_name} *self) {{\n            return self->run();\n        }}\n\n        static void {struct_name}_destructor(PyObject *capsule) {{\n            {struct_name} *self = ({struct_name} *)PyCapsule_GetContext(capsule);\n            delete self;\n        }}\n        ' . format ( struct_name = self . struct_name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# static = ( '\n        static int %(struct_name)s_executor(%(struct_name)s* self) {\n            return self->run();\n        }\n\n        static void %(struct_name)s_destructor(void* executor, void* self) {\n            delete ((%(struct_name)s*)self);\n        }\n        ' % dict ( struct_name = self . struct_name ) ) #NEWLINE# #UNINDENT# for support_code in ( self . support_code ( ) + self . c_support_code_apply ) : #NEWLINE# #INDENT# mod . add_support_code ( support_code ) #NEWLINE# #UNINDENT# mod . add_support_code ( self . struct_code ) #NEWLINE# mod . add_support_code ( static ) #NEWLINE# mod . add_function ( instantiate ) #NEWLINE# for header in self . headers ( ) : #NEWLINE# #INDENT# mod . add_include ( header ) #NEWLINE# #UNINDENT# for init_code_block in ( self . init_code ( ) + self . c_init_code_apply ) : #NEWLINE# #INDENT# mod . add_init_code ( support_code ) #NEWLINE# #UNINDENT# self . _mod = mod #NEWLINE# #UNINDENT# return self . _mod