Author: Tim Felgentreff <[email protected]>
Branch: 64bit
Changeset: r574:4661bff0c7d3
Date: 2014-01-10 23:08 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/4661bff0c7d3/
Log: make more code word-size agnostic
diff --git a/spyvm/constants.py b/spyvm/constants.py
--- a/spyvm/constants.py
+++ b/spyvm/constants.py
@@ -142,7 +142,7 @@
"timerSemaphore" : SO_TIMER_SEMAPHORE,
}
-LONG_BIT = 32
+from rpython.rlib.rarithmetic import LONG_BIT
TAGGED_MAXINT = 2 ** (LONG_BIT - 2) - 1
TAGGED_MININT = -2 ** (LONG_BIT - 2)
diff --git a/spyvm/interpreter_proxy.py b/spyvm/interpreter_proxy.py
--- a/spyvm/interpreter_proxy.py
+++ b/spyvm/interpreter_proxy.py
@@ -414,12 +414,12 @@
@expose_on_virtual_machine_proxy([int], oop)
def positive32BitIntegerFor(n):
- return IProxy.space.wrap_positive_32bit_int(n)
+ return IProxy.space.wrap_positive_1word_int(n)
@expose_on_virtual_machine_proxy([oop], int)
def positive32BitValueOf(n):
from rpython.rlib.rarithmetic import intmask
- return intmask(IProxy.space.unwrap_positive_32bit_int(n))
+ return intmask(IProxy.space.unwrap_positive_1word_int(n))
# /* InterpreterProxy methodsFor: 'special objects' */
@@ -1165,4 +1165,4 @@
# class __extend__(model.W_WordsObject):
# def as_c_array(self, proxy):
-# return map(lambda x:
proxy.object_to_oop(proxy.space.wrap_positive_32bit_int(x), self.words)
+# return map(lambda x:
proxy.object_to_oop(proxy.space.wrap_positive_1word_int(x), self.words)
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -174,7 +174,7 @@
upperbound = intmask(r_uint(-1) >> shift)
if 0 <= self.value <= upperbound:
shifted = intmask(self.value << shift)
- return space.wrap_positive_32bit_int(shifted)
+ return space.wrap_positive_1word_int(shifted)
else:
try:
shifted = ovfcheck(self.value << shift)
@@ -280,7 +280,7 @@
upperbound = intmask(r_uint(-1) >> shift)
if 0 <= self.value <= upperbound:
shifted = intmask(self.value << shift)
- return space.wrap_positive_32bit_int(shifted)
+ return space.wrap_positive_1word_int(shifted)
else:
raise error.PrimitiveFailedError()
@@ -395,11 +395,11 @@
from rpython.rlib.rstruct.ieee import float_pack
r = float_pack(self.value, 8) # C double
if n0 == 0:
- return space.wrap_positive_32bit_int(intmask(r >> 32))
+ return space.wrap_positive_1word_int(intmask(r >> 32))
else:
# bounds-check for primitive access is done in the primitive
assert n0 == 1
- return space.wrap_positive_32bit_int(intmask(r))
+ return space.wrap_positive_1word_int(intmask(r))
def store(self, space, n0, w_obj):
from rpython.rlib.rstruct.ieee import float_unpack, float_pack
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -216,14 +216,14 @@
raise WrappingError("negative integer")
if val >= 0:
try:
- return self.wrap_positive_32bit_int(intmask(val))
+ return self.wrap_positive_1word_int(intmask(val))
except WrappingError:
pass
# XXX this code sucks
import math
bytes_len = int(math.log(val) / math.log(0xff)) + 1
if bytes_len <= 4:
- return self.wrap_positive_32bit_int(intmask(val))
+ return self.wrap_positive_1word_int(intmask(val))
else:
return self._wrap_uint_loop(val, bytes_len)
@@ -235,9 +235,9 @@
w_result.setchar(i, chr(intmask((val >> i*8) & 255)))
return w_result
- def wrap_positive_32bit_int(self, val):
+ def wrap_positive_1word_int(self, val):
# This will always return a positive value.
- # XXX: For now, we assume that val is at most 32bit, i.e. overflows are
+ # XXX: For now, we assume that val is at most 1word, i.e. overflows are
# checked for before wrapping.
if int_between(0, val, constants.TAGGED_MAXINT + 1):
return model.W_SmallInteger(val)
@@ -280,13 +280,13 @@
if w_value.value >= 0:
return intmask(w_value.value)
else:
- raise UnwrappingError("The value is negative when interpreted
as 32bit value.")
+ raise UnwrappingError("The value is negative when interpreted
as 1 word value.")
raise UnwrappingError("expected a W_SmallInteger or
W_LargePositiveInteger1Word, got %s" % (w_value,))
def unwrap_uint(self, w_value):
return w_value.unwrap_uint(self)
- def unwrap_positive_32bit_int(self, w_value):
+ def unwrap_positive_1word_int(self, w_value):
if isinstance(w_value, model.W_SmallInteger):
if w_value.value >= 0:
return r_uint(w_value.value)
diff --git a/spyvm/plugins/fileplugin.py b/spyvm/plugins/fileplugin.py
--- a/spyvm/plugins/fileplugin.py
+++ b/spyvm/plugins/fileplugin.py
@@ -112,7 +112,7 @@
except OSError:
raise PrimitiveFailedError
else:
- return interp.space.wrap_positive_32bit_int(rarithmetic.intmask(pos))
+ return interp.space.wrap_positive_1word_int(rarithmetic.intmask(pos))
@FilePlugin.expose_primitive(unwrap_spec=[object, int, int])
def primitiveFileSetPosition(interp, s_frame, w_rcvr, fd, position):
@@ -128,7 +128,7 @@
file_info = os.fstat(fd)
except OSError:
raise PrimitiveFailedError
- return
interp.space.wrap_positive_32bit_int(rarithmetic.intmask(file_info.st_size))
+ return
interp.space.wrap_positive_1word_int(rarithmetic.intmask(file_info.st_size))
@FilePlugin.expose_primitive(unwrap_spec=[object])
def primitiveFileStdioHandles(interp, s_frame, w_rcvr):
@@ -148,7 +148,7 @@
except OSError:
raise PrimitiveFailedError
else:
- return space.wrap_positive_32bit_int(rarithmetic.intmask(written))
+ return space.wrap_positive_1word_int(rarithmetic.intmask(written))
@jit.elidable
def smalltalk_timestamp(space, sec_since_epoch):
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -49,7 +49,7 @@
# converted to an index0
index1_0 = object()
char = object()
-pos_32bit_int = object()
+pos_1word_int = object()
def expose_primitive(code, unwrap_spec=None, no_result=False,
result_is_new_frame=False, may_context_switch=True,
@@ -121,8 +121,8 @@
w_arg = s_frame.peek(index)
if spec is int:
args += (interp.space.unwrap_int(w_arg), )
- elif spec is pos_32bit_int:
- args +=
(interp.space.unwrap_positive_32bit_int(w_arg),)
+ elif spec is pos_1word_int:
+ args +=
(interp.space.unwrap_positive_1word_int(w_arg),)
elif spec is index1_0:
args += (interp.space.unwrap_int(w_arg)-1, )
elif spec is float:
@@ -204,10 +204,10 @@
}
for (code,op) in bitwise_binary_ops.items():
def make_func(op):
- @expose_primitive(code, unwrap_spec=[pos_32bit_int, pos_32bit_int])
+ @expose_primitive(code, unwrap_spec=[pos_1word_int, pos_1word_int])
def func(interp, s_frame, receiver, argument):
res = op(receiver, argument)
- return
interp.space.wrap_positive_32bit_int(rarithmetic.intmask(res))
+ return interp.space.wrap_int(rarithmetic.intmask(res))
make_func(op)
# #/ -- return the result of a division, only succeed if the division is exact
@@ -248,8 +248,6 @@
@expose_primitive(BIT_SHIFT, unwrap_spec=[object, int])
def func(interp, s_frame, receiver, argument):
from rpython.rlib.rarithmetic import LONG_BIT
- # XXX: 32-bit images only!
- # LONG_BIT = 32
if -LONG_BIT < argument < LONG_BIT:
# overflow-checking done in lshift implementations
if argument > 0:
@@ -1072,7 +1070,7 @@
raise PrimitiveFailedError
return w_receiver.short_atput0(interp.space, n0, w_value)
-@expose_primitive(FILL, unwrap_spec=[object, pos_32bit_int])
+@expose_primitive(FILL, unwrap_spec=[object, pos_1word_int])
def func(interp, s_frame, w_arg, new_value):
space = interp.space
if isinstance(w_arg, model.W_BytesObject):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit