Re: python to C code generator
On Tue, 23 Jan 2018 17:43:18 +, bartc wrote: > It wouldn't be a satisfactory way of writing C programs. So, although > I'm not that big a fan of C syntax, it might be better to write C as C, > and Python as Python, to avoid confusion.) This. The fundamental reality is that `a + b` means different things in C and Python. Even if you limit yourself to integers and not arbitrary values (fractions, lists, strings, etc) the semantics are different: - in C, ints have a fixed number of bits and any addition which ends up out of range is undefined behaviour[1]; - while Python uses BigInts, overflow is impossible, and the only possible error is that you run out of memory and an exception is raised (although the addition can take an indefinite long amount of time). Often the difference doesn't matter... but when it does matter, it *really* matters. [1] If anyone thinks that it is addition with overflow, you are wrong. Some C compilers *may* use overflow, but the language strictly defines it as undefined behaviour, so the compiler can equally choose to set your computer on fire[2] if it prefers. https://blog.regehr.org/archives/213 [2] http://www.catb.org/jargon/html/H/HCF.html -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
On 23/01/2018 13:34, bartc wrote: 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. Or rather, 'a=b+c;' (I've written source to source translators, some of which could target C, but not Python to C. It would be feasible to write C code in a syntax that looks rather like Python, but it won't be real Python, and you can't run it as Python. It wouldn't be a satisfactory way of writing C programs. So, although I'm not that big a fan of C syntax, it might be better to write C as C, and Python as Python, to avoid confusion.) -- bartc -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
On Wed, Jan 24, 2018 at 1:45 AM,wrote: > Hey Ally, > > Cython adds a big chunk of complexity to simple things. That's the problem. That's like saying "Unicode adds a big chunk of complexity to the simple task of translating a word from Japanese into Russian". No, it doesn't; the complexity is inherent in the problem. You cannot translate Python code into C code without either (a) reimplementing all of Python's semantics, as Cython does; or (b) drastically changing the semantics, such that even the very simplest of code might behave quite differently; or (c) manually reading through the code and writing equivalent C, which is what you might call "porting" or "rewriting". (Or possibly "prototyping", if the intention was always to transform it into C.) There is fundamentally NO easy way to translate code from one language into another and get readable, idiomatic code at the other end. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
Hey Ally, Cython adds a big chunk of complexity to simple things. That's the problem. Greetings. On 01/23/2018 01:54 PM, ally.m...@bankmail.host wrote: Have you tried cython ? On 01/23/2018 01:25 PM, 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 hi, I have found nuitka as asuitable candidate but it seems that nuitka doesnt generate a simple C code which could be included as a C file in another program.Is there any alternative easier way regarding this? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
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 ok so which python tool would be the best one which can be included and parameters can be passed to from another C code file -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
Id go this way too. Basic C is straightforward. I usually consider learning a new "thing " if the time to support potwntially combersome solution using existing methods justifies the effort. On Jan 23, 2018 09:01, "Ned Batchelder"wrote: > On 1/23/18 8:48 AM, kushal bhattacharya wrote: > >> On Tuesday, January 23, 2018 at 7:05:02 PM UTC+5:30, bartc wrote: >> >>> 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 >>> >> >> This is exactly what i meant to say.My goal is to translate the python >> code into its C equivalent with function name as it is. >> > > The best way to do that is to read the Python code, understand what it > does, and re-write it in C. You won't find an automatic tool that can do > the job you want. The semantics of Python and C are too different. > > --Ned. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
You can look at SymPy code generator http://docs.sympy.org/latest/modules/utilities/codegen.html Perhaps this is exactly what you need. With kind regards, -gdg 2018-01-23 17:00 GMT+03:00 Ned Batchelder: > On 1/23/18 8:48 AM, kushal bhattacharya wrote: > >> On Tuesday, January 23, 2018 at 7:05:02 PM UTC+5:30, bartc wrote: >> >>> 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 >>> >> >> This is exactly what i meant to say.My goal is to translate the python >> code into its C equivalent with function name as it is. >> > > The best way to do that is to read the Python code, understand what it > does, and re-write it in C. You won't find an automatic tool that can do > the job you want. The semantics of Python and C are too different. > > --Ned. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
On 1/23/18 8:48 AM, kushal bhattacharya wrote: On Tuesday, January 23, 2018 at 7:05:02 PM UTC+5:30, bartc wrote: 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 This is exactly what i meant to say.My goal is to translate the python code into its C equivalent with function name as it is. The best way to do that is to read the Python code, understand what it does, and re-write it in C. You won't find an automatic tool that can do the job you want. The semantics of Python and C are too different. --Ned. -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
On Tuesday, January 23, 2018 at 7:05:02 PM UTC+5:30, bartc wrote: > 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 This is exactly what i meant to say.My goal is to translate the python code into its C equivalent with function name as it is. -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
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 -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
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 -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
What about Cython? On 01/23/2018 01:25 PM, 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 hi, I have found nuitka as asuitable candidate but it seems that nuitka doesnt generate a simple C code which could be included as a C file in another program.Is there any alternative easier way regarding this? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
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 hi, I have found nuitka as asuitable candidate but it seems that nuitka doesnt generate a simple C code which could be included as a C file in another program.Is there any alternative easier way regarding this? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
On 17/01/2018 11:04, kushal bhattacharya wrote: Hi, Is there any python framework or any tool as which can generate C code from python code as it is . What C code would you expect to see from this line of Python: a = b + c ? -- https://mail.python.org/mailman/listinfo/python-list
Re: python to C code generator
Hi, Have a look at Cython. Best 2018-01-17 12:04 GMT+01:00 kushal bhattacharya: > Hi, > Is there any python framework or any tool as which can generate C code from > python code as it is . > > Thanks, > Kushal > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
python to C code generator
Hi, Is there any python framework or any tool as which can generate C code from python code as it is . Thanks, Kushal -- https://mail.python.org/mailman/listinfo/python-list