Commits

Antonio Cuni committed c1b66eb Merge

(benol) merge the jvm-improvements branch, which fixes (again :-)) the translation for the JVM backend

  • Participants
  • Parent commits 5e43d79, 88e6de5

Comments (0)

Files changed (18)

 *.py[co]
 *~
 .*.swp
+.idea
+.project
+.pydevproject
 
 syntax: regexp
 ^testresult$

File pypy/rlib/longlong2float.py

 longlong2float = rffi.llexternal(
     "pypy__longlong2float", [rffi.LONGLONG], rffi.DOUBLE,
     _callable=longlong2float_emulator, compilation_info=eci,
-    _nowrapper=True, elidable_function=True, sandboxsafe=True)
+    _nowrapper=True, elidable_function=True, sandboxsafe=True,
+    oo_primitive="pypy__longlong2float")
 
 float2longlong = rffi.llexternal(
     "pypy__float2longlong", [rffi.DOUBLE], rffi.LONGLONG,
     _callable=float2longlong_emulator, compilation_info=eci,
-    _nowrapper=True, elidable_function=True, sandboxsafe=True)
+    _nowrapper=True, elidable_function=True, sandboxsafe=True,
+    oo_primitive="pypy__float2longlong")
 
 uint2singlefloat = rffi.llexternal(
     "pypy__uint2singlefloat", [rffi.UINT], rffi.FLOAT,
     _callable=uint2singlefloat_emulator, compilation_info=eci,
-    _nowrapper=True, elidable_function=True, sandboxsafe=True)
+    _nowrapper=True, elidable_function=True, sandboxsafe=True,
+    oo_primitive="pypy__uint2singlefloat")
 
 singlefloat2uint = rffi.llexternal(
     "pypy__singlefloat2uint", [rffi.FLOAT], rffi.UINT,
     _callable=singlefloat2uint_emulator, compilation_info=eci,
-    _nowrapper=True, elidable_function=True, sandboxsafe=True)
+    _nowrapper=True, elidable_function=True, sandboxsafe=True,
+    oo_primitive="pypy__singlefloat2uint")

File pypy/rlib/objectmodel.py

                   vobj.concretetype.TO._gckind == 'gc')
         else:
             from pypy.rpython.ootypesystem import ootype
-            ok = isinstance(vobj.concretetype, ootype.Instance)
+            ok = isinstance(vobj.concretetype, (ootype.Instance, ootype.BuiltinType))
         if not ok:
             from pypy.rpython.error import TyperError
             raise TyperError("compute_unique_id() cannot be applied to"

File pypy/rlib/rmd5.py

File contents unchanged.

File pypy/rpython/ootypesystem/ootype.py

             "ll_append_char": Meth([CHARTP], Void),
             "ll_append": Meth([STRINGTP], Void),
             "ll_build": Meth([], STRINGTP),
+            "ll_getlength": Meth([], Signed),
             })
         self._setup_methods({})
 
     def _cast_to_object(self):
         return make_object(self)
 
+    def _identityhash(self):
+        return object.__hash__(self)
+
 class _string(_builtin_type):
 
     def __init__(self, STRING, value = ''):
         else:
             return make_unicode(u''.join(self._buf))
 
+    def ll_getlength(self):
+        return self.ll_build().ll_strlen()
+
 class _null_string_builder(_null_mixin(_string_builder), _string_builder):
     def __init__(self, STRING_BUILDER):
         self.__dict__["_TYPE"] = STRING_BUILDER

File pypy/rpython/ootypesystem/rbuilder.py

         builder.ll_append_char(char)
 
     @staticmethod
+    def ll_getlength(builder):
+        return builder.ll_getlength()
+
+    @staticmethod
     def ll_append(builder, string):
         builder.ll_append(string)
 

File pypy/rpython/test/test_rbuilder.py

     pass
 
 class TestOOtype(BaseTestStringBuilder, OORtypeMixin):
-    def test_string_getlength(self):
-        py.test.skip("getlength(): not implemented on ootype")
-    def test_unicode_getlength(self):
-        py.test.skip("getlength(): not implemented on ootype")
     def test_append_charpsize(self):
         py.test.skip("append_charpsize(): not implemented on ootype")

