3 ms·
Just in case anyone doesn't know, there's actually a real, live project that does this: https://pypy.org/ https://pypy.org/ (Technically the base interpreter
by asperous 9y ago
Just in case anyone doesn't know, there's actually a real, live project that does this:
https://pypy.org/ https://pypy.org/
(Technically the base interpreter is a subset/restricted version of Python however). The reason this is done (my understanding), is that a the python source code for the base interpreter can be fed into a JIT generator, which produces a Python interpreter that can perform JIT optimizations.
- masklinn 9y ago> Technically the base interpreter is a subset/restricted version of Python however The base interpreter is written in a subset/restricted version of Python, but it's still Python. You can run Pypy as an interpreter on top of CPython or pypy. And IIRC the restrictions mostly have to do with static type inference so you're mostly limited in how dynamic/weird the program gets the other big limits being magic methods being unavailable (for user-defined types) and most of the stdlib being off-limits. So it's Python in a straightjacket, but for most interpreter implementations it's probably fine, as long as you're not using an overly interesting parsing strategy (hello pratt parsers) an interpreter tends not to use the more dynamic/odd corners of the language I think.
- xapata 9y agoThere's also interesting pieces like sections not in try/except have reduced checking for out-of-bounds and type mismatch. I don't grok it yet, mostly because I've had no need to use that flavor of Python. But in some ways it's providing flexibility instead of constraints. Flexibility for the interpreter, not necessarily the programmer.
- sametmax 9y agoYes but pypy is designed for speed, not for simplicity. The source code is very, very hard to understand. cPython is the reference implementation, and has an explicity goal of being easier to understand. Yet, some part of it are quite obscure. So here we are, with this beautiful blog post