[pypy-svn] r10445 - in pypy/dist/pypy: annotation objspace/std objspace/std/test tool tool/test translator translator/genc
pedronis at codespeak.net
pedronis at codespeak.net
Fri Apr 8 19:22:15 CEST 2005
Author: pedronis
Date: Fri Apr 8 19:22:15 2005
New Revision: 10445
Added:
pypy/dist/pypy/tool/rarithmetic.py
- copied unchanged from r10438, pypy/dist/pypy/objspace/std/restricted_int.py
pypy/dist/pypy/tool/test/test_rarithmetic.py
- copied, changed from r10438, pypy/dist/pypy/objspace/std/test/test_restricted_int.py
Removed:
pypy/dist/pypy/objspace/std/restricted_int.py
pypy/dist/pypy/objspace/std/test/test_restricted_int.py
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/annotation/model.py
pypy/dist/pypy/objspace/std/dictobject.py
pypy/dist/pypy/objspace/std/intobject.py
pypy/dist/pypy/objspace/std/listobject.py
pypy/dist/pypy/objspace/std/stringobject.py
pypy/dist/pypy/objspace/std/tupleobject.py
pypy/dist/pypy/translator/genc/t_pyobj.py
pypy/dist/pypy/translator/geninterplevel.py
Log:
start to follow our plan about integer arithmetic,
moved restricted_int out of std, because it may be used elsewhere, to tool/rarithmetic.py
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Fri Apr 8 19:22:15 2005
@@ -11,7 +11,7 @@
from pypy.annotation.bookkeeper import getbookkeeper
from pypy.annotation.factory import ListFactory
from pypy.objspace.flow.model import Constant
-import pypy.objspace.std.restricted_int
+import pypy.tool.rarithmetic
# convenience only!
def immutablevalue(x):
@@ -225,8 +225,8 @@
original = getattr(__builtin__, name[8:])
BUILTIN_ANALYZERS[original] = value
-BUILTIN_ANALYZERS[pypy.objspace.std.restricted_int.r_int] = builtin_int
-BUILTIN_ANALYZERS[pypy.objspace.std.restricted_int.r_uint] = restricted_uint
+BUILTIN_ANALYZERS[pypy.tool.rarithmetic.r_int] = builtin_int
+BUILTIN_ANALYZERS[pypy.tool.rarithmetic.r_uint] = restricted_uint
BUILTIN_ANALYZERS[Exception.__init__.im_func] = exception_init
# this one is needed otherwise when annotating assert in a test we may try to annotate
# py.test AssertionError.__init__ .
Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py (original)
+++ pypy/dist/pypy/annotation/model.py Fri Apr 8 19:22:15 2005
@@ -105,7 +105,7 @@
knowntype = int
def __init__(self, nonneg=False, unsigned=False):
self.nonneg = nonneg
- self.unsigned = unsigned # pypy.objspace.std.restricted_int.r_uint
+ self.unsigned = unsigned # pypy.tool.rarithmetic.r_uint
class SomeBool(SomeInteger):
Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictobject.py Fri Apr 8 19:22:15 2005
@@ -8,7 +8,7 @@
from pypy.objspace.std.objspace import *
from pypy.interpreter import gateway
-from pypy.objspace.std.restricted_int import r_uint
+from pypy.tool.rarithmetic import r_uint
class Entry:
def __init__(self):
Modified: pypy/dist/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/intobject.py (original)
+++ pypy/dist/pypy/objspace/std/intobject.py Fri Apr 8 19:22:15 2005
@@ -1,6 +1,6 @@
from pypy.objspace.std.objspace import *
from pypy.objspace.std.noneobject import W_NoneObject
-from pypy.objspace.std.restricted_int import r_int, LONG_BIT
+from pypy.tool.rarithmetic import r_int, LONG_BIT
"""
The implementation of integers is a bit difficult,
Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py (original)
+++ pypy/dist/pypy/objspace/std/listobject.py Fri Apr 8 19:22:15 2005
@@ -5,7 +5,7 @@
from pypy.objspace.std import slicetype
from pypy.interpreter import gateway, baseobjspace
-from pypy.objspace.std.restricted_int import r_int, r_uint
+from pypy.tool.rarithmetic import r_int, r_uint
from pypy.objspace.std.listsort import TimSort
Deleted: /pypy/dist/pypy/objspace/std/restricted_int.py
==============================================================================
--- /pypy/dist/pypy/objspace/std/restricted_int.py Fri Apr 8 19:22:15 2005
+++ (empty file)
@@ -1,283 +0,0 @@
-"""
-This file defines restricted integers.
-
-Purpose:
-Have an integer implementation that emulates
-restricted Python for CPython.
-
-r_int an integer type which has overflow checking.
- It doesn not automatically extend to long
-r_uint an unsigned integer which has not overflow
- checking. It is always positive and always
- truncated to the internal machine word size.
-
-We try to keep the number of such internal types
-to a minimum.
-"""
-
-class r_int(int):
- """ fake integer implementation in order to make sure that
- primitive integer operations do overflow """
-
- def __add__(self, other):
- x = int(self)
- y = int(other)
- return r_int(x + y)
- __radd__ = __add__
-
- def __sub__(self, other):
- x = int(self)
- y = int(other)
- return r_int(x - y)
-
- def __rsub__(self, other):
- y = int(self)
- x = int(other)
- return r_int(x - y)
-
- def __mul__(self, other):
- x = int(self)
- if not isinstance(other, (int, long)):
- return x * other
- y = int(other)
- return r_int(x * y)
- __rmul__ = __mul__
-
- def __div__(self, other):
- x = int(self)
- y = int(other)
- return r_int(x // y)
-
- __floordiv__ = __div__
-
- def __rdiv__(self, other):
- y = int(self)
- x = int(other)
- return r_int(x // y)
-
- __rfloordiv__ = __rdiv__
-
- def __mod__(self, other):
- x = int(self)
- y = int(other)
- return r_int(x % y)
-
- def __rmod__(self, other):
- y = int(self)
- x = int(other)
- return r_int(x % y)
-
- def __divmod__(self, other):
- x = int(self)
- y = int(other)
- res = divmod(x, y)
- return (r_int(res[0]), r_int(res[1]))
-
- def __lshift__(self, n):
- # ensure long shift, so we don't depend on
- # shift truncation (2.3) vs. long(2.4)
- x = long(self)
- y = int(n)
- return r_int(x << y)
-
- def __rlshift__(self, n):
- y = long(self)
- x = int(n)
- return r_int(x << y)
-
- def __rshift__(self, n):
- x = int(self)
- y = int(n)
- return r_int(x >> y)
-
- def __rrshift__(self, n):
- y = int(self)
- x = int(n)
- return r_int(x >> y)
-
- def __or__(self, other):
- x = int(self)
- y = int(other)
- return r_int(x | y)
- __ror__ = __or__
-
- def __and__(self, other):
- x = int(self)
- y = int(other)
- return r_int(x & y)
- __rand__ = __and__
-
- def __xor__(self, other):
- x = int(self)
- y = int(other)
- return r_int(x ^ y)
- __rxor__ = __xor__
-
- def __neg__(self):
- x = int(self)
- return r_int(-x)
-
- def __pos__(self):
- return r_int(self)
-
- def __invert__(self):
- x = int(self)
- return r_int(~x)
-
- def __pow__(self, other, m=None):
- x = int(self)
- y = int(other)
- res = pow(x, y, m)
- return r_int(res)
-
- def __rpow__(self, other, m=None):
- y = int(self)
- x = int(other)
- res = pow(x, y, m)
- return r_int(res)
-
-# set up of machine internals
-_bits = 0
-_itest = 1
-_Ltest = 1L
-while _itest == _Ltest and type(_itest) is int:
- _itest *= 2
- _Ltest *= 2
- _bits += 1
-
-LONG_BIT = _bits+1
-LONG_MASK = _Ltest*2-1
-LONG_TEST = _Ltest
-
-def intmask(n):
- if isinstance(n, int):
- return n
- n &= LONG_MASK
- if n >= LONG_TEST:
- n -= 2*LONG_TEST
- return int(n)
-
-del _bits, _itest, _Ltest
-
-class r_uint(long):
- """ fake unsigned integer implementation """
-
- _mask = LONG_MASK
-
- def __new__(klass, val):
- return long.__new__(klass, val & klass._mask)
-
- def __add__(self, other):
- x = long(self)
- y = long(other)
- return r_uint(x + y)
- __radd__ = __add__
-
- def __sub__(self, other):
- x = long(self)
- y = long(other)
- return r_uint(x - y)
-
- def __rsub__(self, other):
- y = long(self)
- x = long(other)
- return r_uint(x - y)
-
- def __mul__(self, other):
- x = long(self)
- if not isinstance(other, (int, long)):
- return x * other
- y = long(other)
- return r_uint(x * y)
- __rmul__ = __mul__
-
- def __div__(self, other):
- x = long(self)
- y = long(other)
- return r_uint(x // y)
-
- __floordiv__ = __div__
-
- def __rdiv__(self, other):
- y = long(self)
- x = long(other)
- return r_uint(x // y)
-
- __rfloordiv__ = __rdiv__
-
- def __mod__(self, other):
- x = long(self)
- y = long(other)
- return r_uint(x % y)
-
- def __rmod__(self, other):
- y = long(self)
- x = long(other)
- return r_uint(x % y)
-
- def __divmod__(self, other):
- x = long(self)
- y = long(other)
- res = divmod(x, y)
- return (r_uint(res[0]), r_uint(res[1]))
-
- def __lshift__(self, n):
- x = long(self)
- y = long(n)
- return r_uint(x << y)
-
- def __rlshift__(self, n):
- y = long(self)
- x = long(n)
- return r_uint(x << y)
-
- def __rshift__(self, n):
- x = long(self)
- y = long(n)
- return r_uint(x >> y)
-
- def __rrshift__(self, n):
- y = long(self)
- x = long(n)
- return r_uint(x >> y)
-
- def __or__(self, other):
- x = long(self)
- y = long(other)
- return r_uint(x | y)
- __ror__ = __or__
-
- def __and__(self, other):
- x = long(self)
- y = long(other)
- return r_uint(x & y)
- __rand__ = __and__
-
- def __xor__(self, other):
- x = long(self)
- y = long(other)
- return r_uint(x ^ y)
- __rxor__ = __xor__
-
- def __neg__(self):
- x = long(self)
- return r_uint(-x)
-
- def __pos__(self):
- return r_uint(self)
-
- def __invert__(self):
- x = long(self)
- return r_uint(~x)
-
- def __pow__(self, other, m=None):
- x = long(self)
- y = long(other)
- res = pow(x, y, m)
- return r_uint(res)
-
- def __rpow__(self, other, m=None):
- y = long(self)
- x = long(other)
- res = pow(x, y, m)
- return r_uint(res)
Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py (original)
+++ pypy/dist/pypy/objspace/std/stringobject.py Fri Apr 8 19:22:15 2005
@@ -76,8 +76,8 @@
from pypy.objspace.std.objspace import *
from pypy.interpreter import gateway
+from pypy.tool.rarithmetic import intmask
from pypy.objspace.std.intobject import W_IntObject
-from pypy.objspace.std.restricted_int import intmask
from pypy.objspace.std.sliceobject import W_SliceObject
from pypy.objspace.std import slicetype
from pypy.objspace.std.listobject import W_ListObject
Deleted: /pypy/dist/pypy/objspace/std/test/test_restricted_int.py
==============================================================================
--- /pypy/dist/pypy/objspace/std/test/test_restricted_int.py Fri Apr 8 19:22:15 2005
+++ (empty file)
@@ -1,128 +0,0 @@
-import unittest
-import autopath
-from pypy.objspace.std.restricted_int import *
-import sys
-
-maxint_mask = (sys.maxint*2 + 1)
-
-objspacename = 'std'
-
-class Test_r_int:
-
- def setup_method(self,method):
- space = self.space
-
- def test__add__(self):
- self.binary_test(lambda x, y: x + y)
- def test__sub__(self):
- self.binary_test(lambda x, y: x - y)
- def test__mul__(self):
- self.binary_test(lambda x, y: x * y)
- x = 3; y = [2]
- assert x*y == r_int(x)*y
- assert y*x == y*r_int(x)
- def test__div__(self):
- self.binary_test(lambda x, y: x // y)
- def test__mod__(self):
- self.binary_test(lambda x, y: x % y)
- def test__divmod__(self):
- self.binary_test(divmod)
- def test__lshift__(self):
- self.binary_test(lambda x, y: x << y, (1, 2, 3))
- def test__rshift__(self):
- self.binary_test(lambda x, y: x >> y, (1, 2, 3))
- def test__or__(self):
- self.binary_test(lambda x, y: x | y)
- def test__and__(self):
- self.binary_test(lambda x, y: x & y)
- def test__xor__(self):
- self.binary_test(lambda x, y: x ^ y)
- def test__neg__(self):
- self.unary_test(lambda x: -x)
- def test__pos__(self):
- self.unary_test(lambda x: +x)
- def test__invert__(self):
- self.unary_test(lambda x: ~x)
- def test__pow__(self):
- self.binary_test(lambda x, y: x**y, (2, 3))
- self.binary_test(lambda x, y: pow(x, y, 42), (2, 3, 5, 1000))
-
- def unary_test(self, f):
- for arg in (-10, -1, 0, 3, 12345):
- res = f(arg)
- cmp = f(r_int(arg))
- assert res == cmp
-
- def binary_test(self, f, rargs = None):
- if not rargs:
- rargs = (-10, -1, 3, 55)
- for larg in (-10, -1, 0, 3, 1234):
- for rarg in rargs:
- for types in ((int, r_int), (r_int, int), (r_int, r_int)):
- res = f(larg, rarg)
- left, right = types
- cmp = f(left(larg), right(rarg))
- assert res == cmp
-
-class Test_r_uint:
-
- def setup_method(self,method):
- space = self.space
-
- def test__add__(self):
- self.binary_test(lambda x, y: x + y)
- def test__sub__(self):
- self.binary_test(lambda x, y: x - y)
- def test__mul__(self):
- self.binary_test(lambda x, y: x * y)
- x = 3; y = [2]
- assert x*y == r_uint(x)*y
- assert y*x == y*r_uint(x)
- def test__div__(self):
- self.binary_test(lambda x, y: x // y)
- def test__mod__(self):
- self.binary_test(lambda x, y: x % y)
- def test__divmod__(self):
- self.binary_test(divmod)
- def test__lshift__(self):
- self.binary_test(lambda x, y: x << y, (1, 2, 3))
- def test__rshift__(self):
- self.binary_test(lambda x, y: x >> y, (1, 2, 3))
- def test__or__(self):
- self.binary_test(lambda x, y: x | y)
- def test__and__(self):
- self.binary_test(lambda x, y: x & y)
- def test__xor__(self):
- self.binary_test(lambda x, y: x ^ y)
- def test__neg__(self):
- self.unary_test(lambda x: -x)
- def test__pos__(self):
- self.unary_test(lambda x: +x)
- def test__invert__(self):
- self.unary_test(lambda x: ~x)
- def test__pow__(self):
- self.binary_test(lambda x, y: x**y, (2, 3))
- # pow is buggy, dowsn't allow our type
- #self.binary_test(lambda x, y: pow(x, y, 42), (2, 3, 5, 1000))
-
- def unary_test(self, f):
- for arg in (0, 3, 12345):
- res = f(arg) & maxint_mask
- cmp = f(r_uint(arg))
- assert res == cmp
-
- def binary_test(self, f, rargs = None):
- mask = maxint_mask
- if not rargs:
- rargs = (1, 3, 55)
- for larg in (0, 1, 2, 3, 1234):
- for rarg in rargs:
- for types in ((int, r_uint), (r_uint, int), (r_uint, r_uint)):
- res = f(larg, rarg)
- left, right = types
- cmp = f(left(larg), right(rarg))
- if type(res) is tuple:
- res = res[0] & mask, res[1] & mask
- else:
- res = res & mask
- assert res == cmp
Modified: pypy/dist/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/tupleobject.py (original)
+++ pypy/dist/pypy/objspace/std/tupleobject.py Fri Apr 8 19:22:15 2005
@@ -1,6 +1,6 @@
from pypy.objspace.std.objspace import *
from pypy.objspace.std.intobject import W_IntObject
-from pypy.objspace.std.restricted_int import intmask
+from pypy.tool.rarithmetic import intmask
from pypy.objspace.std.sliceobject import W_SliceObject
from pypy.objspace.std import slicetype
from pypy.interpreter import gateway
Copied: pypy/dist/pypy/tool/test/test_rarithmetic.py (from r10438, pypy/dist/pypy/objspace/std/test/test_restricted_int.py)
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_restricted_int.py (original)
+++ pypy/dist/pypy/tool/test/test_rarithmetic.py Fri Apr 8 19:22:15 2005
@@ -1,6 +1,6 @@
import unittest
import autopath
-from pypy.objspace.std.restricted_int import *
+from pypy.tool.rarithmetic import *
import sys
maxint_mask = (sys.maxint*2 + 1)
Modified: pypy/dist/pypy/translator/genc/t_pyobj.py
==============================================================================
--- pypy/dist/pypy/translator/genc/t_pyobj.py (original)
+++ pypy/dist/pypy/translator/genc/t_pyobj.py Fri Apr 8 19:22:15 2005
@@ -5,7 +5,7 @@
from pypy.translator.genc.t_simple import CType
from types import FunctionType, CodeType, InstanceType, ClassType
-from pypy.objspace.std.restricted_int import r_int, r_uint
+from pypy.tool.rarithmetic import r_int, r_uint
class CPyObjectType(CType):
Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py (original)
+++ pypy/dist/pypy/translator/geninterplevel.py Fri Apr 8 19:22:15 2005
@@ -28,7 +28,7 @@
from types import FunctionType, CodeType, ModuleType
from pypy.interpreter.error import OperationError
from pypy.interpreter.argument import Arguments
-from pypy.objspace.std.restricted_int import r_int, r_uint
+from pypy.tool.rarithmetic import r_int, r_uint
from pypy.translator.translator import Translator
from pypy.objspace.flow import FlowObjSpace
More information about the Pypy-commit
mailing list