File pypy/rpython/test/test_rbuiltin.py

             assert x1 == intmask(x0)
             assert x3 == intmask(x2)
 
+    def test_id_on_builtins(self):
+        from pypy.rlib.objectmodel import compute_unique_id
+        from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
+        def fn():
+            return (compute_unique_id("foo"),
+                    compute_unique_id(u"bar"),
+                    compute_unique_id([1]),
+                    compute_unique_id({"foo": 3}),
+                    compute_unique_id(StringBuilder()),
+                    compute_unique_id(UnicodeBuilder()))
+        res = self.interpret(fn, [])
+        for id in self.ll_unpack_tuple(res, 6):
+            assert isinstance(id, (int, r_longlong))
+
+    def test_uniqueness_of_id_on_strings(self):
+        from pypy.rlib.objectmodel import compute_unique_id
+        def fn(s1, s2):
+            return (compute_unique_id(s1), compute_unique_id(s2))
+
+        s1 = "foo"
+        s2 = ''.join(['f','oo'])
+        res = self.interpret(fn, [self.string_to_ll(s1), self.string_to_ll(s2)])
+        i1, i2 = self.ll_unpack_tuple(res, 2)
+        assert i1 != i2
+
     def test_cast_primitive(self):
         from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
         def llf(u):

File pypy/translator/jvm/builtin.py

     (ootype.StringBuilder.__class__, "ll_build"):
     jvm.Method.v(jStringBuilder, "toString", (), jString),
 
+    (ootype.StringBuilder.__class__, "ll_getlength"):
+    jvm.Method.v(jStringBuilder, "length", (), jInt),
+
     (ootype.String.__class__, "ll_hash"):
     jvm.Method.v(jString, "hashCode", (), jInt),
 

File 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,

File pypy/translator/jvm/metavm.py

 CASTS = {
 #   FROM                      TO
     (ootype.Signed,           ootype.UnsignedLongLong): jvm.I2L,
+    (ootype.Unsigned,         ootype.UnsignedLongLong): jvm.I2L,
     (ootype.SignedLongLong,   ootype.Signed):           jvm.L2I,
     (ootype.UnsignedLongLong, ootype.Unsigned):         jvm.L2I,
     (ootype.UnsignedLongLong, ootype.Signed):           jvm.L2I,

File pypy/translator/jvm/opcodes.py

     'jit_force_virtualizable':  Ignore,
     'jit_force_virtual':        DoNothing,
     'jit_force_quasi_immutable': Ignore,
+    'jit_is_virtual':           PushPrimitive(ootype.Bool, False),
 
     'debug_assert':              [], # TODO: implement?
     'debug_start_traceback':    Ignore,

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

         }
     }
 
+    public double pypy__longlong2float(long l) {
+        return Double.longBitsToDouble(l);
+    }
+
+    public long pypy__float2longlong(double d) {
+        return Double.doubleToRawLongBits(d);
+    }
+
     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";

File 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

File pypy/translator/jvm/test/test_builder.py

+from pypy.translator.jvm.test.runtest import JvmTest
+from pypy.rpython.test.test_rbuilder import BaseTestStringBuilder
+import py
+
+class TestJvmStringBuilder(JvmTest, BaseTestStringBuilder):
+    def test_append_charpsize(self):
+        py.test.skip("append_charpsize(): not implemented on ootype")

File 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")

File 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)

File pypy/translator/oosupport/test_template/cast.py

 def to_longlong(x):
     return r_longlong(x)
 
+def to_ulonglong(x):
+    return r_ulonglong(x)
+
 def uint_to_int(x):
     return intmask(x)
 
     def test_unsignedlonglong_to_unsigned4(self):
         self.check(to_uint, [r_ulonglong(18446744073709551615l)]) # max 64 bit num
 
+    def test_unsigned_to_usignedlonglong(self):
+        self.check(to_ulonglong, [r_uint(42)])
+
     def test_uint_to_int(self):
         self.check(uint_to_int, [r_uint(sys.maxint+1)])