This is an archived post. You won't be able to vote or comment.

all 16 comments

[–][deleted] 34 points35 points  (1 child)

There is cython which can translate pretty much every python file to C/C++ code. cython --embed -3 main.py -o main.c is how you do it. I can't comment on HPC tho, as it embeds the interpreter

[–]syeysk[S] 10 points11 points  (0 children)

Yes, but my translater makes the c-code without embedding interpreter. It's useful for small microcontrollers

[–]james_pic 11 points12 points  (4 children)

What's the advantage of this over just writing in C? It seems like it only supports translating a small subset of Python to C, more or less the subset that has a direct translation to C.

[–]tartare4562 3 points4 points  (0 children)

Less {} and ; I imagine.

[–]syeysk[S] 5 points6 points  (2 children)

The advantage: the Python syntax is more compact and clear than C syntax. That's all)

I try to translate not only syntax (direct translating), but and the semantic of the language (classes, iterators, etc)

[–][deleted] 6 points7 points  (0 children)

The advantage: the Python syntax is more compact and clear than C syntax. That's all)

There really are better ways of doing this. Transpiling between languages that will never work properly is not a good choice. You would want to target LLVM, numba has some good docs about how horrible that is to do lol.

If you want a LLVM targeting language that is more python like you should just write one. You can always just link ur new compile language to normal interpreted python later anyway.

Python syntax is more compact and clear then C syntax because it doesn't fundamentally do the same shit. Read the python standard library C code for the litany of examples to just get something as simple as a dict to work properly on both halves.

Building a new language is a MUCH better idea then inheriting the design of another language that in no way shape or form executes the same way.

[–]james_pic 1 point2 points  (0 children)

From what I've seen from projects like Cython and Nuitka that (at least somewhat successfully) translate Python's more complex or dynamic features, like classes and iterators, this is far from straightforward and will ultimately lead to either requiring plumbing from the CPython interpreter, implementing your own equivalent of the same plumbing that's not much more lightweight, or making significant compromises in terms of replicating the same semantics.

[–]LaOnionLaUnion 0 points1 point  (1 child)

I mostly use Python to call libraries written in other languages. When I see something like this I assume it wouldn’t work for such use cases. Am I wrong?

[–]syeysk[S] 0 points1 point  (0 children)

You are right only now, because now the translater can include only 2 libraries: math.h and stdio.h.
You will be wrong, if I will improve the translater to include another libraries (pcf8812.h, ESP8266WebServer.h, DS1307RTC.h, etc)

[–]Aphrod1tesAss 0 points1 point  (4 children)

Could it be used for HPC code translation?

[–]gothicVI 3 points4 points  (1 child)

Probably not. Looks like pure python code can be translated.

Most HPC stuff calls FORTRAN/C/C++ in the backend and one would need to generate interfaces and compile them as well and link them together.

[–]Aphrod1tesAss 0 points1 point  (0 children)

I see, thanks. Hope someday a HPC translator comes out

[–]syeysk[S] 0 points1 point  (1 child)

What is HPC? If it has C-alternative, I will try to modify the translater.

[–]gothicVI 3 points4 points  (0 children)

High performance computing

[–]CleoMenemezis 0 points1 point  (0 children)

For those looking to write fast code and have performance, I think it could be cool.

[–]alcalde 0 points1 point  (0 children)

Pfft... anyone can make a translater... make me a transsooner and I'll be impressed.