Giter VIP home page Giter VIP logo

py2c's Introduction

π2c – A Python-Bytecode to C compiler

Project Overview:

Toba is a set of tools that increase the speed of Java programs by converting Java Bytecode to C and compiling it ahead-of-time to generate a native executable. We want to apply the same basic idea to Python, and convert .pyc files to C code. This bytecode-to-source compiler (called π2c) has the aim of improving runtime efficiency of python code. We also plan on comparing the performance of π2c to other existing python runtimes, e.g., the python interpreter, cython, etc. across a broad set of benchmarks.

Instructions for use:

To convert a python3 file to c source code, run

./py2c.py python_file [out_file]

For example, running

./py2c.py test/fibonacci.py test/fibonacci.c

will compile the fibonacci program into a .pyc bytecode file, and convert it to a c program. Then, running

gcc -O3 test/fibonacci.c -o test/fibonacci

will compile and optimize the c program, creating an executable binary in the desired location.

Note: In order for py2c to work, all functions and variables need to be statically typed. Type annotations (introduced in v3.5) are required for functions. Supported types include int, float, and bool.

Examples:

A set of example programs can be found in the test/ directory, and a set of benchmarks can be found in the benchmarks/ directory. Note that the examples test/complicated.py and test/dynamic_typing.py do not work, since they highlight features that have not been implemented in py2c.

These examples can be run manually using the instructions in the section above.

Benchmarks:

The run-benchmarks.py program exists to automatically test the runtime of the py2c translation against various other runtime systems. Currently, it tests the program when run with py2c (with and without optimizations), CPython (python interpreter), PyPy (python JIT compiler), cython (c/python interface), and idiomatic (manual) c translation. The runtimes and relative speedups are printed for each program and runtime.

To run all of the benchmarks at once, run

python3 run-benchmarks.py

Before you run the above command, it may be necessary to install the following programs:

  • Cython (pip3 install cython)
  • PyPy (version >= 3.5)

Important: At the top of the run-benchmarks.py file, change the user-defined constants to contain the proper values for your environment. If cython is installed, set the value of isCythonInstalled to True

References

Useful Links:

py2c's People

Contributors

ben1152000 avatar seifibrahim avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.