Byte-run: a Python interpreter written in Python

BartC bc at freeuk.com
Fri Jan 13 13:07:33 EST 2017


On 13/01/2017 17:08, Ian Kelly wrote:
> On Fri, Jan 13, 2017 at 3:46 AM, Steve D'Aprano
> <steve+python at pearwood.info> wrote:
>>
>> http://aosabook.org/en/500L/a-python-interpreter-written-in-python.html
>
> Neat. But not really surprising IMO that it can fit into 500 lines,

If there are still 120 or so byte-codes, then that's just 4 lines on 
average to implement each byte-code, which is pretty good going.

Even when it turns out that the actual code on github is 1000 lines 
rather than 500! Maybe it grew a bit since the 500 lines was quoted.

But it's still 8 lines per byte-code.

> since it doesn't handle compiling Python into bytecode (which is the
> hard part)

I disagree that that's the hardest part. But it was probably not very 
interesting for this project. Implementing the runtime environment, the 
object system, type-dispatchers, error-handling, symbol tables, garbage 
collection and all the rest would be more challenging.

> and doesn't include libraries. There doesn't seem to be
> much purpose to this other than it being a toy project written for a
> book.

Being educational would be enough of a point.

-- 
Bartc


More information about the Python-list mailing list