I was asked to write a code translator that would take a Python program and produce a C program. Do you have any ideas how could I approach this problem or is it even possible?
Python code can make calls directly into C modules. Those C modules can be either generic C libraries or libraries built specifically to work with Python. Cython generates the second kind of module: C libraries that talk to Python's internals, and that can be bundled with existing Python code.
Python is an interpreted language, which means the source code of a Python program is converted into bytecode that is then executed by the Python virtual machine. Python is different from major compiled languages, such as C and C + +, as Python code is not required to be built and linked like code for these languages.
Extending Python with C or C++ It is quite easy to add new built-in modules to Python, if you know how to program in C. Such extension modules can do two things that can't be done directly in Python: they can implement new built-in object types, and they can call C library functions and system calls.
It's hard to believe that nobody has mentioned Cython -- pretty much the de facto standard for this type of job, in my opinion: http://www.cython.org/
Shedskin: http://code.google.com/p/shedskin/
Boost Python: http://www.boost.org/doc/libs/1_42_0/libs/python/doc/index.html
PyCXX: http://cxx.sourceforge.net/
Cython: http://www.cython.org/
from http://wiki.python.org/moin/compile%20Python%20to%20C, there's a list of related projects.
Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
psyco: http://psyco.sourceforge.net/
RPython: http://code.google.com/p/rpython/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With