How to port Python code into C++ code automatically?

Discussion in 'Python' started by Bo, Mar 13, 2008.

  1. Bo

    Bo Guest

    I want to port a Python project (about 10,000 line python code) to C+
    +. Is there any automatically tool to do this kind of things? e.g.,
    SWIG(http://www.swig.org/)?

    Any comment is welcome!

    Thanks!
    Bo, Mar 13, 2008
    #1
    1. Advertising

  2. Bo

    Paddy Guest

    On Mar 13, 3:15 am, Bo <> wrote:
    > I want to port a Python project (about 10,000 line python code) to C+
    > +. Is there any automatically tool to do this kind of things? e.g.,
    > SWIG(http://www.swig.org/)?
    >
    > Any comment is welcome!
    >
    > Thanks!


    There isn't a magic porting tool available.
    If you said more about the why and the resources available then you
    might get a better answer.

    - Paddy.
    Paddy, Mar 13, 2008
    #2
    1. Advertising

  3. Bo

    Jeff Schwab Guest

    Bo wrote:
    > I want to port a Python project (about 10,000 line python code) to C+
    > +. Is there any automatically tool to do this kind of things? e.g.,


    That's not trivial. Python is very heavily oriented toward run-time
    processing, whereas C++ favors compile-time processing.

    > e.g., SWIG(http://www.swig.org/)?


    Swig isn't so much a translator as a way of linking C or C++ code to
    multiple different scripting languages, using shared configuration (.i)
    files. If you're only connecting two languages (Python and C++), Swig
    is probably not going to help you much unless you happen to already be a
    master of Swig-foo.

    If the Python code works, then it's probably best to keep it in Python.
    To access it from C++, try Boost.Python. If you really do need to
    translate the code from Python to C++, try to do it incrementally. If
    the Python code is so monolithic that you can't find individual pieces
    to move one-at-a-time, consider refactoring the code in Python so that
    you'll at least have some modularity to work with. (In the process of
    refactoring, you may also find that you don't have to move the code out
    of Python, after all, e.g. because the performance improves along with
    the design.)
    Jeff Schwab, Mar 13, 2008
    #3
  4. On Wed, 12 Mar 2008 20:15:32 -0700, Bo wrote:

    > I want to port a Python project (about 10,000 line python code) to C+
    > +. Is there any automatically tool to do this kind of things? e.g.,
    > SWIG(http://www.swig.org/)?
    >
    > Any comment is welcome!


    Have a look at the ShedSkin Python-to-C++ compiler:

    http://shed-skin.blogspot.com/

    It has some restrictions, i.e. the code has to be written in a more or
    less statically typed way.

    And me too is interested in why you want to port the entire project instead
    just the time critical parts? ShedSkin might help here too. As Cython_
    or Pyrex_ do. Both compile a subset of Python with optional static typing
    to C extension modules.

    ... _Cython: http://www.cython.org/
    ... _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/

    Ciao,
    Marc 'BlackJack' Rintsch
    Marc 'BlackJack' Rintsch, Mar 13, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John T. Goodman

    Overhead of 4-port over 2-port SRAM

    John T. Goodman, Jan 25, 2005, in forum: VHDL
    Replies:
    0
    Views:
    597
    John T. Goodman
    Jan 25, 2005
  2. Sean Wolfe
    Replies:
    1
    Views:
    2,251
    Joerg Jooss
    Apr 28, 2005
  3. =?Utf-8?B?TWlrZQ==?=

    Automatically Insert Code into each New Webform

    =?Utf-8?B?TWlrZQ==?=, Dec 5, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    355
  4. b3ny
    Replies:
    11
    Views:
    921
    Babu Kalakrishnan
    Nov 20, 2004
  5. Gerald Klix
    Replies:
    0
    Views:
    1,272
    Gerald Klix
    Oct 26, 2005
Loading...

Share This Page