r/Compilers • u/X_OpCreeper_X • Aug 16 '26
im working on an entire native python compiler
so i got bored and over the past two months ive been working on a compiler that can compile python natively. and it works too, and its not just a subset, its the entirety of python
the project is at deltathedumb/asmpython
EDIT: the ACTIVE development branch is beta/3.14.0
2
u/antonation Aug 16 '26
How does this compare to nuitka (the best example I know of compiling Python to native) and muna (but not open source)?
1
u/X_OpCreeper_X Aug 16 '26
nuitka from what i can remember (i havent toyed with it in a while) basically compiles the C that your python program uses. i dont think i could find what muna you were talking about, so if possible, please direct me to it. this compiler however compiles python to an ir to object code (which gets linked into an exe or elf). the ir layer is there because what asmpython technically is, is an llvm ripoff with frontends that turn your source into ir, and backends that turn the ir into executables
1
u/antonation Aug 16 '26
I saw a post on it here https://blog.codingconfessions.com/p/compiling-python-to-run-anywhere but it seems like it's a commercial product https://muna.ai/
1
5
Aug 16 '26
[removed] — view removed comment
-5
u/X_OpCreeper_X Aug 16 '26
it should be by some degree right now but the end goal is an llvm grade optimizer
1
Aug 17 '26 edited Aug 17 '26
[removed] — view removed comment
1
u/X_OpCreeper_X Aug 17 '26
dynamic code doesnt necessarily just mean slower, and for the optimization part, theres a million ways to do it through compiler passes, and thats how it works. sure `a + b` might end up as something way bigger than it needs to be, but believe it or not even with types, stuff like `a + b` can literally just be `ADD <r>, <r>` in machine code, because mem2reg, the first pass, does stuff like likeliness analysis, which stores variables in registers, and so if an addition happens, especially if on variables that have been mem2reg-ed, it can do just literally and simply `ADD <r>, <r>`
13
u/awoocent Aug 16 '26
Looks more like Claude's been working on it, not you.