Commits

Michał Bendowski committed 5ba6249

Implemented float2longlong and longlong2float for the JVM.

Also removed the oo_primitive for pypy__rotateLeft - it's not needed
on 32 bit architecture (and JVM backend doesn't support 64 bit
anyway).

Comments (0)

Files changed (6)

pypy/rlib/rmd5.py

     _rotateLeft = rffi.llexternal(
         "pypy__rotateLeft", [lltype.Unsigned, lltype.Signed], lltype.Unsigned,
         _callable=_rotateLeft_emulator, compilation_info=eci,
-        _nowrapper=True, elidable_function=True, oo_primitive='pypy__rotateLeft') # TODO implement the oo_primitive
+        _nowrapper=True, elidable_function=True)
     # we expect the function _rotateLeft to be actually inlined
 
 

pypy/translator/jvm/database.py

         ootype.Unsigned:jvm.PYPYSERIALIZEUINT,
         ootype.SignedLongLong:jvm.LONGTOSTRINGL,
         ootype.UnsignedLongLong: jvm.PYPYSERIALIZEULONG,
-        ootype.Float:jvm.DOUBLETOSTRINGD,
+        ootype.Float:jvm.PYPYSERIALIZEDOUBLE,
         ootype.Bool:jvm.PYPYSERIALIZEBOOLEAN,
         ootype.Void:jvm.PYPYSERIALIZEVOID,
         ootype.Char:jvm.PYPYESCAPEDCHAR,

pypy/translator/jvm/src/pypy/PyPy.java

 import java.util.Map;
 import java.text.DecimalFormat;
 import java.lang.reflect.Array;
+import java.nio.ByteBuffer;
 
 /**
  * Class with a number of utility routines.  One instance of this is
         }
     }
 
+    public double pypy__longlong2float(long l) {
+        ByteBuffer buf = ByteBuffer.allocate(8);
+        buf.putLong(l);
+        buf.flip();
+        return buf.getDouble();
+    }
+
+    public long pypy__float2longlong(double d) {
+        ByteBuffer buf = ByteBuffer.allocate(8);
+        buf.putDouble(d);
+        buf.flip();
+        return buf.getLong();
+    }
+
     public double ooparse_float(String s) {
         try {
             return Double.parseDouble(s);
             return "False";
     }
 
+    public static String serialize_double(double d) {
+        if (Double.isNaN(d)) {
+            return "float(\"nan\")";
+        } else if (Double.isInfinite(d)) {
+            if (d > 0)
+                return "float(\"inf\")";
+            else
+                return "float(\"-inf\")";
+        } else {
+            return Double.toString(d);
+        }
+    }
+
     private static String format_char(char c) {
         String res = "\\x";
         if (c <= 0x0F) res = res + "0";

pypy/translator/jvm/test/runtest.py

 
 # CLI could-be duplicate
 class JvmGeneratedSourceWrapper(object):
+
     def __init__(self, gensrc):
         """ gensrc is an instance of JvmGeneratedSource """
         self.gensrc = gensrc

pypy/translator/jvm/test/test_longlong2float.py

+from pypy.translator.jvm.test.runtest import JvmTest
+from pypy.rlib.longlong2float import *
+from pypy.rlib.test.test_longlong2float import enum_floats
+from pypy.rlib.test.test_longlong2float import fn as float2longlong2float
+import py
+
+class TestLongLong2Float(JvmTest):
+
+    def test_float2longlong_and_longlong2float(self):
+        def func(f):
+            return float2longlong2float(f)
+
+        for f in enum_floats():
+            assert repr(f) == repr(self.interpret(func, [f]))
+
+    def test_uint2singlefloat(self):
+        py.test.skip("uint2singlefloat is not implemented in ootype")
+
+    def test_singlefloat2uint(self):
+        py.test.skip("singlefloat2uint is not implemented in ootype")

pypy/translator/jvm/typesystem.py

 PYPYSERIALIZEUINT  =    Method.s(jPyPy, 'serialize_uint', (jInt,), jString)
 PYPYSERIALIZEULONG =    Method.s(jPyPy, 'serialize_ulonglong', (jLong,),jString)
 PYPYSERIALIZEVOID =     Method.s(jPyPy, 'serialize_void', (), jString)
+PYPYSERIALIZEDOUBLE =   Method.s(jPyPy, 'serialize_double', (jDouble,), jString)
 PYPYESCAPEDCHAR =       Method.s(jPyPy, 'escaped_char', (jChar,), jString)
 PYPYESCAPEDUNICHAR =    Method.s(jPyPy, 'escaped_unichar', (jChar,), jString)
 PYPYESCAPEDSTRING =     Method.s(jPyPy, 'escaped_string', (jString,), jString)