[pypy-dev] pow and complex object

Ben Young ben at transversal.com
Mon Jul 5 15:59:42 CEST 2004


On Monday 05 July 2004 10:33, holger krekel wrote:
> [Ben Young Mon, Jul 05, 2004 at 09:29:44AM +0100]
>
> > On Monday 05 July 2004 09:16, holger krekel wrote:
> > > [Ben Young Mon, Jul 05, 2004 at 08:54:49AM +0100]
> > > I think it's ok to add yet another special case to stdobjspace.wrap()
> > > to create a proper complex object for compiled literals. The other
> > > solution of having a proper complex object in co_consts from the start
> > > is problematic because code objects in PyPy are considered an
> > > objectspace-independent "dead" representation of the source code.
> > > When we finally do parser/compiler integration we probably should
> > > revisit this literal/wrapping issue.
> >
> > But is is possible to access module/__builtin__module from objspace/std
> > or should complex be moved into the object spaces?
>
> Basically yes, for example
>
> w_cls = space.getitem(space.w_builtins, self.wrap('complex'))
> w_obj = space.call_function(w_cls, space.newfloat(x.real),
> space.newfloat(x.imag))

Have got this all working with the standard object space, however I can't get 
it working with the trivial object space. This is because for something like
2j * 2 the standard object space coerces the 2 to a complex object and then 
multiplies it. However the trivial space calls complex.__mul__, then 
int.__mul__, both of which fail. Does something special happen here in 
cpython?

Also I can't get the trivial object space to use the complex class in 
__builtin__module, it always appears to use the cpython version. Is this 
intended? There doesn't seem to be a big list of isinstance in the wrap 
function at it all just forwards straight to the underlying object, but I 
think we want to override the underlying complex with the one in 
__builtin__module.py?

Ben
---




More information about the Pypy-dev mailing list