Author: Michal Bendowski <mic...@bendowski.pl> Branch: jvm-improvements Changeset: r51380:5ba62496112e Date: 2012-01-16 00:56 +0100 http://bitbucket.org/pypy/pypy/changeset/5ba62496112e/
Log: 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). diff --git a/pypy/rlib/rmd5.py b/pypy/rlib/rmd5.py --- a/pypy/rlib/rmd5.py +++ b/pypy/rlib/rmd5.py @@ -51,7 +51,7 @@ _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 diff --git a/pypy/translator/jvm/database.py b/pypy/translator/jvm/database.py --- a/pypy/translator/jvm/database.py +++ b/pypy/translator/jvm/database.py @@ -358,7 +358,7 @@ 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, diff --git a/pypy/translator/jvm/src/pypy/PyPy.java b/pypy/translator/jvm/src/pypy/PyPy.java --- a/pypy/translator/jvm/src/pypy/PyPy.java +++ b/pypy/translator/jvm/src/pypy/PyPy.java @@ -8,6 +8,7 @@ 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 @@ -283,6 +284,20 @@ } } + 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); @@ -353,6 +368,19 @@ 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"; diff --git a/pypy/translator/jvm/test/runtest.py b/pypy/translator/jvm/test/runtest.py --- a/pypy/translator/jvm/test/runtest.py +++ b/pypy/translator/jvm/test/runtest.py @@ -56,6 +56,7 @@ # CLI could-be duplicate class JvmGeneratedSourceWrapper(object): + def __init__(self, gensrc): """ gensrc is an instance of JvmGeneratedSource """ self.gensrc = gensrc diff --git a/pypy/translator/jvm/test/test_longlong2float.py b/pypy/translator/jvm/test/test_longlong2float.py new file mode 100644 --- /dev/null +++ b/pypy/translator/jvm/test/test_longlong2float.py @@ -0,0 +1,20 @@ +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") diff --git a/pypy/translator/jvm/typesystem.py b/pypy/translator/jvm/typesystem.py --- a/pypy/translator/jvm/typesystem.py +++ b/pypy/translator/jvm/typesystem.py @@ -955,6 +955,7 @@ 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) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit