[pypy-dev] Re: Base Object library (was: stdobjspace status)

Christian Tismer tismer at tismer.com
Wed Feb 26 19:46:12 CET 2003


Stephan Diehl wrote:

Once again on this:

> def __init__(w_self, rintval):
>         w_self.intval = rintval
> 
> where rintval is already the restricted intval.
> Am I right here?

As said, I'm not sure if rintval will be
an r_int already, it depends on the rest
of the implementation which is quite a
bit foggy to me, still.

Maybe I define intval as a slot, and give
it a setter method that always enforces
the primitive r_int type.

Also there will be a basic notation of
primitive arrays. They might be built using
the array module, but I think I like it
better to implement it using derived list
objects, with a restricted type attribute.

And then, these objects are meant to describe just
plain memory arrays, no Python objects. The are,
but they don't behave like that.

For instance, r_objectarray would be a list,
which is restricted that it only can hold
references to W_Object, or None which acts as NULL.
r_objectarray would also override Python operators
like "+" and "*", since these don't exist in
RPython's arrays: An array can only be created
once, with a fixed size. There is no concatenation
or repetition. Instead, this has to be built
upon that, in terms of the primitive arrays.

So, W_ListObject
would have some fields like
     self.objarray    # r_objectarray
     self.maxlen      # r_uint
     self.actlen      # r_uint

It has been suggested to not use maxlen, since
we could use len(self.objarray), but I believe
this is wrong to do. If we are modelling primitive
arrays, then they don't support len() at all.

Now, for example, the definition of concatenation
for our new lists could read like so:

class r_range(object):
     def __init__(self, *args):
         self.xr = xrange(*args)
         def __getitem__(self, idx):
             return r_int(self.xr[idx])

class W_ListObject(W_Object):
     __slots__ = ["objarray", "maxlen", "actlen"]
     def __init__(self, lng, data=None):
         self.objarray = newobjarray(lng)
         if data:
             for i in r_range(lng):
                 self.objarray[i] = data[i]
             self.actlen = lng
         else:
             self.actlen = 0
         self.maxlen = lng

def list_list_add(space, w_lis1, w_lis2):
     lng1 = w_lis1.actlen
     lng2 = w_lis2.actlen
     lng = lng1 + lng2
     res = W_ListObject(lng)
     for i in r_range(lng1):
         res.objarray[i] = w_lis1.objarray[i]
     for i in r_range(lng1, lng):
         res.objarray[i] = w_lis2.objarray[i]
     res.actlen = lng
     return res

Maybe this is just very rough, but give a little
an idea how things can work.

Wile we are at it, Stephan,
you wrote the longobject.py .
You are probably aware of the fact that
this implementation is slightly not what
we need?

You coded, for instance:

def long_long_sub(space, w_long1, w_long2):
     x = w_long1.longval
     y = w_long2.longval
     try:
         z = x - y   # <== ick! We don't have that!
     except Error,e:
         raise OperationError(Error, e)
     return W_LongObject(z)

This is ok, if you rely on the existance of
long objects. But for a real implementation,
we need to use integer arrays like in
longobject.c, and implement everything by
hand.

So how to fill longobject.py with real life?
I think, we first need some basic structure
like r_integerarray or maybe even better
r_uintarray, and based upon that, we must
build every and all the necessary loops.

Anybody wants to try it?

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/



More information about the Pypy-dev mailing list