python to C code generator

bartc bc at freeuk.com
Tue Jan 23 08:34:50 EST 2018


On 23/01/2018 13:23, kushal bhattacharya wrote:
> On Wednesday, January 17, 2018 at 4:34:23 PM UTC+5:30, kushal bhattacharya wrote:
>> Hi,
>> Is there any python framework or any tool as  which can generate C code from python code as it is .
>>
>> Thanks,
>> Kushal
> 
> yes i have but it generates a complex C code with python dependencies.I want to call the generated function from another C code but i Cant figure out how to do that

Because the translation isn't simply defined.

I've just tried nuitka on the Python code 'a=b+c', and it generates 2400 
lines of C. The main purpose seems to be to generate a self-contained 
executable corresponding to the Python, but generating first a C 
equivalent then using a C compiler and linker.

This equivalent code may just contain all the bits in CPython needed to 
do the job, but bypassing all the stuff to do with executing actual 
byte-code. But it also seems to do some optimisations (in the generated 
C before it uses C compiler optimisations), so that if static types can 
be inferred it might make use of that info.

Perhaps you simply want to use Python syntax to write C code? That would 
be a different kind of translator. And a simpler one, as 'a=b+c' 
translates to 'a+b+c;' in C.

-- 
bartc




More information about the Python-list mailing list