Omyyyy/pycom: A Python compiler, down to native code, using C++(github.com)
github.com
Omyyyy/pycom: A Python compiler, down to native code, using C++
https://github.com/Omyyyy/pycom
34 comments
AFAIK, nuitka does not compile down to static executables. Just a heads up.
is it faster than interpreted cpython? couldn't find the benchmarks, maybe I'm blind
People, before you decide to trash this project, keep in mind that whoever wrote it is probably not the same person that posted the link on HN. They have not asked for your highly critical feedback on their two-weeks-old project.
The author did, however, post it to Reddit, and they specifically asked for feedback there.
https://www.reddit.com/r/Python/comments/w7vlim/i_made_a_pyt...
https://www.reddit.com/r/Python/comments/w7vlim/i_made_a_pyt...
My point exactly. They specifically solicited feedback from r/python and not from Hacker News.
i just want a transpiler to c++ that doesn't require curly braces, or semi colons, and other weird symbols. oh and handles strings and memory safely for me
I'm curious about the opposite direction. Is there C compiler or transpiler targeting either the Python VM or native Python code?
I know there is a rich history of projects targeting the JVM, but I could not find anything regarding Python.
Doesn't matter if it is heavily restricted, incomplete, just supports a subset of C or if it is just a research project. All projects targeting the JVM I encountered are like this.
For me it is not so much about a solution but more about the question why apparently everyone is interested in the JVM and no one tackled Python.
I know there is a rich history of projects targeting the JVM, but I could not find anything regarding Python.
Doesn't matter if it is heavily restricted, incomplete, just supports a subset of C or if it is just a research project. All projects targeting the JVM I encountered are like this.
For me it is not so much about a solution but more about the question why apparently everyone is interested in the JVM and no one tackled Python.
Possible reasons:
1. The JVM executes bytecode much (~10 times) faster than the CPython VM.
2. Unlike the JVM, the CPython VM and bytecode are not compatible with older or newer versions of CPython. (The differences are small, but they add up, increading maintenance costs.)
1. The JVM executes bytecode much (~10 times) faster than the CPython VM.
2. Unlike the JVM, the CPython VM and bytecode are not compatible with older or newer versions of CPython. (The differences are small, but they add up, increading maintenance costs.)
The only project that compares 1:1 is Pythran: https://github.com/serge-sans-paille/pythran
Pythran is fairly nice, and it really does work. I tried it last year and it compiles down to modifiable templated C++. I was able to use it to build Python for a highly specialized environment.
All the others compile down to dynamically linked binaries, and that just puts them in the "other" box.
Pythran is fairly nice, and it really does work. I tried it last year and it compiles down to modifiable templated C++. I was able to use it to build Python for a highly specialized environment.
All the others compile down to dynamically linked binaries, and that just puts them in the "other" box.
It would be nicer to have it written in Python, and eventually bootstrap itself.
Anyway, good luck with project.
Anyway, good luck with project.
This looks amazing. I’ve been hoping for something like this to come out for awhile. With the recent wave of Python type hinting I always felt like it should be possible to compile type hinted Python
I also wonder why people don't just use a language which is statically typed if that's something they actually want / need?
That’s completely valid. I do the bulk of my work in my current internship in Machine Learning & Data Science codebases and there is no other language which has anything close to the ecosystem of libraries/tooling that Python has in this domain while also being a suitable general purpose programming language. I don’t have much experience with Matlab/Mathematica but I hear Matlab is decent for Machine Learning - but I don’t want to have vendor lock-in. That leaves me with C++ or Julia. C++ is not the most ergonomic language and adding manual memory management isn’t an ideal. Julia looked promising and I have heavily considered taking a deep dive, but ended up being deterred [0] - I feel like these are pretty major problems to exist for a language of this point in maturity.
[0] https://yuri.is/not-julia/
[0] https://yuri.is/not-julia/
Python has better libraries and faster turnaround. It would be handy if you could write something without using type hints as a quick prototype, and then add them in for a performant releasable product. It would also help with distribution of python code (distribute the binary), which isn't as strong as python's other features.
Sometimes I wonder if people who say this have tried something like Go?
The way I think about it is like this, if you want to really just hack something together, why do you care about static typing?
If you're building a serious larger code base, you then might want static typing, so then why not use a statically typed language?
The way I think about it is like this, if you want to really just hack something together, why do you care about static typing?
If you're building a serious larger code base, you then might want static typing, so then why not use a statically typed language?
Go looks very promising, particularly for web services / networking oriented programs. I don’t have much experience / knowledge about Go, does it have a comparable ability to write the kind of expressive, elegant code that Python can with its list/dict comprehensions, operator overloading, generators, etc.
Because python is #2 on the most used languages list, has great tooling, IDE support, has been around for 30+ years.
It's been used to build serious large scale projects.
The idea is that you can get great runtime performance by transpiling. This is how Facebook worked till 2013-2014 (php -> C++ transpiler).
It's unfortunate that google abandoned the grumpy project. But many good alternatives around.
It's been used to build serious large scale projects.
The idea is that you can get great runtime performance by transpiling. This is how Facebook worked till 2013-2014 (php -> C++ transpiler).
It's unfortunate that google abandoned the grumpy project. But many good alternatives around.
There are reasons it's #2 on that list, because there's a lot of shit python code out there. Not all of it is Instagram (Django).
Probably the most atrocious code I've ever seen has been PHP followed by Python.
I use Python personally, I just don't think it's a good choice if you really want a statically typed language...because it's not statically typed.
Probably the most atrocious code I've ever seen has been PHP followed by Python.
I use Python personally, I just don't think it's a good choice if you really want a statically typed language...because it's not statically typed.
There's no need to paint typing as a black and white picture. Basically all of the major Common Lisp implementations are compiled yet allow for typing in order to let the compiler emit better machine code (e.g. the compiler doesn't need to insert runtime type checks or use generic arithmetic when adding two u16s and storing the result in a u32). It's nice being able to use dynamic types for prototyping then gradually adding types later for better optimization by the compiler.
Try py2many may be? 7-8 supported target languages, although it began with c++14 as the py14 project.
How does it compare to ShedSkin (other than supporting more recent versions of Python)? https://github.com/shedskin/shedskin
This doesn't actually seem any better than Cython and is, in my opinion, many many years behind it. What am I missing here?
Nothing. I don't mean to insult the author with this, but he is a 15 year old with a month old project. It's a toy. Toys are great, and teenagers attempting something like this is outstanding, but they are toys.
This parses the python and more or less does one for one text replacement. That's a strategy that doesn't scale. It doesn't handle any of Python's dynamic features (x=1, wait, now x="hi" and all the rest), on and on. His claims of 20x speed are based on super simple functions; these numbers will not scale into real scripts/programs. It cannot compile most of the standard lib. It doesn't handle classes, or exceptions. Basically you get simple if/while/for constructs and def func().
His claims that it is faster/better than other mature projects that do work are hubris. Excusable perhaps because of his age, but time to learn.
Lots of assertions on my part, but I'm basing it on this reddit thread: https://www.reddit.com/r/Python/comments/w7vlim/i_made_a_pyt...
Omyyyy, if you are reading this, I'm impressed you got as far as you did, and are continuing to work on it, and don't intend to belittle you. But you are way overselling it and I'm pretty sure you don't understand how you have painted yourself into a corner you cannot get out of due to the simplistic conversions you are doing. Buy a compiler book and start reading!
This parses the python and more or less does one for one text replacement. That's a strategy that doesn't scale. It doesn't handle any of Python's dynamic features (x=1, wait, now x="hi" and all the rest), on and on. His claims of 20x speed are based on super simple functions; these numbers will not scale into real scripts/programs. It cannot compile most of the standard lib. It doesn't handle classes, or exceptions. Basically you get simple if/while/for constructs and def func().
His claims that it is faster/better than other mature projects that do work are hubris. Excusable perhaps because of his age, but time to learn.
Lots of assertions on my part, but I'm basing it on this reddit thread: https://www.reddit.com/r/Python/comments/w7vlim/i_made_a_pyt...
Omyyyy, if you are reading this, I'm impressed you got as far as you did, and are continuing to work on it, and don't intend to belittle you. But you are way overselling it and I'm pretty sure you don't understand how you have painted yourself into a corner you cannot get out of due to the simplistic conversions you are doing. Buy a compiler book and start reading!
> Buy a compiler book and start reading!
so what's a good first book for a 15 year old to pick up?
so what's a good first book for a 15 year old to pick up?
Omyyyy, if you are reading this, these may seem harsh comments but they are very good. If you have been able to code your project that far, then you're ripe to get serious about the stuff. Go read books, you'll be amazed !
Cython doesn't consume python3 type hints and needs special type hints of its own. But it's certainly more mature than other players in the field.
What we need is a rpython suitable for app programming and a stdlib written in that dialect.
https://github.com/py2many/py2many/blob/main/doc/langspec.md
What we need is a rpython suitable for app programming and a stdlib written in that dialect.
https://github.com/py2many/py2many/blob/main/doc/langspec.md
> doesn't consume python3 type hints
Mypyc ships with mypy and does this. Mypy itself and Black are compiled with it.
https://github.com/python/mypy/tree/master/mypyc
Mypyc ships with mypy and does this. Mypy itself and Black are compiled with it.
https://github.com/python/mypy/tree/master/mypyc
Looks interesting. Does this support Threading and/or Multiprocessing? Just looking at the readme, my guess would be no, but I might have a use for it if so.
>>How does it handle type instability, i.e. when the type of a variable is only known at run-time, not at compile-time?
>c++’s extremely convenient ‘auto’ keyword :)
https://www.reddit.com/r/Python/comments/w7vlim/i_made_a_pyt...
>c++’s extremely convenient ‘auto’ keyword :)
https://www.reddit.com/r/Python/comments/w7vlim/i_made_a_pyt...
[deleted]
https://nuitka.net/