[pypy-svn] r45414 - in pypy/dist/pypy/translator/jvm: . src/pypy test

pdg at codespeak.net pdg at codespeak.net
Fri Jul 27 20:48:04 CEST 2007


Author: pdg
Date: Fri Jul 27 20:48:04 2007
New Revision: 45414

Modified:
   pypy/dist/pypy/translator/jvm/generator.py
   pypy/dist/pypy/translator/jvm/opcodes.py
   pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
   pypy/dist/pypy/translator/jvm/test/test_overflow.py
Log:
translator/jvm - added overflow detection for left shifting and updated test_overflow to reflect that.  The overflow code is nearly identical to the c backend version from int.h (pdg)

Modified: pypy/dist/pypy/translator/jvm/generator.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/generator.py	(original)
+++ pypy/dist/pypy/translator/jvm/generator.py	Fri Jul 27 20:48:04 2007
@@ -383,6 +383,8 @@
 LFLOORDIVZEROVF =       Method.s(jPyPy, 'floordiv_zer_ovf', (jLong, jLong), jLong)
 IREMOVF =               Method.s(jPyPy, 'mod_ovf', (jInt, jInt), jInt)
 LREMOVF =               Method.s(jPyPy, 'mod_ovf', (jLong, jLong), jLong)
+ISHLOVF =               Method.s(jPyPy, 'lshift_ovf', (jInt, jInt), jInt)
+LSHLOVF =               Method.s(jPyPy, 'lshift_ovf', (jLong, jLong), jLong)
 MATHDPOW =              Method.s(jMath, 'pow', (jDouble, jDouble), jDouble)
 PRINTSTREAMPRINTSTR =   Method.v(jPrintStream, 'print', (jString,), jVoid)
 CLASSFORNAME =          Method.s(jClass, 'forName', (jString,), jClass)

Modified: pypy/dist/pypy/translator/jvm/opcodes.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/opcodes.py	(original)
+++ pypy/dist/pypy/translator/jvm/opcodes.py	Fri Jul 27 20:48:04 2007
@@ -54,8 +54,8 @@
     'oohash':                   [PushAllArgs, jvmgen.OBJHASHCODE, StoreResult], 
     'oostring':                 [OOString, StoreResult],
     #'ooparse_int':              [PushAllArgs, 'call int32 [pypylib]pypy.runtime.Utils::OOParseInt(string, int32)'],
-    'ooparse_float':            [PushAllArgs, 'call float64 [pypylib]pypy.runtime.Utils::OOParseFloat(string)'],
-	'oonewcustomdict':          [NewCustomDict, StoreResult],
+    #'ooparse_float':            [PushAllArgs, 'call float64 [pypylib]pypy.runtime.Utils::OOParseFloat(string)'],
+    'oonewcustomdict':          [NewCustomDict, StoreResult],
     #
     'same_as':                  DoNothing,
     'hint':                     [PushArg(0), StoreResult],
@@ -122,8 +122,8 @@
     'int_and_ovf':              jvmgen.IAND,
     'int_or_ovf':               jvmgen.IOR,
 
-    'int_lshift_ovf':           _check_ovf(jvmgen.ISHL),
-    'int_lshift_ovf_val':       _check_ovf(jvmgen.ISHL), # VAL??
+    'int_lshift_ovf':           jvmgen.ISHLOVF,
+    'int_lshift_ovf_val':       jvmgen.ISHLOVF, # VAL... what is val used for??
 
     'int_rshift_ovf':           jvmgen.ISHR, # these can't overflow!
     'int_xor_ovf':              jvmgen.IXOR,
@@ -201,6 +201,7 @@
     'llong_xor':                jvmgen.LXOR,
     'llong_floordiv_ovf':       jvmgen.LDIV, # these can't overflow!
     'llong_mod_ovf':            jvmgen.LREMOVF,
+    'llong_lshift_ovf':         jvmgen.LSHLOVF,
 
     'ullong_is_true':           [PushAllArgs,
                                  jvmgen.LCONST_0,

Modified: pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
==============================================================================
--- pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java	(original)
+++ pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java	Fri Jul 27 20:48:04 2007
@@ -469,6 +469,27 @@
         return x%y;
     }
 
+    public static int lshift_ovf(int x, int y) // x << y
+    {
+        int result = x << y;
+        if (x != (result >> y))
+        {
+            throwOverflowError();
+        }
+        return result;
+    }
+
+    public static long lshift_ovf(long x, long y) // x << y
+    {
+        long result = x << y;
+        if (x != (result >> y))
+        {
+            throwOverflowError();
+        }
+        return result;
+    }
+    
+
     // ----------------------------------------------------------------------
     // String
 

Modified: pypy/dist/pypy/translator/jvm/test/test_overflow.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/test/test_overflow.py	(original)
+++ pypy/dist/pypy/translator/jvm/test/test_overflow.py	Fri Jul 27 20:48:04 2007
@@ -3,9 +3,5 @@
 from pypy.translator.oosupport.test_template.overflow import BaseTestOverflow
 
 class TestOverflow(BaseTestOverflow, JvmTest):
-
-    def test_lshift(self):
-        py.test.skip('Shift is currently not implemented in src/PyPy.java because the C version interacts with Pypy directly, and it\'s not clear how to do that in Java')
-
-
+    pass
 



More information about the Pypy-commit mailing list