Comment on Writing a C compiler in 500 lines of Python (2023)parentComments−wyldfire1yA python VM that consumes bytecode might be doable in not-ludicrous-amounts of C. Not 500 lines I suppose. But something manageable I think? Especially if you targeted the older releases.−jonjacky1yIn the CPython reference interpreter, that VM can be found athttps://github.com/python/cpython/blob/main/Python/ceval.cIt's 3619 lines. It's explained in this 515 line file:https://github.com/python/cpython/blob/main/InternalDocs/For comparison, there is a pure Python bytecode interpreter, its VM is here:https://github.com/nedbat/byterun/blob/master/byterun/pyvm2....It's 1043 lines.
Comments
A python VM that consumes bytecode might be doable in not-ludicrous-amounts of C. Not 500 lines I suppose. But something manageable I think? Especially if you targeted the older releases.
In the CPython reference interpreter, that VM can be found at
https://github.com/python/cpython/blob/main/Python/ceval.c
It's 3619 lines. It's explained in this 515 line file:
https://github.com/python/cpython/blob/main/InternalDocs/
For comparison, there is a pure Python bytecode interpreter, its VM is here:
https://github.com/nedbat/byterun/blob/master/byterun/pyvm2....
It's 1043 lines.