Author: Manuel Jacob
Branch: remove-tuple-smm
Changeset: r64413:0fc0f446a6f7
Date: 2013-05-22 00:45 +0200
http://bitbucket.org/pypy/pypy/changeset/0fc0f446a6f7/
Log: Remove tuple from multi-method table.
diff --git a/pypy/objspace/std/model.py b/pypy/objspace/std/model.py
--- a/pypy/objspace/std/model.py
+++ b/pypy/objspace/std/model.py
@@ -15,8 +15,6 @@
_registered_implementations.add(implcls)
option_to_typename = {
- "withspecialisedtuple" :
["specialisedtupleobject.W_SpecialisedTupleObject"],
- "withsmalltuple" : ["smalltupleobject.W_SmallTupleObject"],
"withsmalllong" : ["smalllongobject.W_SmallLongObject"],
"withstrbuf" : ["strbufobject.W_StringBufferObject"],
}
@@ -38,7 +36,6 @@
from pypy.objspace.std.inttype import int_typedef
from pypy.objspace.std.floattype import float_typedef
from pypy.objspace.std.complextype import complex_typedef
- from pypy.objspace.std.tupletype import tuple_typedef
from pypy.objspace.std.basestringtype import basestring_typedef
from pypy.objspace.std.stringtype import str_typedef
from pypy.objspace.std.bytearraytype import bytearray_typedef
@@ -79,6 +76,7 @@
# not-multimethod based types
+ self.pythontypes.append(tupleobject.W_TupleObject.typedef)
self.pythontypes.append(listobject.W_ListObject.typedef)
self.pythontypes.append(dictmultiobject.W_DictMultiObject.typedef)
self.pythontypes.append(setobject.W_SetObject.typedef)
@@ -90,7 +88,6 @@
boolobject.W_BoolObject: [],
intobject.W_IntObject: [],
floatobject.W_FloatObject: [],
- tupleobject.W_TupleObject: [],
stringobject.W_StringObject: [],
bytearrayobject.W_BytearrayObject: [],
typeobject.W_TypeObject: [],
@@ -109,7 +106,6 @@
self.imported_but_not_registered = {
stringobject.W_StringObject: True,
- tupleobject.W_TupleObject: True,
}
for option, value in config.objspace.std:
if option.startswith("with") and option in option_to_typename:
@@ -191,10 +187,11 @@
strbufobject.delegate_buf2unicode)
]
- if config.objspace.std.withspecialisedtuple:
- from pypy.objspace.std import specialisedtupleobject
- self.typeorder[specialisedtupleobject.W_SpecialisedTupleObject] +=
[
- (tupleobject.W_TupleObject,
specialisedtupleobject.delegate_SpecialisedTuple2Tuple)]
+ # XXX fix specialisedtuple
+ #if config.objspace.std.withspecialisedtuple:
+ # from pypy.objspace.std import specialisedtupleobject
+ # self.typeorder[specialisedtupleobject.W_SpecialisedTupleObject]
+= [
+ # (tupleobject.W_TupleObject,
specialisedtupleobject.delegate_SpecialisedTuple2Tuple)]
# put W_Root everywhere
self.typeorder[W_Root] = []
diff --git a/pypy/objspace/std/smalltupleobject.py
b/pypy/objspace/std/smalltupleobject.py
--- a/pypy/objspace/std/smalltupleobject.py
+++ b/pypy/objspace/std/smalltupleobject.py
@@ -1,26 +1,15 @@
from pypy.interpreter.error import OperationError
-from pypy.objspace.std.model import registerimplementation, W_Object
-from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.inttype import wrapint
-from pypy.objspace.std.multimethod import FailedToImplement
+from pypy.objspace.std.sliceobject import W_SliceObject
+from pypy.objspace.std.tupleobject import W_AbstractTupleObject
+from pypy.objspace.std.util import negate
from rpython.rlib.rarithmetic import intmask
-from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
-from pypy.objspace.std import slicetype
-from pypy.objspace.std.util import negate
-from pypy.interpreter import gateway
-from rpython.rlib.debug import make_sure_not_resized
from rpython.rlib.unroll import unrolling_iterable
from rpython.tool.sourcetools import func_with_new_name
-from pypy.objspace.std.tupleobject import W_AbstractTupleObject, W_TupleObject
-
-
-class W_SmallTupleObject(W_AbstractTupleObject):
- from pypy.objspace.std.tupletype import tuple_typedef as typedef
def make_specialized_class(n):
iter_n = unrolling_iterable(range(n))
- class cls(W_SmallTupleObject):
+ class cls(W_AbstractTupleObject):
def __init__(self, values):
assert len(values) == n
@@ -39,9 +28,6 @@
def length(self):
return n
- def descr_len(self):
- return space.wrap(n)
-
def descr_getitem(self, space, w_index):
if isinstance(w_index, W_SliceObject):
return self._getslice(space, w_index)
@@ -95,5 +81,3 @@
W_SmallTupleObject6 = make_specialized_class(6)
W_SmallTupleObject7 = make_specialized_class(7)
W_SmallTupleObject8 = make_specialized_class(8)
-
-registerimplementation(W_SmallTupleObject)
diff --git a/pypy/objspace/std/test/test_smalltupleobject.py
b/pypy/objspace/std/test/test_smalltupleobject.py
--- a/pypy/objspace/std/test/test_smalltupleobject.py
+++ b/pypy/objspace/std/test/test_smalltupleobject.py
@@ -1,5 +1,5 @@
from pypy.objspace.std.tupleobject import W_TupleObject
-from pypy.objspace.std.smalltupleobject import W_SmallTupleObject
+from pypy.objspace.std.smalltupleobject import W_SmallTupleObject2
from pypy.interpreter.error import OperationError
from pypy.objspace.std.test.test_tupleobject import AppTestW_TupleObject
from pypy.tool.pytest.objspace import gettestobjspace
@@ -55,12 +55,16 @@
c = (1,3,2)
assert hash(a) != hash(c)
+ def test_foo(self):
+ assert tuple([0]) + (1,) == (0, 1)
+ assert not tuple([0]) + (1,) == (0,)
+
class TestW_SmallTupleObject():
spaceconfig = {"objspace.std.withsmalltuple": True}
def test_issmalltupleobject(self):
w_tuple = self.space.newtuple([self.space.wrap(1), self.space.wrap(2)])
- assert isinstance(w_tuple, W_SmallTupleObject)
+ assert isinstance(w_tuple, W_SmallTupleObject2)
def test_hash_agains_normal_tuple(self):
normalspace = gettestobjspace(**{"objspace.std.withsmalltuple": False})
@@ -69,7 +73,7 @@
smallspace = gettestobjspace(**{"objspace.std.withsmalltuple": True})
w_smalltuple = smallspace.newtuple([self.space.wrap(1),
self.space.wrap(2)])
- assert isinstance(w_smalltuple, W_SmallTupleObject)
+ assert isinstance(w_smalltuple, W_SmallTupleObject2)
assert isinstance(w_tuple, W_TupleObject)
assert not normalspace.is_true(normalspace.eq(w_tuple, w_smalltuple))
assert smallspace.is_true(smallspace.eq(w_tuple, w_smalltuple))
diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py
--- a/pypy/objspace/std/tupleobject.py
+++ b/pypy/objspace/std/tupleobject.py
@@ -1,18 +1,17 @@
import sys
+from pypy.interpreter import gateway
+from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError
-from pypy.objspace.std.model import registerimplementation, W_Object
-from pypy.objspace.std.register_all import register_all
+from pypy.interpreter.gateway import interp2app, interpindirect2app
+from pypy.objspace.std import slicetype
from pypy.objspace.std.inttype import wrapint
+from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
+from pypy.objspace.std.stdtypedef import StdTypeDef
+from pypy.objspace.std.util import negate
+from rpython.rlib import jit
+from rpython.rlib.debug import make_sure_not_resized
from rpython.rlib.rarithmetic import intmask
-from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
-from pypy.objspace.std import slicetype
-from pypy.objspace.std.util import negate
-from pypy.objspace.std.stdtypedef import StdTypeDef
-from rpython.rlib.debug import make_sure_not_resized
-from rpython.rlib import jit
from rpython.tool.sourcetools import func_with_new_name
-from pypy.interpreter import gateway
-from pypy.interpreter.gateway import interp2app, interpindirect2app
UNROLL_CUTOFF = 10
@@ -23,7 +22,7 @@
jit.loop_unrolling_heuristic(other, other.length(), UNROLL_CUTOFF))
-class W_AbstractTupleObject(W_Object):
+class W_AbstractTupleObject(W_Root):
__slots__ = ()
def __repr__(w_self):
@@ -282,8 +281,6 @@
raise OperationError(space.w_IndexError,
space.wrap("tuple index out of range"))
-registerimplementation(W_TupleObject)
-
@jit.look_inside_iff(lambda space, wrappeditems:
jit.loop_unrolling_heuristic(wrappeditems, len(wrappeditems),
UNROLL_CUTOFF))
diff --git a/pypy/objspace/std/tupletype.py b/pypy/objspace/std/tupletype.py
--- a/pypy/objspace/std/tupletype.py
+++ b/pypy/objspace/std/tupletype.py
@@ -3,12 +3,13 @@
def wraptuple(space, list_w):
from pypy.objspace.std.tupleobject import W_TupleObject
- if space.config.objspace.std.withspecialisedtuple:
- from specialisedtupleobject import makespecialisedtuple, NotSpecialised
- try:
- return makespecialisedtuple(space, list_w)
- except NotSpecialised:
- pass
+ # XXX fix specialisedtuple
+ #if space.config.objspace.std.withspecialisedtuple:
+ # from specialisedtupleobject import makespecialisedtuple,
NotSpecialised
+ # try:
+ # return makespecialisedtuple(space, list_w)
+ # except NotSpecialised:
+ # pass
if space.config.objspace.std.withsmalltuple:
from pypy.objspace.std.smalltupleobject import W_SmallTupleObject2
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit