Can Python theoretically "decompile" in C

Since Python itself is written in C, is it theoretically possible to “decompile” any Python program in C for any reason? Not translate, (which will take the semantics of the program and write another program in C, which does the same thing), but really decompile (use the program to find the appropriate C functions for each Python operation and implement them in the syntactically correct way).

+4
source share
3 answers

Any programming language can theoretically be translated into any other programming language. This theoretical possibility says nothing about how simple it is, or whether any existing tools allow you.

This is also ambiguous, which is considered "decompilation". For example, I can use boost::pythonand embed a python program as a string in a C ++ program. Now I have a C ++ program that is completely equivalent to this python code. This is hardly considered a correct translation.

There are some things that a translator cannot do (well):

if ask_user():
    a = 1
else:
    a = "hi"
print(a)

Due to the ambiguity of the type of compilation time, any equivalent c-program must have some complex data structures with information such as runtime.

+3
source

. , c. , , c. RPython, . . .

0

Give up https://code.google.com/p/py2c/ to convert python to c.

-1
source

Source: https://habr.com/ru/post/1530052/


All Articles