[pypy-dev] List and string in ootypesystem

Armin Rigo arigo at tunes.org
Thu Apr 6 18:08:10 CEST 2006


Hi Antonio,

On Tue, Apr 04, 2006 at 10:16:32AM +0200, Antonio Cuni wrote:
> def ll_list_is_true(lst):
>     return lst is not None and len(lst) != 0
> 
> I hoped that the rtyper was smart enough to convert 'len(lst)' into my 
> low-level op 'list_len', but it wasn't: indeed, it generated code that 
> called len function for a generic PyObject* and that was not what I wanted.
> I tried to copy the implementation of 
> lltypesystem.rlist.ll_list_is_true, but I couldn't because that can call 
> the ll_lenght() method that I didn't have. Now it has no longer 
> importance, but how could I do to get thing working?

It is probably less confusing to call a method like .length() instead of
using len() at this level again.  But in both cases, you need to add
support for this in the annotator and the rtyper again -- the
ll_list_is_true() function is itself passed through both of them.

I see you added SomeOOList to annoation.model.lltype_to_annotation().
There is already a generic 'def len()' in the base class SomeObject, so
that's how the annotator is happy with your ll function's 'len(lst)'.
Fine here.  If you wanted a .length() method instead, you would need a
'def method_length()' in unaryop.py.

On the rtyper side, you need something similar to rpython/rptr.py that
maps SomeOOList back to its low-level type, with yet another Repr.  It's
this repr that must implement the operations you want to be able to use
in low-level helpers; e.g. rtype_len() if you want len(lst) to work; or
if instead you use .length() in low-level helpers, then you would need
an rtype_method_length() in the repr corresponding to SomeOOList (by
opposition to the rtype_len() in the repr corresponding to SomeList).

Nik's approach is to map lists to reguar OO classes and instances, which
are already supported in the annotator/rtyper with a similarly indirect
approach: SomeOOClass/SomeOOInstance in the annotator, which
rpython/ootypesystem/rootype.py maps back to the low-level OO types.
Just like rptr.py, this rootype.py is only needed to support low-level
helpers.


A bientot,

Armin



More information about the Pypy-dev mailing list