[Python-Dev] Porting information
"Martin v. Löwis"
martin at v.loewis.de
Tue Sep 4 05:33:10 CEST 2007
> I've started by looking at the parser portion of the code. However I am
> not certain this is the best place to start. Since there are so many
> ports I assume there is a well trodden path to completing this kind of
I believe this assumption is wrong. There are not many ports, only a
handful (or less - Jython, IronPython, PyPy). While Jython and
IronPython may have similar implementation strategies, I would expect
that PyPy took an entirely different approach.
In any case, there certainly is a step that you apparently failed
to perform as the very first step: set some explicit goals. What
kind of compatibility do you want to achieve in your port, what
other goals would you like to follow?
IOW, why is IronPython not what you want (it *is* a port of CPython
to C#, in a sense), and why is the C# support in PyPy not good enough
> I would prefer to break the task into portions that can be verified
> (tested for correctness) independently or as a stack (one on top of the
> next). That way I can catch errors early and have more confidence in
> what I am creating.
As I don't know what you want to achieve, it is difficult to tell
you what steps to take.
I assume your implementation would be similar to CPython in that
it uses the same byte code format. So one path would be to ignore
the compiler at all, and assume that the byte code format is given,
i.e. start with port ceval.c.
I'm not sure whether you also want to provide the same low-level
API (i.e. whether you want to provide "Embedding and Extending");
it surely can't be the *same* API, since your's will be C#, whereas
CPython's is, well, C. If you implement ceval.c, you will find
quickly that you need much of the Objects folder, so implementing
the 10 or so most important objects would be the natural starting
point (type, int, string, tuple, dict, frame, code, class, method -
assuming you would target Python 1.5 first, i.e. no bool, cell,
descr, gen, iter, weakref, unicode, object).
> When I looked through the test suites they all seem to be written in
> Python. Is there a test suite for the core of CPython i.e. before the C
> code can interpret Python code?
Yes and no. The core Python is tested through compilation - if it
compiles without warnings on the relevant compilers, it is considered
good enough to run the Python test suite. For selected features of
the interpreter, there are specific tests, in particular test_capi.
The core of CPython (compiler, objects, builtins) is then tested
through Python code.
More information about the Python-Dev