[pypy-dev] oopspec

Armin Rigo arigo at tunes.org
Wed May 3 09:22:20 CEST 2006


Hi Antonio,

On Wed, May 03, 2006 at 01:00:28AM +0200, Antonio Cuni wrote:
> I'm unsure about using 'delslice': it make me think that such an 
> operation behave exactly like the corresponding python statement, but 
> that was not my intent: in my mind the difference between 'remove_range' 
> and 'delslice' is that the first doesn't handle negative indexes and so 
> it is likely that the target has some built-in method that implement it 
> natively.

I remember thinking about this that the hint "not negative" could be
specified somewhere in addition to the basic oopspec:

    def ll_getitem_nonneg(func, l, index):
        ...
    ll_getitem_nonneg.oopspec = 'list.getitem(l, index)'
    ll_getitem_nonneg.oopspechint = {'index': '>=0'}      # <====

    def ll_getitem(func, l, index):
        ...
    ll_getitem.oopspec = 'list.getitem(l, index)'

The point is that a backend can ignore the hint and implement a general
getitem operation that accepts negatives and raises IndexError, or
select a more optimized version if it's got one when it sees the hint.

Also, note that all our slice operations at RPython level assume that
indices are non-negative, with a special exception for exactly x[:-1].
(see rslice.py)


A bientot,

Armin



More information about the Pypy-dev mailing list