A Python Interpreter Written in Python
Posted by xk3 3 days ago
Comments
Comment by BoppreH 5 hours ago
I'm not so sure. The difference between a self-hosted compiler and a circular interpreter is that the compiler has a binary artifact that you can store.
With an interpreter, you still need some binary to run your interpreter, which will probably be CPython, making the new interpreter redundant. And if you add a language feature to the custom interpreter, and you want to use that feature in the interpreter itself, you need to run the whole chain at runtime: CPython -> Old Interpreter That Understand New Feature -> New Interpreter That Uses New Feature -> Target Program. And the chain only gets longer, each iteration exponentially slower.
Meanwhile with a self-hosted compiler, each iteration is "cached" in the form a compiled binary. The chain is only in the history of the binary, not part of the runtime.
---
Edit since this is now a top comment: I'm not complaining about the project! Interpreters are cool, and this is genuinely useful for learning and experimentation. It's also nice to demystify our tools.
Comment by gwerbin 3 hours ago
Comment by SJC_Hacker 2 hours ago
Comment by anitil 8 hours ago
I think because python is a stack-based interpreter this is a really great way to get some exposure to how it works if you're not too familiar with C. A nice project!
Comment by blueybingo 6 hours ago
Comment by vachanmn123 5 hours ago
Comment by jgbuddy 37 minutes ago
eval(str)
Comment by tekknolagi 8 hours ago
Comment by bjoli 8 hours ago
It makes me sad that I have to write C to make any meaningful changes to Python. Same goes for ruby. Rubinius was such a nice project.
Hacking on schemes and lisps made me realize how much more fun it is when the language is implemented in the language itself. It also makes sure you have the right abstractions for solving a bunch of real problems.
Comment by anitil 8 hours ago
What do you mean by that? I'm not familiar with PyPy
Comment by nxpnsv 8 hours ago
Comment by wyldfire 1 hour ago
Comment by notpushkin 8 hours ago
It lags behind CPython in features and currently only supports Python versions up to 3.11. There was a big discussion a month ago: https://news.ycombinator.com/item?id=47293415
But you can help! https://pypy.org/howtohelp.html
Comment by Doxin 8 hours ago
Comment by bjoli 6 hours ago
Comment by Doxin 5 hours ago
Comment by actionfromafar 5 hours ago
Shedskin is very nearly Python compatible, one could say it is an implementation of Python.
Comment by throwpoaster 1 hour ago
cf: https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_Ref...
Comment by gield 3 hours ago
Comment by em-bee 18 minutes ago
the text is based on python 3.5 which was released in 2015
other discussions:
https://news.ycombinator.com/item?id=16795049
Comment by woadwarrior01 7 hours ago
Comment by mapontosevenths 2 hours ago
Comment by andltsemi3 6 hours ago
Comment by kevinten10 6 hours ago
Comment by hcfman 8 hours ago
Comment by dnnddidiej 6 hours ago