[pypy-svn] r12152 - in pypy/dist/pypy: annotation interpreter objspace/std objspace/std/test rpython rpython/test tool tool/test translator translator/genc translator/test
pedronis at codespeak.net
pedronis at codespeak.net
Tue May 10 15:36:01 CEST 2005
Author: pedronis
Date: Tue May 10 15:36:01 2005
New Revision: 12152
Added:
pypy/dist/pypy/rpython/rarithmetic.py
- copied unchanged from r12148, pypy/dist/pypy/tool/rarithmetic.py
pypy/dist/pypy/rpython/test/ (props changed)
pypy/dist/pypy/rpython/test/__init__.py
- copied unchanged from r12151, pypy/dist/pypy/rpython/__init__.py
pypy/dist/pypy/rpython/test/test_rarithmetic.py
- copied, changed from r12148, pypy/dist/pypy/tool/test/test_rarithmetic.py
Removed:
pypy/dist/pypy/tool/rarithmetic.py
pypy/dist/pypy/tool/test/test_rarithmetic.py
Modified:
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/annotation/model.py
pypy/dist/pypy/interpreter/baseobjspace.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/listsort.py
pypy/dist/pypy/objspace/std/longobject.py
pypy/dist/pypy/objspace/std/longtype.py
pypy/dist/pypy/objspace/std/stringobject.py
pypy/dist/pypy/objspace/std/strutil.py
pypy/dist/pypy/objspace/std/test/test_intobject.py
pypy/dist/pypy/objspace/std/test/test_longobject.py
pypy/dist/pypy/objspace/std/tupleobject.py
pypy/dist/pypy/rpython/ (props changed)
pypy/dist/pypy/translator/genc/pyobjtype.py
pypy/dist/pypy/translator/geninterplevel.py
pypy/dist/pypy/translator/simplify.py
pypy/dist/pypy/translator/test/snippet.py
pypy/dist/pypy/translator/test/test_annrpython.py
Log:
moving rarithmetic.py to rpython
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Tue May 10 15:36:01 2005
@@ -14,7 +14,7 @@
from pypy.interpreter.pycode import CO_VARARGS
from pypy.interpreter.pycode import cpython_code_signature
from pypy.interpreter.argument import ArgErr
-from pypy.tool.rarithmetic import r_uint
+from pypy.rpython.rarithmetic import r_uint
from pypy.tool.unionfind import UnionFind
import inspect, new
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Tue May 10 15:36:01 2005
@@ -10,7 +10,7 @@
from pypy.annotation.model import SomeFloat, unionof
from pypy.annotation.bookkeeper import getbookkeeper
from pypy.objspace.flow.model import Constant
-import pypy.tool.rarithmetic
+import pypy.rpython.rarithmetic
# convenience only!
def immutablevalue(x):
@@ -53,7 +53,7 @@
r = SomeBool()
if s_type.is_constant():
typ = s_type.const
- if typ == pypy.tool.rarithmetic.r_uint:
+ if typ == pypy.rpython.rarithmetic.r_uint:
if s_obj.is_constant():
r.const = isinstance(s_obj.const, typ)
else:
@@ -203,10 +203,10 @@
original = getattr(__builtin__, name[8:])
BUILTIN_ANALYZERS[original] = value
-BUILTIN_ANALYZERS[pypy.tool.rarithmetic.r_uint] = restricted_uint
-BUILTIN_ANALYZERS[pypy.tool.rarithmetic.ovfcheck] = rarith_ovfcheck
-BUILTIN_ANALYZERS[pypy.tool.rarithmetic.ovfcheck_lshift] = rarith_ovfcheck_lshift
-BUILTIN_ANALYZERS[pypy.tool.rarithmetic.intmask] = rarith_intmask
+BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.r_uint] = restricted_uint
+BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.ovfcheck] = rarith_ovfcheck
+BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.ovfcheck_lshift] = rarith_ovfcheck_lshift
+BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.intmask] = rarith_intmask
BUILTIN_ANALYZERS[Exception.__init__.im_func] = exception_init
# this one is needed otherwise when annotating assert in a test we may try to annotate
Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py (original)
+++ pypy/dist/pypy/annotation/model.py Tue May 10 15:36:01 2005
@@ -118,7 +118,7 @@
knowntype = int
def __init__(self, nonneg=False, unsigned=False):
self.nonneg = unsigned or nonneg
- self.unsigned = unsigned # pypy.tool.rarithmetic.r_uint
+ self.unsigned = unsigned # pypy.rpython.rarithmetic.r_uint
class SomeBool(SomeInteger):
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Tue May 10 15:36:01 2005
@@ -3,7 +3,7 @@
from pypy.interpreter.miscutils import getthreadlocals
from pypy.interpreter.argument import Arguments
from pypy.tool.cache import Cache
-from pypy.tool.rarithmetic import r_uint
+from pypy.rpython.rarithmetic import r_uint
__all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'BaseWrappable',
'W_Root']
Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictobject.py Tue May 10 15:36:01 2005
@@ -8,7 +8,7 @@
from pypy.objspace.std.objspace import *
from pypy.interpreter import gateway
-from pypy.tool.rarithmetic import r_uint
+from pypy.rpython.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 Tue May 10 15:36:01 2005
@@ -1,6 +1,6 @@
from pypy.objspace.std.objspace import *
from pypy.objspace.std.noneobject import W_NoneObject
-from pypy.tool.rarithmetic import ovfcheck, ovfcheck_lshift, LONG_BIT, r_uint
+from pypy.rpython.rarithmetic import ovfcheck, ovfcheck_lshift, LONG_BIT, r_uint
"""
In order to have the same behavior running
Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py (original)
+++ pypy/dist/pypy/objspace/std/listobject.py Tue May 10 15:36:01 2005
@@ -5,7 +5,7 @@
from pypy.objspace.std import slicetype
from pypy.interpreter import gateway, baseobjspace
-from pypy.tool.rarithmetic import r_uint
+from pypy.rpython.rarithmetic import r_uint
from pypy.objspace.std.listsort import TimSort
Modified: pypy/dist/pypy/objspace/std/listsort.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listsort.py (original)
+++ pypy/dist/pypy/objspace/std/listsort.py Tue May 10 15:36:01 2005
@@ -1,4 +1,4 @@
-from pypy.tool.rarithmetic import ovfcheck, ovfcheck_lshift
+from pypy.rpython.rarithmetic import ovfcheck, ovfcheck_lshift
## ------------------------------------------------------------------------
Modified: pypy/dist/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longobject.py (original)
+++ pypy/dist/pypy/objspace/std/longobject.py Tue May 10 15:36:01 2005
@@ -3,8 +3,8 @@
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.floatobject import W_FloatObject
from pypy.objspace.std.noneobject import W_NoneObject
-from pypy.tool.rarithmetic import intmask, r_uint, LONG_MASK
-from pypy.tool.rarithmetic import LONG_BIT
+from pypy.rpython.rarithmetic import intmask, r_uint, LONG_MASK
+from pypy.rpython.rarithmetic import LONG_BIT
import math
Modified: pypy/dist/pypy/objspace/std/longtype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longtype.py (original)
+++ pypy/dist/pypy/objspace/std/longtype.py Tue May 10 15:36:01 2005
@@ -3,7 +3,7 @@
from pypy.interpreter.error import OperationError
from pypy.objspace.std.inttype import int_typedef
from pypy.interpreter.gateway import NoneNotWrapped
-from pypy.tool.rarithmetic import r_uint
+from pypy.rpython.rarithmetic import r_uint
def descr__new__(space, w_longtype, w_value=0, w_base=NoneNotWrapped):
from pypy.objspace.std.longobject import W_LongObject, args_from_long
Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py (original)
+++ pypy/dist/pypy/objspace/std/stringobject.py Tue May 10 15:36:01 2005
@@ -2,7 +2,7 @@
from pypy.objspace.std.objspace import *
from pypy.interpreter import gateway
-from pypy.tool.rarithmetic import intmask, ovfcheck
+from pypy.rpython.rarithmetic import intmask, ovfcheck
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.sliceobject import W_SliceObject
from pypy.objspace.std import slicetype
Modified: pypy/dist/pypy/objspace/std/strutil.py
==============================================================================
--- pypy/dist/pypy/objspace/std/strutil.py (original)
+++ pypy/dist/pypy/objspace/std/strutil.py Tue May 10 15:36:01 2005
@@ -2,7 +2,7 @@
Pure Python implementation of string utilities.
"""
-from pypy.tool.rarithmetic import r_uint, ovfcheck
+from pypy.rpython.rarithmetic import r_uint, ovfcheck
# XXX factor more functions out of stringobject.py.
# This module is independent from PyPy.
Modified: pypy/dist/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_intobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_intobject.py Tue May 10 15:36:01 2005
@@ -2,7 +2,7 @@
import autopath
from pypy.objspace.std import intobject as iobj
from pypy.objspace.std.objspace import FailedToImplement
-from pypy.tool.rarithmetic import r_uint
+from pypy.rpython.rarithmetic import r_uint
objspacename = 'std'
Modified: pypy/dist/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_longobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_longobject.py Tue May 10 15:36:01 2005
@@ -3,7 +3,7 @@
from random import random, randint
from pypy.objspace.std import longobject as lobj
from pypy.objspace.std.objspace import FailedToImplement
-from pypy.tool.rarithmetic import r_uint
+from pypy.rpython.rarithmetic import r_uint
objspacename = 'std'
Modified: pypy/dist/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/tupleobject.py (original)
+++ pypy/dist/pypy/objspace/std/tupleobject.py Tue May 10 15:36:01 2005
@@ -1,6 +1,6 @@
from pypy.objspace.std.objspace import *
from pypy.objspace.std.intobject import W_IntObject
-from pypy.tool.rarithmetic import intmask
+from pypy.rpython.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/rpython/test/test_rarithmetic.py (from r12148, pypy/dist/pypy/tool/test/test_rarithmetic.py)
==============================================================================
--- pypy/dist/pypy/tool/test/test_rarithmetic.py (original)
+++ pypy/dist/pypy/rpython/test/test_rarithmetic.py Tue May 10 15:36:01 2005
@@ -1,6 +1,4 @@
-import unittest
-import autopath
-from pypy.tool.rarithmetic import *
+from pypy.rpython.rarithmetic import *
import sys
Deleted: /pypy/dist/pypy/tool/rarithmetic.py
==============================================================================
--- /pypy/dist/pypy/tool/rarithmetic.py Tue May 10 15:36:01 2005
+++ (empty file)
@@ -1,310 +0,0 @@
-"""
-This file defines restricted arithmetic:
-
-classes and operations to express integer arithmetic,
-such that before and after translation semantics are
-consistent
-
-r_uint an unsigned integer which has not overflow
- checking. It is always positive and always
- truncated to the internal machine word size.
-intmask mask a possibly long value when running on CPython
- back to a signed int value
-ovfcheck check on CPython whether the result of a signed
- integer operation did overflow
-ovfcheck_lshift
- << with oveflow checking
- catering to 2.3/2.4 differences about <<
-
-These are meant to be erased by translation, r_uint
-in the process should mark unsigned values, ovfcheck should
-mark where overflow checking is required.
-
-
-"""
-
-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
- if isinstance(n, r_uint):
- n = long(n)
- n &= LONG_MASK
- if n >= LONG_TEST:
- n -= 2*LONG_TEST
- return int(n)
-
-del _bits, _itest, _Ltest
-
-def ovfcheck(r):
- # to be used as ovfcheck(x <op> y)
- # raise OverflowError if the operation did overflow
- assert not isinstance(r, r_uint), "unexpected ovf check on unsigned"
- if isinstance(r, long):
- raise OverflowError, "signed integer expression did overflow"
- return r
-
-def ovfcheck_lshift(a, b):
- return ovfcheck(int(long(a) << b))
-
-class r_uint(long):
- """ fake unsigned integer implementation """
-
- _mask = LONG_MASK
-
- def __new__(klass, val):
- return long.__new__(klass, val & klass._mask)
-
- def __int__(self):
- if self < LONG_TEST:
- return long.__int__(self)
- else:
- return intmask(self)
-
- 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)
Deleted: /pypy/dist/pypy/tool/test/test_rarithmetic.py
==============================================================================
--- /pypy/dist/pypy/tool/test/test_rarithmetic.py Tue May 10 15:36:01 2005
+++ (empty file)
@@ -1,218 +0,0 @@
-import unittest
-import autopath
-from pypy.tool.rarithmetic import *
-import sys
-
-
-maxint_mask = (sys.maxint*2 + 1)
-machbits = 0
-i = 1
-l = 1L
-while i == l and type(i) is int:
- i *= 2
- l *= 2
- machbits += 1
-#print machbits
-
-
-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 test_back_to_int(self):
- assert int(r_uint(-1)) == -1
- assert int(r_uint(1)) == 1
-
- 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
-
-def test_intmask():
- assert intmask(1) == 1
- assert intmask(sys.maxint) == sys.maxint
- minint = -sys.maxint-1
- assert intmask(minint) == minint
- assert intmask(2*sys.maxint+1) == -1
- assert intmask(sys.maxint*2) == -2
- assert intmask(sys.maxint*2+2) == 0
- assert intmask(2*(sys.maxint*1+1)) == 0
- assert intmask(1 << (machbits-1)) == 1 << (machbits-1)
- assert intmask(sys.maxint+1) == minint
- assert intmask(minint-1) == sys.maxint
- assert intmask(r_uint(-1)) == -1
-
-
-def test_ovfcheck():
- one = 1
- x = sys.maxint
- minusx = -sys.maxint
- n = -sys.maxint-1
- y = sys.maxint-1
- # sanity
- raises(AssertionError, ovfcheck, r_uint(0))
-
- # not overflowing
- try:
- ovfcheck(y+one)
- except OverflowError:
- assert False
- else:
- pass
- try:
- ovfcheck(minusx-one)
- except OverflowError:
- assert False
- else:
- pass
- try:
- ovfcheck(x-x)
- except OverflowError:
- assert False
- else:
- pass
- try:
- ovfcheck(n-n)
- except OverflowError:
- assert False
- else:
- pass
-
- # overflowing
- try:
- ovfcheck(x+one)
- except OverflowError:
- pass
- else:
- assert False
- try:
- ovfcheck(x+x)
- except OverflowError:
- pass
- else:
- assert False
- try:
- ovfcheck(n-one)
- except OverflowError:
- pass
- else:
- assert False
- try:
- ovfcheck(n-y)
- except OverflowError:
- pass
- else:
- assert False
Modified: pypy/dist/pypy/translator/genc/pyobjtype.py
==============================================================================
--- pypy/dist/pypy/translator/genc/pyobjtype.py (original)
+++ pypy/dist/pypy/translator/genc/pyobjtype.py Tue May 10 15:36:01 2005
@@ -5,7 +5,7 @@
from pypy.translator.genc.basetype import CType
from types import FunctionType, CodeType, InstanceType, ClassType
-from pypy.tool.rarithmetic import r_int, r_uint
+from pypy.rpython.rarithmetic import r_int, r_uint
# XXX maybe this can be done more elegantly:
# needed to convince should_translate_attr
Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py (original)
+++ pypy/dist/pypy/translator/geninterplevel.py Tue May 10 15:36:01 2005
@@ -29,7 +29,7 @@
from types import FunctionType, CodeType, ModuleType
from pypy.interpreter.error import OperationError
from pypy.interpreter.argument import Arguments
-from pypy.tool.rarithmetic import r_int, r_uint
+from pypy.rpython.rarithmetic import r_int, r_uint
from pypy.translator.translator import Translator
from pypy.objspace.flow import FlowObjSpace
Modified: pypy/dist/pypy/translator/simplify.py
==============================================================================
--- pypy/dist/pypy/translator/simplify.py (original)
+++ pypy/dist/pypy/translator/simplify.py Tue May 10 15:36:01 2005
@@ -65,7 +65,7 @@
# this is the case if no exception handling was provided.
# Otherwise, we have a block ending in the operation,
# followed by a block with a single ovfcheck call.
- from pypy.tool.rarithmetic import ovfcheck, ovfcheck_lshift
+ from pypy.rpython.rarithmetic import ovfcheck, ovfcheck_lshift
from pypy.objspace.flow.objspace import op_appendices
from pypy.objspace.flow.objspace import implicit_exceptions
covf = Constant(ovfcheck)
Modified: pypy/dist/pypy/translator/test/snippet.py
==============================================================================
--- pypy/dist/pypy/translator/test/snippet.py (original)
+++ pypy/dist/pypy/translator/test/snippet.py Tue May 10 15:36:01 2005
@@ -84,7 +84,7 @@
def simple_func(i=numtype):
return i + 1
-from pypy.tool.rarithmetic import ovfcheck, ovfcheck_lshift
+from pypy.rpython.rarithmetic import ovfcheck, ovfcheck_lshift
def add_func(i=numtype):
try:
Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py (original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py Tue May 10 15:36:01 2005
@@ -8,7 +8,7 @@
from pypy.annotation.listdef import ListDef
from pypy.annotation.dictdef import DictDef
from pypy.objspace.flow.model import *
-from pypy.tool.rarithmetic import r_uint
+from pypy.rpython.rarithmetic import r_uint
from pypy.translator.test import snippet
@@ -801,7 +801,6 @@
py.test.raises(KeyError, "access_sets[object()]")
def test_isinstance_usigned(self):
- from pypy.tool.rarithmetic import r_uint
def f(x):
return isinstance(x, r_uint)
def g():
More information about the Pypy-commit
mailing list