[pypy-svn] r13414 - in pypy/dist/pypy: annotation objspace/flow rpython
arigo at codespeak.net
arigo at codespeak.net
Tue Jun 14 23:00:36 CEST 2005
Author: arigo
Date: Tue Jun 14 23:00:32 2005
New Revision: 13414
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/objspace/flow/objspace.py
pypy/dist/pypy/objspace/flow/operation.py
pypy/dist/pypy/rpython/rint.py
Log:
Added is_true and xxx_ovf operations in the table of flow/operation.py.
Some more simplifications about which _ovf operations can exist: indeed,
it's not possible to use the ovfcheck(a <op> b) syntax with the following
operations:
divmod
inplace_*
Moreover, 'invert' can never raise OverflowError in any case, and neither can
'truediv' with integer arguments.
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Tue Jun 14 23:00:32 2005
@@ -35,8 +35,7 @@
'coerce',
]
+[opname+'_ovf' for opname in
- """add sub mul truediv
- floordiv div mod divmod pow lshift
+ """add sub mul floordiv div mod pow lshift
""".split()
])
Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py (original)
+++ pypy/dist/pypy/objspace/flow/objspace.py Tue Jun 14 23:00:32 2005
@@ -465,11 +465,12 @@
inplace_add inplace_sub inplace_mul inplace_truediv
inplace_floordiv inplace_div inplace_mod inplace_divmod
inplace_pow""", FloatingPointError)
-_add_except_ovf("""neg abs invert add sub mul truediv
- floordiv div mod divmod pow lshift
+_add_exceptions("""truediv divmod
inplace_add inplace_sub inplace_mul inplace_truediv
inplace_floordiv inplace_div inplace_mod inplace_pow
- inplace_lshift""")
+ inplace_lshift""", OverflowError) # without a _ovf version
+_add_except_ovf("""neg abs add sub mul
+ floordiv div mod pow lshift""") # with a _ovf version
del _add_exceptions, _add_except_ovf
def extract_cell_content(c):
Modified: pypy/dist/pypy/objspace/flow/operation.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/operation.py (original)
+++ pypy/dist/pypy/objspace/flow/operation.py Tue Jun 14 23:00:32 2005
@@ -5,6 +5,7 @@
from pypy.interpreter.baseobjspace import ObjSpace
import operator, types, __future__
from pypy.tool.sourcetools import compile2
+from pypy.rpython.rarithmetic import ovfcheck, ovfcheck_lshift
FunctionByName = {} # dict {"operation_name": <built-in function>}
OperationName = {} # dict {<built-in function>: "operation_name"}
@@ -100,6 +101,36 @@
def userdel(x):
x.__del__()
+def neg_ovf(x):
+ return ovfcheck(-x)
+
+def abs_ovf(x):
+ return ovfcheck(abs(x))
+
+def add_ovf(x, y):
+ return ovfcheck(x + y)
+
+def sub_ovf(x, y):
+ return ovfcheck(x - y)
+
+def mul_ovf(x, y):
+ return ovfcheck(x * y)
+
+def floordiv_ovf(x, y):
+ return ovfcheck(operator.floordiv(x, y))
+
+def div_ovf(x, y):
+ return ovfcheck(operator.div(x, y))
+
+def mod_ovf(x, y):
+ return ovfcheck(x % y)
+
+def pow_ovf(*two_or_three_args):
+ return ovfcheck(pow(*two_or_three_args))
+
+def lshift_ovf(x, y):
+ return ovfcheck_lshift(x, y)
+
# ____________________________________________________________
# The following table can list several times the same operation name,
@@ -122,6 +153,8 @@
('delattr', delattr),
('nonzero', bool),
('nonzero', operator.truth),
+ ('is_true', bool),
+ ('is_true', operator.truth),
('abs' , abs),
('hex', hex),
('oct', oct),
@@ -152,6 +185,17 @@
('set', set),
('delete', delete),
('userdel', userdel),
+ # --- operations added by graph transformations ---
+ ('neg_ovf', neg_ovf),
+ ('abs_ovf', abs_ovf),
+ ('add_ovf', add_ovf),
+ ('sub_ovf', sub_ovf),
+ ('mul_ovf', mul_ovf),
+ ('floordiv_ovf', floordiv_ovf),
+ ('div_ovf', div_ovf),
+ ('mod_ovf', mod_ovf),
+ ('pow_ovf', pow_ovf),
+ ('lshift_ovf', lshift_ovf),
]
def setup():
@@ -166,8 +210,8 @@
for name, func in Table:
if name not in FunctionByName:
FunctionByName[name] = func
- assert func not in OperationName
- OperationName[func] = name
+ if func not in OperationName:
+ OperationName[func] = name
# check that the result is complete
for line in ObjSpace.MethodTable:
name = line[0]
Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py (original)
+++ pypy/dist/pypy/rpython/rint.py Tue Jun 14 23:00:32 2005
@@ -74,9 +74,6 @@
return _rtype_template(hop, 'truediv', [ZeroDivisionError])
rtype_inplace_truediv = rtype_truediv
- def rtype_truediv_ovf(_, hop):
- return _rtype_template(hop, 'truediv_ovf', [ZeroDivisionError])
-
def rtype_mod(_, hop):
return _rtype_template(hop, 'mod', [ZeroDivisionError])
rtype_inplace_mod = rtype_mod
More information about the Pypy-commit
mailing list