[pypy-svn] r25092 - in pypy/dist/pypy/translator/cli: . test

antocuni at codespeak.net antocuni at codespeak.net
Tue Mar 28 23:18:34 CEST 2006


Author: antocuni
Date: Tue Mar 28 23:18:15 2006
New Revision: 25092

Modified:
   pypy/dist/pypy/translator/cli/function.py
   pypy/dist/pypy/translator/cli/opcodes.py
   pypy/dist/pypy/translator/cli/test/compile.py
   pypy/dist/pypy/translator/cli/test/test_op.py
   pypy/dist/pypy/translator/cli/test/test_overflow.py
Log:
More overflow support.
Added special tests for int_le and int_ge operations


Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py	(original)
+++ pypy/dist/pypy/translator/cli/function.py	Tue Mar 28 23:18:15 2006
@@ -2,7 +2,7 @@
 from pypy.rpython.lltypesystem.lltype import Void
 from pypy.translator.cli.option import getoption
 from pypy.translator.cli import cts
-from pypy.translator.cli.opcodes import opcodes, DoNothing, PushArgs
+from pypy.translator.cli.opcodes import opcodes, DoNothing, PushArgs, PushArg
 
 from pypy.tool.ansi_print import ansi_log
 import py
@@ -206,6 +206,8 @@
             if instr is PushArgs:
                 for arg in op.args:
                     self._push(arg)
+            elif isinstance(instr, PushArg):
+                self._push(op.args[instr.arg])
             else:
                 self.ilasm.opcode(instr)
 

Modified: pypy/dist/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/dist/pypy/translator/cli/opcodes.py	(original)
+++ pypy/dist/pypy/translator/cli/opcodes.py	Tue Mar 28 23:18:15 2006
@@ -4,6 +4,10 @@
 # come useful instruction patterns
 Not = ['ldc.i4.0', 'ceq']
 
+class PushArg(object):
+    def __init__(self, arg):
+        self.arg = arg
+
 def _not(op):
     return [PushArgs, op]+Not
 
@@ -55,20 +59,20 @@
     'int_sub_ovf':              'sub.ovf',
     'int_mul_ovf':              'mul.ovf',
 #    'int_div_ovf':              None,
-    'int_floordiv_ovf':         None,
-    'int_mod_ovf':              None,
-    'int_lt_ovf':               None,
-    'int_le_ovf':               None,
-    'int_eq_ovf':               None,
-    'int_ne_ovf':               None,
-    'int_gt_ovf':               None,
-    'int_ge_ovf':               None,
-    'int_and_ovf':              None,
-    'int_or_ovf':               None,
-    'int_lshift_ovf':           None,
-    'int_rshift_ovf':           None,
-    'int_xor_ovf':              None,
-    'int_floordiv_ovf_zer':     None,
+    'int_floordiv_ovf':         'div', # these can't overflow!
+    'int_mod_ovf':              'rem',
+    'int_lt_ovf':               'clt',
+    'int_le_ovf':               _not('cgt'),
+    'int_eq_ovf':               'ceq',
+    'int_ne_ovf':               _not('ceq'),
+    'int_gt_ovf':               'cgt',
+    'int_ge_ovf':               _not('clt'),
+    'int_and_ovf':              'and',
+    'int_or_ovf':               'or',
+    'int_lshift_ovf_val':       [PushArg(0), 'conv.i8', PushArg(1), 'shl', 'conv.ovf.i4'],
+    'int_rshift_ovf':           'shr', # these can't overflow!
+    'int_xor_ovf':              'xor',
+    'int_floordiv_ovf_zer':     None,  # what's the meaning?
     'int_mod_ovf_zer':          None,
 
     'uint_is_true':             DoNothing,

Modified: pypy/dist/pypy/translator/cli/test/compile.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/compile.py	(original)
+++ pypy/dist/pypy/translator/cli/test/compile.py	Tue Mar 28 23:18:15 2006
@@ -24,18 +24,11 @@
         print 'OK'
 
 
-def foo():
+def foo(x, y, z):
     pass
 
 def bar(x, y):
-    try:
-        foo()
-        z = x
-    except OverflowError:
-        z = x+y
-
-    return z
-
+    foo(x+y, x-y, x*y)
 
 f = compile_function(bar, [int, int])
 

Modified: pypy/dist/pypy/translator/cli/test/test_op.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_op.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_op.py	Tue Mar 28 23:18:15 2006
@@ -4,6 +4,11 @@
 import sys
 
 def test_op():
+    yield check, op_any_ge, [int, int], (42, 42)
+    yield check, op_any_ge, [int, int], (13, 42)    
+    yield check, op_any_le, [int, int], (42, 42)
+    yield check, op_any_le, [int, int], (13, 42)    
+    
     for name, func in globals().iteritems():
         if not name.startswith('op_'):
             continue

Modified: pypy/dist/pypy/translator/cli/test/test_overflow.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_overflow.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_overflow.py	Tue Mar 28 23:18:15 2006
@@ -21,7 +21,21 @@
     except OverflowError:
         return 42
 
+def op_lshift(x, y):
+    try:
+        return ovfcheck(x<<y)
+    except OverflowError:
+        return 42
+
+def op_neg(x):
+    try:
+        return ovfcheck(-x)
+    except OverflowError:
+        return 42
+
 def test_overflow():
     yield check, op_add, [int, int], (sys.maxint, 1)
     yield check, op_sub, [int, int], (-sys.maxint, 1)
     yield check, op_mul, [int, int], (sys.maxint/2 + 1, 2)
+    yield check, op_lshift, [int, int], (2, 30)
+    yield check, op_neg, [int], (-sys.maxint-1,)



More information about the Pypy-commit mailing list