[pypy-dev] Restricted language

Armin Rigo arigo at tunes.org
Tue Jan 21 12:13:52 CET 2003

Hello Rocco,

On Mon, Jan 20, 2003 at 10:39:04PM -0500, Rocco Moretti wrote:
> So if I understand you correctly, we should not use (either explicitly
> or implicitly) any of the special methods of the objects we create for
> the interpreter. The only acceptable use is member dereferencing
> (object.attribute).

Yes, indeed.  To avoid confusion the host objects (CPython objects) should not
define special methods.  We should define our own set of methods, althought it
can be as straightforward as using the canonical name and dropping "__".  So
custom list implementations would define a "getitem()" method and not a
"__getitem__()" one.

Another way to see this important distinction is by closely following the
CPython core declarations.  Wherever there is a "PyObject*", it means that the
core is handling an application-level object (which we have to translate into
an application-level object, like an ImmediateObject).  Wherever there are
other C data types, it is interpreter-internal data.  The application-level
"__getitem__()" method corresponds to:

  PyObject* PyObject_GetItem(PyObject* object, PyObject* index);

This function is not called "__getitem__"; there is only a similarity in the
name.  The function does not take an integer index (i.e. an "int"), but an
application-level "PyObject*".

It is exactly the same in our case: we need a "getitem(self, v_index)" method
whose name merely reminds us about "__getitem__", and taking as index argument
not an integer, but another object implementing an application-level object
(which might be an ImmediateObject() containing an integer).

> P.S. In your implementation of EPython exceptions, how would associated
> traceback objects be handled?

If we decide to use attributes of the EPython instance to store the
application-level exception type and value, then the traceback could also be
there.  In the main loop, when an EPython exception is caught, its traceback
info would be updated.  In fact this description is just what one would
explain to describe what the PyTraceBack_Here() call in ceval.c does.

A bientôt,


More information about the Pypy-dev mailing list