[pypy-dev] Support for __getitem__ in rpython?
Hakan Ardo
hakan at debian.org
Thu Dec 4 10:15:34 CET 2008
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. 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()
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?
Would it be a better solution to add an intermediate step between the
annotator and the rtyper that converts
getitem(SomeInstance,SomeObject) into
vx=getattr(SomeInstance,'__getitem__'); simple_call(vx,SomeObject)?
Any suggestions will be appreciated. Thanx!
--
Håkan Ardö
More information about the Pypy-dev
mailing list