[pypy-svn] r10822 - in pypy/dist/pypy: interpreter objspace objspace/std
pedronis at codespeak.net
pedronis at codespeak.net
Mon Apr 18 20:09:54 CEST 2005
Author: pedronis
Date: Mon Apr 18 20:09:54 2005
New Revision: 10822
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/objspace/descroperation.py
pypy/dist/pypy/objspace/std/dictobject.py
pypy/dist/pypy/objspace/std/inttype.py
pypy/dist/pypy/objspace/std/listobject.py
pypy/dist/pypy/objspace/std/objspace.py
Log:
fix some type mixing
use a different, annotation friendlier approach than the statedict
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Mon Apr 18 20:09:54 2005
@@ -179,11 +179,11 @@
raise ValueError, "need more than %d value%s to unpack" % (i, plural)
return items
- def unpacktuple(self, w_tuple, expected_length=None):
+ def unpacktuple(self, w_tuple, expected_length=-1):
"""Same as unpackiterable(), but only for tuples.
Only use for bootstrapping or performance reasons."""
tuple_length = self.int_w(self.len(w_tuple))
- if expected_length is not None and tuple_length != expected_length:
+ if expected_length != -1 and tuple_length != expected_length:
raise ValueError, "got a tuple of length %d instead of %d" % (
tuple_length, expected_length)
items = [
Modified: pypy/dist/pypy/objspace/descroperation.py
==============================================================================
--- pypy/dist/pypy/objspace/descroperation.py (original)
+++ pypy/dist/pypy/objspace/descroperation.py Mon Apr 18 20:09:54 2005
@@ -60,6 +60,10 @@
class DescrOperation:
_mixin_ = True
+ def setup_ec(space, ec):
+ ec._compare_nesting = 0
+ ec._cmp_state = {}
+
def getdict(space, w_obj):
return w_obj.getdict()
@@ -296,10 +300,10 @@
token = None
_inprogress_dict = None
- # um
- statedict = space.get_ec_state_dict()
- _compare_nesting = statedict.get('_compare_nesting', 0) + 1
- statedict['_compare_nesting'] = _compare_nesting
+ ec = space.getexecutioncontext()
+ ec._compare_nesting += 1
+ _compare_nesting = ec._compare_nesting
+
try:
# Try to do some magic to compare cyclic constructs.
if (_compare_nesting > space._NESTING_LIMIT and
@@ -313,7 +317,7 @@
t = (iv, iw, -1)
else:
t = (iw, iv, -1)
- _inprogress_dict = statedict.setdefault('cmp_state', {})
+ _inprogress_dict = ec._cmp_state
if t in _inprogress_dict:
# If we are allready trying to compare the arguments
# presume they are equal
@@ -343,7 +347,7 @@
except:
pass
finally:
- statedict['_compare_nesting'] -= 1
+ ec._compare_nesting -= 1
def coerce(space, w_obj1, w_obj2):
w_typ1 = space.type(w_obj1)
@@ -480,10 +484,9 @@
token = None
_inprogress_dict = None
- # um
- statedict = space.get_ec_state_dict()
- _compare_nesting = statedict.get('_compare_nesting', 0) + 1
- statedict['_compare_nesting'] = _compare_nesting
+ ec = space.getexecutioncontext()
+ ec._compare_nesting += 1
+ _compare_nesting = ec._compare_nesting
try:
# Try to do some magic to compare cyclic constructs.
if (_compare_nesting > space._NESTING_LIMIT and
@@ -529,7 +532,7 @@
res = space.int_w(w_res)
return space.wrap(op(res, 0))
finally:
- statedict['_compare_nesting'] -= 1
+ ec._compare_nesting -= 1
if token is not None:
try:
del _inprogress_dict[token]
Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictobject.py Mon Apr 18 20:09:54 2005
@@ -270,11 +270,7 @@
if w_dict.used == 0:
return space.wrap('{}')
statedict = space.get_ec_state_dict()
- try:
- w_currently_in_repr = statedict['Py_Repr']
- except KeyError:
- w_currently_in_repr = statedict['Py_Repr'] = space.newdict([])
-
+ w_currently_in_repr = space.getexecutioncontext()._py_repr
return dictstr(space, w_currently_in_repr, w_dict)
repr__Dict = str__Dict
Modified: pypy/dist/pypy/objspace/std/inttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/inttype.py (original)
+++ pypy/dist/pypy/objspace/std/inttype.py Mon Apr 18 20:09:54 2005
@@ -58,9 +58,9 @@
raise OperationError(space.w_OverflowError,
space.wrap(
"long int too large to convert to int"))
- from pypy.objspace.std.longobject import W_LongObject
+ from pypy.objspace.std.longobject import W_LongObject, args_from_long
w_obj = space.allocate_instance(W_LongObject, space.w_long)
- w_obj.__init__(space, value)
+ w_obj.__init__(space, *args_from_long(value))
return w_obj
else:
w_obj = space.allocate_instance(W_IntObject, w_inttype)
Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py (original)
+++ pypy/dist/pypy/objspace/std/listobject.py Mon Apr 18 20:09:54 2005
@@ -326,12 +326,7 @@
def repr__List(space, w_list):
if w_list.ob_size == 0:
return space.wrap('[]')
- statedict = space.get_ec_state_dict()
- try:
- w_currently_in_repr = statedict['Py_Repr']
- except KeyError:
- w_currently_in_repr = statedict['Py_Repr'] = space.newdict(())
-
+ w_currently_in_repr = space.getexecutioncontext()._py_repr
return listrepr(space, w_currently_in_repr, w_list)
def hash__List(space,w_list):
Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py (original)
+++ pypy/dist/pypy/objspace/std/objspace.py Mon Apr 18 20:09:54 2005
@@ -149,6 +149,13 @@
from pypy.interpreter.module import Module
return Module(self, self.wrap("exceptions"), w_dic)
+ def createexecutioncontext(self):
+ # add space specific fields to execution context
+ ec = ObjSpace.createexecutioncontext(self)
+ DescrOperation.setup_ec(self, ec)
+ ec._py_repr = self.newdict([])
+ return ec
+
def gettypeobject(self, typedef):
# types_w maps each StdTypeDef instance to its
# unique-for-this-space W_TypeObject instance
@@ -276,10 +283,10 @@
allocate_instance._specialize_ = "location"
- def unpacktuple(self, w_tuple, expected_length=None):
+ def unpacktuple(self, w_tuple, expected_length=-1):
assert isinstance(w_tuple, W_TupleObject)
t = w_tuple.wrappeditems
- if expected_length is not None and expected_length != len(t):
+ if expected_length != -1 and expected_length != len(t):
raise ValueError, "got a tuple of length %d instead of %d" % (
len(t), expected_length)
return t
More information about the Pypy-commit
mailing list