[pypy-svn] r76920 - in pypy/trunk/pypy: annotation annotation/test rlib
arigo at codespeak.net
arigo at codespeak.net
Tue Sep 7 16:47:19 CEST 2010
Author: arigo
Date: Tue Sep 7 16:47:17 2010
New Revision: 76920
Modified:
pypy/trunk/pypy/annotation/bookkeeper.py
pypy/trunk/pypy/annotation/builtin.py
pypy/trunk/pypy/annotation/classdef.py
pypy/trunk/pypy/annotation/test/test_annrpython.py
pypy/trunk/pypy/rlib/rarithmetic.py
Log:
Change annotation to say that int(r_uint(x)) is invalid:
you have to call intmask(). Fix one place that use it
in rlib. Also fix an issue where unexpected constants
of type "long", but actually that fit an "int", show up
during translation (e.g. constants from .pyc files
generated under 32-bit and loaded under 64-bit).
Modified: pypy/trunk/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/trunk/pypy/annotation/bookkeeper.py (original)
+++ pypy/trunk/pypy/annotation/bookkeeper.py Tue Sep 7 16:47:17 2010
@@ -338,8 +338,12 @@
result = SomeBool()
elif tp is int:
result = SomeInteger(nonneg = x>=0)
- elif tp is long and 0 <= x <= (sys.maxint * 2 + 1):
- result = SomeInteger(unsigned = True)
+ elif tp is long:
+ if -sys.maxint-1 <= x <= sys.maxint:
+ x = int(x)
+ result = SomeInteger(nonneg = x>=0)
+ else:
+ raise Exception("seeing a prebuilt long (value %s)" % hex(x))
elif issubclass(tp, str): # py.lib uses annotated str subclasses
if len(x) == 1:
result = SomeChar()
Modified: pypy/trunk/pypy/annotation/builtin.py
==============================================================================
--- pypy/trunk/pypy/annotation/builtin.py (original)
+++ pypy/trunk/pypy/annotation/builtin.py Tue Sep 7 16:47:17 2010
@@ -92,6 +92,8 @@
return s_obj.is_true()
def builtin_int(s_obj, s_base=None):
+ if isinstance(s_obj, SomeInteger):
+ assert not s_obj.unsigned, "instead of int(r_uint(x)), use intmask(r_uint(x))"
assert (s_base is None or isinstance(s_base, SomeInteger)
and s_obj.knowntype == str), "only int(v|string) or int(string,int) expected"
if s_base is not None:
Modified: pypy/trunk/pypy/annotation/classdef.py
==============================================================================
--- pypy/trunk/pypy/annotation/classdef.py (original)
+++ pypy/trunk/pypy/annotation/classdef.py Tue Sep 7 16:47:17 2010
@@ -276,6 +276,8 @@
# create the Attribute and do the generalization asked for
newattr = Attribute(attr, self.bookkeeper)
if s_value:
+ if newattr.name == 'intval' and getattr(s_value, 'unsigned', False):
+ import pdb; pdb.set_trace()
newattr.s_value = s_value
# keep all subattributes' values
Modified: pypy/trunk/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/trunk/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/trunk/pypy/annotation/test/test_annrpython.py Tue Sep 7 16:47:17 2010
@@ -767,7 +767,6 @@
assert s.classdef is a.bookkeeper.getuniqueclassdef(IndexError) # KeyError ignored because l is a list
def test_overrides(self):
- import sys
excs = []
def record_exc(e):
"""NOT_RPYTHON"""
@@ -869,8 +868,27 @@
def f():
return large_constant
a = self.RPythonAnnotator()
+ py.test.raises(Exception, a.build_types, f, [])
+ # if you want to get a r_uint, you have to be explicit about it
+
+ def test_prebuilt_long_that_is_not_too_long(self):
+ small_constant = 12L
+ def f():
+ return small_constant
+ a = self.RPythonAnnotator()
s = a.build_types(f, [])
- assert s.knowntype == r_uint
+ assert s.const == 12
+ assert s.nonneg
+ assert not s.unsigned
+ #
+ small_constant = -23L
+ def f():
+ return small_constant
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert s.const == -23
+ assert not s.nonneg
+ assert not s.unsigned
def test_pbc_getattr(self):
class C:
@@ -1386,7 +1404,6 @@
assert isinstance(a.binding(ev), annmodel.SomeInstance) and a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(Exception)
def test_sys_attrs(self):
- import sys
def f():
return sys.argv[0]
a = self.RPythonAnnotator()
Modified: pypy/trunk/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/trunk/pypy/rlib/rarithmetic.py (original)
+++ pypy/trunk/pypy/rlib/rarithmetic.py Tue Sep 7 16:47:17 2010
@@ -74,7 +74,7 @@
def widen(n):
from pypy.rpython.lltypesystem import lltype
if _should_widen_type(lltype.typeOf(n)):
- return int(n)
+ return intmask(n)
else:
return n
widen._annspecialcase_ = 'specialize:argtype(0)'
More information about the Pypy-commit
mailing list