Question

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

I know the python interpreter is written in C and produces bytecode to be run on the python virtual machine also written in C (right?). My question is would it be possible to implement both of these in python itself? I guess where I'm going with this is the (technical) possibility of writing something like on OS in python, particularly WITHOUT statically compiling anything?

If I understand correctly, python doesn't have an assembler which would have to be written as well in python. Are these things something that could technically (feasibly?) be done? Or would the dynamic typing of python pose some kind of problem?

I know a bit about microprocessor architecture, assembly and machine code, what a recent EE grad learns in school. But I get lost looking at the whole picture for higher level languages like python.

Was it helpful?

Solution

You would first need to write a Python compiler (not interpreter), in any language, preferably Python. The first run of the compiler would need to be run throught the interpreter.

You would then compile your compiler with itself, leading to a native compiler that needs no interpreter.

You could then use the compiler to compile any Python to native 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 process here: http://en.wikipedia.org/wiki/Bootstrapping_(compilers)

As for creating an operating system, you would need to implement, as a bare minimum, a Python interpreter, if you want to avoid compiled code. If you write a Python interpreter as a microkernel, you could write the rest of the operating system in Python. (Edit: I just inadvertently described Cleese, which Jiaaro mentioned :))

OTHER TIPS

Compiler, not interpreter. But you're looking for PyPy.

James Tauber has also built a proof of concept OS in python called Cleese, and has recently begun an effort to get it working on Pypy (python interpreter written in python)

Regarding the OS implementation question, you need a system programming language to implement an OS. Doing it all in pure python will not be possible unless you can dream up a python assembler and convert python to directly executable binaries no VM needed.

If you want to code in assembly and get python to assemble it for you, have a look at slightly dated and experimental pyasm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top