Git Product home page Git Product logo

compy's Introduction

Compy

Compy is a program that apply transformations on Python programs. This tool is currently in development and is considered a preview, which means that it may be unstable and doesn't support all Python3 language features.

Transformations

Here are some of the transformations that Compy can handle, along with their status. If you have idea for new transformations, don't hesitate to add and issue. If you would like to contribute, you can fork the repository and create a pull request with your changes. Please make sure to write tests for any new features or bug fixes, and to run cargo test and cargo fmt before submitting your pull request.

✅ No transformations

🚧 To One-liner

Feature Status
Variables and data types ✅ Done
Control structures (if/else, for/while loops) ✅ Done
Flow statements (return, break, continue, pass) ✅ Done
Functions and lambdas ✅ Done
Classes and objects ✅ Done
Annotations ✅ Done
List, tuple, and dictionary manipulation ✅ Done
Modules and packages ✅ Done
Decorators ✅ Done
Built-in functions and modules ✅ Done
Generators and iterators ✅ Done
Globals ✅ Done
Delete ✅ Done
Exceptions ✅ Done
Yield ❌ Not supported
Exception handling ❌ Not supported
Context managers ❌ Not supported
Async / Await ❌ Not supported
Type hints / Static typing ❌ Not supported

Getting started

git clone https://github.com/mlhoutel/compy.git && cd compy

Library development

cargo test
cargo build

Demo website

cd docs
wasm-pack build --target web --out-dir static
npm i && npm run start

Once the server is running, you can open your web browser and navigate to http://localhost:8000 to see the demo website in action.

compy's People

Contributors

mlhoutel avatar

Stargazers

 avatar  avatar

Watchers

 avatar

compy's Issues

Broken state for while recursive lambda

As noticed in #6, the current state of the while statement for oneliner code is borken.

As for the precedent update to fix the flow statements in the while, for it to be correctly implemented, we must add an explicit declaration of the scoped state for the while.

For instance:

 ..., [__INL__STATE := (None, 2), __INL__TEMP := (...)], ...

Variable scoping issue for nested loops

for i in range(10):
    while True:
        print(i)
        break

is transformed to

[__INL__STATE := (None, 1), [[__INL__i := i, [__INL__TEMP := (lambda __INL__CORE, __INL__STATE, i, print: __INL__CORE(__INL__CORE, __INL__STATE, __INL__i, print))((lambda __INL__CORE, __INL__STATE, i, print: [__INL__i := __INL__i, __INL__print := print, __INL__COND := True, [__INL__print(__INL__i), __INL__STATE := (None, 2), __INL__CORE(__INL__CORE, __INL__STATE, __INL__i, __INL__print)][-1] if __INL__COND else (__INL__STATE, __INL__i, print)][-1]), __INL__STATE, __INL__i if 'i' in vars() else __builtins__.i if hasattr(__builtins__, 'i') else None, print if 'print' in vars() else __builtins__.print if hasattr(__builtins__, 'print') else None), __INL__STATE := __INL__TEMP[0], __INL__i := __INL__TEMP[1], print := __INL__TEMP[2]], [] if __INL__STATE[1] > 1 else None] for i in range(10)], [] if __INL__STATE[1] > 0 else None]

where there is an issue: UnboundLocalError: local variable '__INL__i' referenced before assignment

Variable update in loop

test_list = [12, 67, 98, 34]

res = []
for ele in test_list:
    sum = 0
    for digit in str(ele):
        sum += int(digit)
    res.append(sum) # <= here
 
print ("List Integer Summation : " + str(res))

Problem with flow expressions in recursive while

while True:
    if True:
        break

this function terminates, but onelined

[__INL__STATE := (None, 1), [__INL__TEMP := (lambda __INL__CORE, __INL__STATE: __INL__CORE(__INL__CORE, __INL__STATE))((lambda __INL__CORE, __INL__STATE: [__INL__COND := True, [[__INL__STATE := (None, 2)] if True else None, [] if __INL__STATE[1] > 1 else None, __INL__CORE(__INL__CORE, __INL__STATE)][-1] if __INL__COND else (__INL__STATE, None)][-1]), __INL__STATE), __INL__STATE := __INL__TEMP[0]], [] if __INL__STATE[1] > 0 else None]

This does not because the return only acts by the current rec scoping

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.