<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome to CodePy’s documentation! — CodePy 2013.1 documentation</title> <link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '', VERSION: '2013.1', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="_static/jquery.js"></script> <script type="text/javascript" src="_static/underscore.js"></script> <script type="text/javascript" src="_static/doctools.js"></script> <link rel="top" title="CodePy 2013.1 documentation" href="#" /> <link rel="next" title="Wrapping and Linking" href="jit.html" /> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="jit.html" title="Wrapping and Linking" accesskey="N">next</a> |</li> <li><a href="#">CodePy 2013.1 documentation</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-codepy"> <span id="welcome-to-codepy-s-documentation"></span><h1>Welcome to CodePy’s documentation!<a class="headerlink" href="#module-codepy" title="Permalink to this headline">¶</a></h1> <p>CodePy is a C metaprogramming toolkit for Python. It handles two aspects of metaprogramming:</p> <ul class="simple"> <li>Generating C source code.</li> <li>Compiling this source code and dynamically loading it into the Python interpreter.</li> </ul> <p>Both capabilities are meant to be used together, but also work on their own. In particular, the code generation facilities work well in conjunction with <a class="reference external" href="http://mathema.tician.de/software/pycuda">PyCuda</a>. Dynamic compilation and linking are so far only supported in Linux with the GNU toolchain.</p> <div class="section" id="a-taste-of-codepy"> <h2>A taste of CodePy<a class="headerlink" href="#a-taste-of-codepy" title="Permalink to this headline">¶</a></h2> <p>This sample CodePy program builds a Boost.Python C++ module that returns the string “hello world”:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">cgen</span> <span class="kn">import</span> <span class="o">*</span> <span class="kn">from</span> <span class="nn">codepy.bpl</span> <span class="kn">import</span> <span class="n">BoostPythonModule</span> <span class="n">mod</span> <span class="o">=</span> <span class="n">BoostPythonModule</span><span class="p">()</span> <span class="n">mod</span><span class="o">.</span><span class="n">add_function</span><span class="p">(</span> <span class="n">FunctionBody</span><span class="p">(</span> <span class="n">FunctionDeclaration</span><span class="p">(</span><span class="n">Const</span><span class="p">(</span><span class="n">Pointer</span><span class="p">(</span><span class="n">Value</span><span class="p">(</span><span class="s">"char"</span><span class="p">,</span> <span class="s">"greet"</span><span class="p">))),</span> <span class="p">[]),</span> <span class="n">Block</span><span class="p">([</span><span class="n">Statement</span><span class="p">(</span><span class="s">'return "hello world"'</span><span class="p">)])</span> <span class="p">))</span> <span class="kn">from</span> <span class="nn">codepy.toolchain</span> <span class="kn">import</span> <span class="n">guess_toolchain</span> <span class="n">cmod</span> <span class="o">=</span> <span class="n">mod</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">guess_toolchain</span><span class="p">())</span> <span class="k">print</span> <span class="n">cmod</span><span class="o">.</span><span class="n">greet</span><span class="p">()</span> </pre></div> </div> <div class="section" id="boost-python-and-codepy"> <h3>Boost.Python and CodePy<a class="headerlink" href="#boost-python-and-codepy" title="Permalink to this headline">¶</a></h3> <p>You may notice that the above code snippet refers to <a class="reference external" href="http://www.boost.org/doc/libs/release/libs/python/doc/">Boost.Python</a>. Boost.Python is a Python wrapper generator library for C++. CodePy does not depend on it being available, but its use is strongly encouraged–otherwise the generated sourcecode would need to use another wrapper generator or talk directly to the <a class="reference external" href="http://docs.python.org/c-api/">Python C API</a> to make its functionality accessible from Python. Boost.Python is only used at run time. CodePy has no install-time dependencies</p> <p><a class="reference external" href="http://mathema.tician.de/software/install-boost">Instructions</a> on how to install Boost.Python are available. As described in the instructions, CodePy looks for the installation location of Boost.Python in <tt class="file docutils literal"><span class="pre">$HOME/.aksetup-defaults.py</span></tt> and <tt class="file docutils literal"><span class="pre">/etc/aksetup-defaults.py</span></tt>.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Boost.Python is not needed at all if CodePy is used to generate code for PyCuda.</p> </div> </div> </div> <div class="section" id="contents"> <h2>Contents<a class="headerlink" href="#contents" title="Permalink to this headline">¶</a></h2> <div class="toctree-wrapper compound"> <ul> <li class="toctree-l1"><a class="reference internal" href="jit.html">Wrapping and Linking</a><ul> <li class="toctree-l2"><a class="reference internal" href="jit.html#module-codepy.jit"><tt class="docutils literal"><span class="pre">codepy.jit</span></tt> – Compilation and Linking of C Source Code</a></li> <li class="toctree-l2"><a class="reference internal" href="jit.html#codepy-bpl-support-for-boost-python"><tt class="docutils literal"><span class="pre">codepy.bpl</span></tt> – Support for Boost.Python</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="faq.html">License</a></li> </ul> </div> <p>If you are looking for the <tt class="xref py py-mod docutils literal"><span class="pre">codepy.cgen</span></tt> module, it has been moved to a separate package called <a class="reference external" href="http://documen.tician.de/cgen/index.html#cgen" title="(in cgen v2013.1.2)"><tt class="xref py py-mod docutils literal"><span class="pre">cgen</span></tt></a>, see also that package’s <a class="reference external" href="http://pypi.python.org/pypi/cgen">package index page</a>.</p> </div> </div> <div class="section" id="indices-and-tables"> <h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1> <ul class="simple"> <li><a class="reference internal" href="genindex.html"><em>Index</em></a></li> <li><a class="reference internal" href="py-modindex.html"><em>Module Index</em></a></li> <li><a class="reference internal" href="search.html"><em>Search Page</em></a></li> </ul> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="#">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Welcome to CodePy’s documentation!</a><ul> <li><a class="reference internal" href="#a-taste-of-codepy">A taste of CodePy</a><ul> <li><a class="reference internal" href="#boost-python-and-codepy">Boost.Python and CodePy</a></li> </ul> </li> <li><a class="reference internal" href="#contents">Contents</a><ul> </ul> </li> </ul> </li> <li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li> </ul> <h4>Next topic</h4> <p class="topless"><a href="jit.html" title="next chapter">Wrapping and Linking</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/index.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="jit.html" title="Wrapping and Linking" >next</a> |</li> <li><a href="#">CodePy 2013.1 documentation</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009, Andreas Kloeckner. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> </body> </html>