Author: Mark Pearse <[email protected]>
Branch: SpecialisedTuples
Changeset: r49079:8b3f48703d65
Date: 2011-11-04 17:43 +0100
http://bitbucket.org/pypy/pypy/changeset/8b3f48703d65/
Log: (antocuni, mwp) starting to implement TupleIntInt
diff --git a/pypy/objspace/std/specialisedtupleobject.py
b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -41,18 +41,31 @@
class W_SpecialisedTupleObjectIntInt(W_SpecialisedTupleObject):
- def __init__(self, intval0, intval1):
+ def __init__(self, space, intval0, intval1):
assert isinstance(intval0, int)
assert isinstance(intval1, int)
+ self.space = space
self.intval0 = intval0
self.intval1 = intval1
def length(self):
return 2
+
+ def tolist(self):
+ return [self.space.wrap(self.intval0), self.space.wrap(self.intval1)]
+
+ def hash(self, space):
+ return space.wrap(0)
+
+ def eq(self, space, w_other):
+ if w_other.length() != 2:
+ return space.w_False
+ if self.intval0 == w_other.intval0 and self.intval1 ==
w_other.intval1: #xxx
+ return space.w_True
+ else:
+ return space.w_False
+
'''
- def tolist(self):
- return [W_IntObject(self.intval)]
-
def getitem(self, index):
if index == 0:
self.wrap(self.intval)
@@ -65,21 +78,13 @@
self.intval = w_item.intval
return
raise IndexError
-
- def eq(self, space, w_other):
- if w_other.length() != 1:
- return space.w_False
- if self.intval == w_other.intval: #is it safe to assume all
1-tuples are specialised ?
- return space.w_True
- else:
- return space.w_False
-'''
+'''
registerimplementation(W_SpecialisedTupleObject)
def delegate_SpecialisedTuple2Tuple(space, w_specialised):
return W_TupleObject(w_specialised.tolist())
-
+'''
def len__SpecialisedTuple(space, w_tuple):
return space.wrap(w_tuple.length())
@@ -123,7 +128,7 @@
def eq__SpecialisedTuple_SpecialisedTuple(space, w_tuple1, w_tuple2):
return w_tuple1.eq(space, w_tuple2)
-
+'''
def hash__SpecialisedTuple(space, w_tuple):
return w_tuple.hash(space)
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
@@ -14,13 +14,23 @@
from pypy.objspace.std.smalltupleobject import W_SmallTupleObject6
from pypy.objspace.std.smalltupleobject import W_SmallTupleObject7
from pypy.objspace.std.smalltupleobject import W_SmallTupleObject8
+
+
+ from pypy.objspace.std.specialisedtupleobject import
W_SpecialisedTupleObjectIntInt
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.floatobject import W_FloatObject
from pypy.objspace.std.stringobject import W_StringObject
if space.config.objspace.std.withspecialisedtuple:
- pass
+ if len(list_w) == 2:
+ w_item0 = list_w[0]
+ w_item1 = list_w[1]
+ if space.type(w_item0) == space.w_int and space.type(w_item1) ==
space.w_int:
+ val0 = space.int_w(w_item0)
+ val1 = space.int_w(w_item1)
+ return W_SpecialisedTupleObjectIntInt(space, val0, val1)
+
if space.config.objspace.std.withsmalltuple:
if len(list_w) == 2:
return W_SmallTupleObject2(list_w)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit