Python bytecode, interpreter and virtual machine

This is a very big question, and I'm mostly looking for resources where I can learn more about the following.

I know that the python interpreter is written in C and creates bytecode to run on the python virtual machine, also written in C (right?). My question is, is it possible to implement both of them in python itself? I assume that I'm going with this (technical) ability to write something like an OS in python, especially WITHOUT static compilation of anything?

If I understand correctly, python does not have assembler, which should also be written in python. Is this something technically possible (maybe?) To do? Or is python dynamic typing a problem?

I am a little versed in microprocessor architecture, assembly and machine codes, as the recent EE course is studying at school. But I get lost looking at the whole picture for higher level languages ​​like python.

+4
source share
4 answers

First you need to write a Python compiler (not an interpreter) in any language, preferably Python. The first start of the compiler should be done through the interpreter.

Then you compile your compiler with yourself, which will lead to the creation of your own compiler, which does not need an interpreter.

You can then use the compiler to compile any Python into your own code.

This process is called bootstrapping and is used by many, if not most, major compilers for many languages.

You can read more about this here: http://en.wikipedia.org/wiki/Bootstrapping_ (compilers)

Regarding the creation of the operating system, you will need to implement at least the Python interpreter if you want to avoid the compiled code. If you write the Python interpreter as a microkernel, you can write the rest of the operating system in Python. (Editing: I just accidentally described Cleese, which Jiaaro mentioned :))

+3
source

A compiler, not an interpreter. But you are looking for PyPy .

+9
source

James Tauber also built a proof of concept of the OS in python called Cleese and recently began to strengthen his work on Pypy (a python interpreter written in python)

+2
source

Regarding the issue of OS implementation, you need a system programming language for OS implementation. Doing all this in pure python will not be possible if you cannot come up with python assembler and convert python to executable files that are not needed by VM.

If you want to code in the assembly and get python to build it for you, check out the slightly outdated and experimental pyasm .

+1
source

All Articles