Python 3 Project to Convert Python Script to C++ Code Converter Using Py2C Library in Command Line

 

 

Py2C

Build Status Coverage Status Gitter Project Status

The project is not functional yet. It’s just in pre-alpha/planning stage…

A trans-compiler for compiling Python code into human-readable C++ code, somewhat like what humans might actually write. It would have to be really smart and that’s the aim!

I have not been able to find the required amount of time to invest in this project to get it working. And it does not seem likely I will get it in the near future. See #11 for more.

This project is currently focused on statically typed programs and optimizing them. This means the current scope of the project is limited. On some future date, this project may also support all of Python’s dynamic nature, subject to whether such a change is helpful and feasible for the project.

The idea is that even in highly dynamic languages (like Python) variables often end up holding (references to) values have only one “type”. This is a major area for improving performance as statically typed languages (like C++) often are better with, well, typed variables. So if these one-type variables can be in a faster language, why not have them there?

But for those gains, you’ll have to leave the comforts of Python and write C++ code. And here’s where Py2C is supposed to come in! You can just tweak the existing Python code a bit and pass it through Py2C and it automagically outputs C++ code that does that same thing as the Python code, just a whole lot faster! Yay!

Here’s Py2C in action (rather Py2C’s planned action) on “Hello World!”:

The above should compile to something like:

If it is needed, a special header file is included in the generated file. For example, the above example would compile to something like:

If all goes as planned, on one fine day, Py2C will also be extendable to accommodate for API changes across the languages, for third party packages (like NumPy, Qt etc)

 

 

https://github.com/pradyun/Py2C

 

Leave a Reply