elyajizi / Py2C

Py2C — a Python to C++ converter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


As of 26 January 2015, the project is on hold, until PEP-484 is finalized...


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


Py2C

Build Status Coverage Status Gitter Project Status

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!

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!

Here's Py2C in action (rather Py2C's planned action) on "Hello World!":

print("Hello World!")

The above should compile to something like:

#include <iostream.h>

int main() {
   std::cout << "Hello World!\n";
   return 0;
}

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

#include "py2c.h"

int main() {
    py2c::print(py2c::str("Hello World!"));
    return 0;
}

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

About

Py2C — a Python to C++ converter

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 97.9%Language:Shell 1.2%Language:JavaScript 0.9%