[pypy-dev] Support for __getitem__ in rpython?
Simon Burton
simon at arrowtheory.com
Fri Dec 5 07:15:36 CET 2008
On Thu, 4 Dec 2008 10:15:34 +0100
"Hakan Ardo" <hakan at debian.org> wrote:
> Hi,
> I've started to play around with the pypy codebase with the intention
> to make obj[i] act like obj.__getitem__(i) for rpython objects.
Woohoo!!
> The
> approach I tried was to add:
>
> class __extend__(pairtype(SomeInstance, SomeObject)):
> def getitem((s_array, s_index)):
> s=SomeString()
> s.const="__getitem__"
> p=s_array.getattr(s)
> return p.simple_call(s_index)
>
> and then do something like:
>
> class __extend__(pairtype(AbstractInstanceRepr, Repr)):
> def rtype_getitem((r_array, r_key), hop):
> hop2=hop.copy()
> ...
> hop2.forced_opname = 'getattr'
> hop2.dispatch()
> hop3=hop.copy()
> ...
> hop3.forced_opname = 'simple_call'
> hop3.dispatch()
um...
>
> But I am having a hard time understanding the rtyper and if this is
> the right approach? Is there anything similar in the code/docs I
> could look at to get a better understanding on how to write this?
I had lots of fun last year writing code in rpython/numpy .
There is plenty of getitem goodness there. Unfortunately it
is probably impenetrable. Um. Perhaps you could revert back to
when the code was sane (but much less functional).
I also had a whack at __str__ for classes but failed horribly.
Keep pestering me and i'm likely to become interested in this stuff again.
Cheering from afar,
Simon.
More information about the Pypy-dev
mailing list