[pypy-dev] pow and complex object
hpk at trillke.net
Mon Jul 5 10:16:30 CEST 2004
[Ben Young Mon, Jul 05, 2004 at 08:54:49AM +0100]
> Ah, I think I have found the problem! pow(complex(0, 2), 2) does return the
> correct result, however stdobjspace.wrap(2j) does not return a complex
> object, it returns a cpython object. Is there a way to plug factory functions
> into the object space from the module directory or should the complex object
> be lifted to the level of int and long, and be put in the object space?
Right, the underlying problem is that we reuse the co.co_consts objects
as compiled by the python compiler. The literal "2j" is represented as a
cpython-object in co_consts and the implementation of LOAD_CONST invokes
stdobjspace.wrap(cpython_complexobject) which does a
cpythonobject-wrapping instead of creating a proper builtin-level
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.
> There also appears to be a problem with pow in general, but I will look at
> this separately.
More information about the Pypy-dev