Implementing Python

about | archive

[ 2005-June-06 14:05 ]

Python is a neat programming language. One of the things I like about it is that nearly everything in it is a collection of (attribute, value) pairs. For example, a module really just contains a set of (string, object) values. So is an object. This means that you can support the Python programming language with a very small set of basic operations. The operations I believe are required are:

Additionally, you must support the following fundamental types:

I believe that if you create a run-time system that supports these features, you can implement the entire Python language. Essentially, the task then becomes creating a compiler that emits the correct combination of these operations for specific language features. For example, a function call must look up the function object in the local or global scope, and possibly in the special __builtins__ module. I am really tempted to try and hook up the new Python parser infrastructure to LLVM in order to create a compiler that executes Python as native code. However, this is quite similar to the PyPy project, and I don't really have time for this anyway.