Giter Club home page Giter Club logo

pytc's Introduction

PyTC

Python compiler written in Rust.

The tool's original premise was to transpile generated Python bytecode (through .pycache files generated by CPython interpreter) to C code. The C would be then compiled to an executable through gcc with optimizations and linked to Python std library function equivalents.

However, assuming the goal is to speed up Python through compilation, there are other possible methods of achieving that:

  1. Transpile the Python binary into Assembly directly. This shouldn't be as hard as it sounds, because instructions in Python binaries resemble Assembly behavior. However, as to my current knowledge, there are no decent Assembly optimizers that work as good as gcc, and developing the code for different platforms would be necessary.
  2. Transpile the Python source code directly to C. For the most part it should be rather easy for basic code, but more advanced Python syntax may require plenty of code generation. Recognizing types may also turn out to be a pain.
  3. Transpile the Python binary into LLVM. I'm not sure what the problems with this approach could be, except learning LLVM.
  4. Create a Lexer to parse the Python source code into an AST and then reconstruct the AST in C. This approach may have similar drawbacks as direct source code manipulation, but basic cases should be easier to handle and more maintainable.

Requirements:

  • Python 3.10.2 (CPython implementation)
  • LLVM 16.0.4

Todo:

  • Create a Python script to generate the .pycache (.pyc) file
  • Map the basic Python binary in Rust
  • Try transpilation with method 3
  • Map the extended Python binary in Rust
  • Create a more basic representation of the binary for further processing
  • Try transpilation with the original method
  • Try transpilation with method 1
  • Try transpilation with method 2
  • Try transpilation with method 4
  • Finally compile the basic Python code
  • Iterate and implement more advanced Python functionality

References:

Examples

Docs

Random

pytc's People

Contributors

tomek20225 avatar

Watchers

 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.