Live data from Hacker News

A Python Interpreter Written in Python

aosabook.org

21–30 of 57 posts

Re: A Python Interpreter Written in Python

#21
post #19

> Byterun is a Python interpreter written in Python. This may strike you as odd, but it's no more odd than writing a C compiler in C. 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 r…

PyPy handled this by implementing PyPy in a restricted minimal subset of Python that they called RPython, and that seemed to work out well for them.

Re: A Python Interpreter Written in Python

#22
post #20
post #7

Earlier quoted context omitted.

PyPy is python implemented in RPython, which is technically a python subset. It's so restricted it might as well be a different language though.

> technically a python subset So it can just run under CPython? If so, then that isn't too misleading.

Yes. It can run under Cpython (2.7).

Re: A Python Interpreter Written in Python

#24
post #19

> Byterun is a Python interpreter written in Python. This may strike you as odd, but it's no more odd than writing a C compiler in C. 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 r…

This is the case only if the new interpreter does not simply include the layer that the old interpreter has for translating bytecode to native instructions. Once you have that, you can simply bootstrap any new interpreters from previous ones. Even in the case of supporting new architectures, you can still work at the Python level to produce the necessary binary, although the initial build would have to be done on an already supported architechture.

Re: A Python Interpreter Written in Python

#26
post #6
post #5

Earlier quoted context omitted.

> And, in some ways, PyPy What do you mean by that? I'm not familiar with PyPy

PyPy is python implemented in python. It is fast.

The fact that it's written in python is often brought up in order to explain its name. But really, it's much less interesting than the fact that it has a tracing JIT. If it were called PyJIT I'd bet it would be clearer and more obvious that it's fast. And people would prob get less hung up on the distinction between python/rpython.

Re: A Python Interpreter Written in Python

#29

the article glosses over something worth pausing on: the `getattr` trick for dispatching instructions (replacing the big if-elif chain) is actaully a really elegant pattern that shows up in a lot of real interpreters and command dispatchers, not just toy ones -- worth studying that bit specifically if you're building anything with extensible command sets.

Are you a bot? All your recent comments point out a thing in an article and contain LLM-isms.

Re: A Python Interpreter Written in Python

#30

the article glosses over something worth pausing on: the `getattr` trick for dispatching instructions (replacing the big if-elif chain) is actaully a really elegant pattern that shows up in a lot of real interpreters and command dispatchers, not just toy ones -- worth studying that bit specifically if you're building anything with extensible command sets.

Are you a bot? All your recent comments point out a thing in an article and contain LLM-isms.

you asking a bot if it is a bot? :)
Post reply on HN