[pypy-svn] r75958 - pypy/branch/rsre2/pypy/rlib
arigo at codespeak.net
arigo at codespeak.net
Wed Jul 7 11:24:34 CEST 2010
Author: arigo
Date: Wed Jul 7 11:24:32 2010
New Revision: 75958
Modified:
pypy/branch/rsre2/pypy/rlib/debug.py
Log:
Rewrite check_nonneg() to give better positioning information when it fails.
Modified: pypy/branch/rsre2/pypy/rlib/debug.py
==============================================================================
--- pypy/branch/rsre2/pypy/rlib/debug.py (original)
+++ pypy/branch/rsre2/pypy/rlib/debug.py Wed Jul 7 11:24:32 2010
@@ -255,11 +255,20 @@
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)
+ assert x >= 0
+ return x
+
+class Entry(ExtRegistryEntry):
+ _about_ = check_nonneg
+
+ def compute_result_annotation(self, s_arg):
+ from pypy.annotation.model import SomeInteger
+ s_nonneg = SomeInteger(nonneg=True)
+ if not s_nonneg.contains(s_arg):
+ raise IntegerCanBeNegative
+ return s_arg
+
+ def specialize_call(self, hop):
+ hop.exception_cannot_occur()
+ return hop.inputarg(hop.args_r[0], arg=0)
More information about the Pypy-commit
mailing list