[pypy-svn] r62371 - in pypy/branch/spy-graphic/pypy/lang/smalltalk: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Mar 2 14:25:33 CET 2009
Author: cfbolz
Date: Mon Mar 2 14:25:32 2009
New Revision: 62371
Modified:
pypy/branch/spy-graphic/pypy/lang/smalltalk/model.py
pypy/branch/spy-graphic/pypy/lang/smalltalk/objspace.py
pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py
pypy/branch/spy-graphic/pypy/lang/smalltalk/shadow.py
pypy/branch/spy-graphic/pypy/lang/smalltalk/squeakimage.py
pypy/branch/spy-graphic/pypy/lang/smalltalk/test/test_primitives.py
Log:
make W_WordObjects use unsigned integers
Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/model.py (original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/model.py Mon Mar 2 14:25:32 2009
@@ -16,7 +16,7 @@
"""
import sys
from pypy.rlib import rrandom, objectmodel
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, r_uint
from pypy.lang.smalltalk import constants, error
from pypy.tool.pairtype import extendabletype
from pypy.rlib.objectmodel import instantiate
@@ -392,25 +392,14 @@
class W_WordsObject(W_AbstractObjectWithClassReference):
def __init__(self, w_class, size):
W_AbstractObjectWithClassReference.__init__(self, w_class)
- self.words = [0] * size
+ self.words = [r_uint(0)] * size
def at0(self, space, index0):
val = self.getword(index0)
- return space.wrap_pos_full_int(val)
+ return space.wrap_uint(val)
def atput0(self, space, index0, w_value):
- if isinstance(w_value, W_BytesObject):
- # TODO: Completely untested! This failed translation bigtime...
- # XXX Probably we want to allow all subclasses
- if not (w_value.getclass(space).is_same_object(
- space.w_LargePositiveInteger) and
- w_value.size() == 4):
- raise error.UnwrappingError("Failed to convert bytes to word")
- word = 0
- for i in range(4):
- word += ord(w_value.getchar(i)) << 8*i
- else:
- word = space.unwrap_int(w_value)
+ word = space.unwrap_uint(w_value)
self.setword(index0, word)
def getword(self, n):
Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/objspace.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/objspace.py (original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/objspace.py Mon Mar 2 14:25:32 2009
@@ -1,8 +1,9 @@
from pypy.lang.smalltalk import constants
from pypy.lang.smalltalk import model
from pypy.lang.smalltalk import shadow
-from pypy.rlib.objectmodel import instantiate
from pypy.lang.smalltalk.error import UnwrappingError, WrappingError
+from pypy.rlib.objectmodel import instantiate
+from pypy.rlib.rarithmetic import intmask, r_uint
class ObjSpace(object):
def __init__(self):
@@ -163,17 +164,18 @@
return model.W_SmallInteger(val)
raise WrappingError("integer too large to fit into a tagged pointer")
- def wrap_pos_full_int(self, val):
+ def wrap_uint(self, val):
if val < 0:
raise WrappingError("negative integer")
- try:
- return self.wrap_int(val)
- except WrappingError:
- pass
+ if intmask(val) > 0:
+ try:
+ return self.wrap_int(intmask(val))
+ except WrappingError:
+ pass
# XXX this is not really working well on 64 bit machines
w_result = model.W_BytesObject(self.classtable['w_LargePositiveInteger'], 4)
for i in range(4):
- w_result.setchar(i, chr((val >> i*8) & 255))
+ w_result.setchar(i, chr(intmask((val >> i*8) & 255)))
return w_result
def wrap_float(self, i):
@@ -196,7 +198,7 @@
def wrap_list(self, lst_w):
"""
- Converts a Python list of wrapper objects into
+ Converts a Python list of wrapped objects into
a wrapped smalltalk array
"""
lstlen = len(lst_w)
@@ -210,6 +212,26 @@
return w_value.value
raise UnwrappingError("expected a W_SmallInteger, got %s" % (w_value,))
+ def unwrap_uint(self, w_value):
+ if isinstance(w_value, model.W_SmallInteger):
+ val = w_value.value
+ if val < 0:
+ raise UnwrappingError("got negative integer")
+ return w_value.value
+ if isinstance(w_value, model.W_BytesObject):
+ # TODO: Completely untested! This failed translation bigtime...
+ # XXX Probably we want to allow all subclasses
+ if not (w_value.getclass(self).is_same_object(
+ self.w_LargePositiveInteger) and
+ w_value.size() == 4):
+ raise UnwrappingError("Failed to convert bytes to word")
+ word = 0
+ for i in range(4):
+ word += r_uint(ord(w_value.getchar(i))) << 8*i
+ return word
+ else:
+ raise UnwrappingError("Got unexpected class in unwrap_uint")
+
def unwrap_char(self, w_char):
from pypy.lang.smalltalk import constants
w_class = w_char.getclass(self)
Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py (original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py Mon Mar 2 14:25:32 2009
@@ -597,11 +597,10 @@
@expose_primitive(SECONDS_CLOCK, unwrap_spec=[object])
def func(interp, w_arg):
- return interp.space.wrap_int(73)
import time
sec_since_epoch = rarithmetic.r_uint(time.time())
sec_since_1901 = sec_since_epoch + secs_between_1901_and_1970
- return interp.space.wrap_pos_full_int(sec_since_1901)
+ return interp.space.wrap_uint(sec_since_1901)
# ___________________________________________________________________________
# Boolean Primitives
Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/shadow.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/shadow.py (original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/shadow.py Mon Mar 2 14:25:32 2009
@@ -462,6 +462,7 @@
# ______________________________________________________________________
# Stack Manipulation
+ # XXX this should really be done with a fixedsize list as well.
def pop(self):
return self._stack.pop()
Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/squeakimage.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/squeakimage.py (original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/squeakimage.py Mon Mar 2 14:25:32 2009
@@ -359,7 +359,8 @@
w_pointersobject.hash = self.chunk.hash12
def fillin_wordsobject(self, w_wordsobject):
- w_wordsobject.words = self.chunk.data
+ from pypy.rlib.rarithmetic import r_uint
+ w_wordsobject.words = [r_uint(x) for x in self.chunk.data]
w_class = self.g_class.w_object
assert isinstance(w_class, model.W_PointersObject)
w_wordsobject.w_class = w_class
Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/test/test_primitives.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/test/test_primitives.py (original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/test/test_primitives.py Mon Mar 2 14:25:32 2009
@@ -392,7 +392,6 @@
prim(primitives.FULL_GC, [42]) # Dummy arg
def test_seconds_clock():
- py.test.skip("disabled because it breaks translation")
import time
now = int(time.time())
w_smalltalk_now1 = prim(primitives.SECONDS_CLOCK, [42])
More information about the Pypy-commit
mailing list