[pypy-dev] C interpreter written in Python, and running CPython on top of PyPy

Celil celil.kj at gmail.com
Fri Jan 6 15:59:57 CET 2012

I have been thinking about the possibility of creating a C interpreter 
in Python.

Is anybody already working on that? With PyPy this would presumably be 
quite easy to do. The interpreter will load the C code, create an AST 
(presumably using pyparsing and the EBNF spec of the C-language), and 
then populate the Flow Object Space with all the C objects, and create a 
control flow graph of the application logic. This graph will containe 
low level lltype objects, and can then be directly connected to the 
RPython flow-graph generated after the RTyper step. This would allow for 
seamless interoperability between C and PyPy, and would also greatly 
simplify the task of porting existing CPython extensions such as numpy.  
Rather than going through the error prone task of translating the whole 
code base into RPython, one will be able to simply load the exiting C 
source code and integrate it directly into the RPython flow graph. It 
will be possible to import *.h and *.c files directly without any 
compilation, and they will run nearly as fast thanks to PyPy's JIT 

This would also allow us to do things like running CPython on top of 
PyPy. Right now it is possible to run PyPy on top of CPython, but the 
reverse is not. If CPython could be run on top of PyPy by interpreting 
its C source code that would be truly amazing. Interpreting C code would 
greatly help CPython developers by freeing them from the task of having 
to repeatedly compile their code.


More information about the pypy-dev mailing list