[pypy-dev] Avoiding code duplication

Armin Rigo arigo at tunes.org
Sat Apr 15 14:59:39 CEST 2006

Hi Antonio,

On Sat, Apr 15, 2006 at 12:59:07PM +0200, Antonio Cuni wrote:
> I saw that 'oopspec' attributes, but I didn't understand the exact 
> semantic;

The oopspec string tells what is the "abstract" list operation that this
particular ll_*() function implement.  For example:

    def ll_prepend(l, newitem):
    ll_prepend.oopspec = 'list.insert(l, 0, newitem)'

means that ll_prepend() is equivalent to an insert with the index set to
zero.  In the stirng, the pseudo-arguments between the ( ) are either
real argument names of the ll_ function, or constants.

So for example, if a backend has got its own way to implement the
insert() calls in general, it could figure out from the oopspec that the
ll_prepend() helper can be replaced by a custom stub invoking the
backend's own version of insertion with an index of 0.  That's
essentially what the JIT does -- see handle_highlevel_operation() in

A bientot,


More information about the Pypy-dev mailing list