[pypy-svn] r75675 - in pypy/trunk/pypy/rlib: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Jun 30 12:50:11 CEST 2010
Author: arigo
Date: Wed Jun 30 12:50:10 2010
New Revision: 75675
Modified:
pypy/trunk/pypy/rlib/debug.py
pypy/trunk/pypy/rlib/test/test_debug.py
Log:
An annotation-time check: check_nonneg().
Modified: pypy/trunk/pypy/rlib/debug.py
==============================================================================
--- pypy/trunk/pypy/rlib/debug.py (original)
+++ pypy/trunk/pypy/rlib/debug.py Wed Jun 30 12:50:10 2010
@@ -250,3 +250,16 @@
def specialize_call(self, hop):
hop.exception_cannot_occur()
return hop.inputarg(hop.args_r[0], arg=0)
+
+
+class IntegerCanBeNegative(Exception):
+ pass
+
+def _check_nonneg(ann, bk):
+ from pypy.annotation.model import SomeInteger
+ s_nonneg = SomeInteger(nonneg=True)
+ if not s_nonneg.contains(ann):
+ raise IntegerCanBeNegative
+
+def check_nonneg(x):
+ check_annotation(x, _check_nonneg)
Modified: pypy/trunk/pypy/rlib/test/test_debug.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_debug.py (original)
+++ pypy/trunk/pypy/rlib/test/test_debug.py Wed Jun 30 12:50:10 2010
@@ -3,6 +3,7 @@
from pypy.rlib.debug import check_annotation, make_sure_not_resized
from pypy.rlib.debug import debug_print, debug_start, debug_stop
from pypy.rlib.debug import have_debug_prints
+from pypy.rlib.debug import check_nonneg, IntegerCanBeNegative
from pypy.rlib import debug
from pypy.rpython.test.test_llinterp import interpret
@@ -30,6 +31,16 @@
py.test.raises(Error, "interpret(g, [3])")
+def test_check_nonneg():
+ def f(x):
+ assert x >= 5
+ check_nonneg(x)
+ interpret(f, [9])
+
+ def g(x):
+ check_nonneg(x-1)
+ py.test.raises(IntegerCanBeNegative, interpret, g, [9])
+
def test_make_sure_not_resized():
from pypy.annotation.listdef import TooLateForChange
def f():
More information about the Pypy-commit
mailing list