[pypy-commit] pypy jvm-improvements: Add files generated by PyCharm to .hgignore

2012-01-17 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r51374:1afe14470fa3
Date: 2012-01-14 20:18 +0100
http://bitbucket.org/pypy/pypy/changeset/1afe14470fa3/

Log:Add files generated by PyCharm to .hgignore

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -2,6 +2,9 @@
 *.py[co]
 *~
 .*.swp
+.idea
+.project
+.pydevproject
 
 syntax: regexp
 ^testresult$
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Fix compute_unique_id to support built-ins in ootype.

2012-01-17 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r51376:143a2edf9601
Date: 2012-01-11 22:29 +0100
http://bitbucket.org/pypy/pypy/changeset/143a2edf9601/

Log:Fix compute_unique_id to support built-ins in ootype.

Otherwise the translation fails because it doesn't know how to apply
compute_unique_id to a String. In the jvm backend this is
implemented by System.identityHashCode() which can be applied to our
representations of built-ins equally well as for instances.

diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -420,7 +420,7 @@
   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"
diff --git a/pypy/rpython/ootypesystem/ootype.py 
b/pypy/rpython/ootypesystem/ootype.py
--- a/pypy/rpython/ootypesystem/ootype.py
+++ b/pypy/rpython/ootypesystem/ootype.py
@@ -1377,6 +1377,9 @@
 def _cast_to_object(self):
 return make_object(self)
 
+def _identityhash(self):
+return hash(self)
+
 class _string(_builtin_type):
 
 def __init__(self, STRING, value = ''):
diff --git a/pypy/rpython/test/test_rbuiltin.py 
b/pypy/rpython/test/test_rbuiltin.py
--- a/pypy/rpython/test/test_rbuiltin.py
+++ b/pypy/rpython/test/test_rbuiltin.py
@@ -463,6 +463,20 @@
 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_cast_primitive(self):
 from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
 def llf(u):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Fix userspace builders in ootype

2012-01-17 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r51375:90cb8d420991
Date: 2012-01-11 22:26 +0100
http://bitbucket.org/pypy/pypy/changeset/90cb8d420991/

Log:Fix userspace builders in ootype

Implement the getlength() method of StringBuilders in ootype.

diff --git a/pypy/rpython/ootypesystem/ootype.py 
b/pypy/rpython/ootypesystem/ootype.py
--- a/pypy/rpython/ootypesystem/ootype.py
+++ b/pypy/rpython/ootypesystem/ootype.py
@@ -512,6 +512,7 @@
 "ll_append_char": Meth([CHARTP], Void),
 "ll_append": Meth([STRINGTP], Void),
 "ll_build": Meth([], STRINGTP),
+"ll_getlength": Meth([], Signed),
 })
 self._setup_methods({})
 
@@ -1543,6 +1544,9 @@
 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
diff --git a/pypy/rpython/ootypesystem/rbuilder.py 
b/pypy/rpython/ootypesystem/rbuilder.py
--- a/pypy/rpython/ootypesystem/rbuilder.py
+++ b/pypy/rpython/ootypesystem/rbuilder.py
@@ -21,6 +21,10 @@
 builder.ll_append_char(char)
 
 @staticmethod
+def ll_getlength(builder):
+return builder.ll_getlength()
+
+@staticmethod
 def ll_append(builder, string):
 builder.ll_append(string)
 
diff --git a/pypy/rpython/test/test_rbuilder.py 
b/pypy/rpython/test/test_rbuilder.py
--- a/pypy/rpython/test/test_rbuilder.py
+++ b/pypy/rpython/test/test_rbuilder.py
@@ -124,9 +124,5 @@
 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")
diff --git a/pypy/translator/jvm/builtin.py b/pypy/translator/jvm/builtin.py
--- a/pypy/translator/jvm/builtin.py
+++ b/pypy/translator/jvm/builtin.py
@@ -84,6 +84,9 @@
 (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),
 
diff --git a/pypy/translator/jvm/test/test_builder.py 
b/pypy/translator/jvm/test/test_builder.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/jvm/test/test_builder.py
@@ -0,0 +1,7 @@
+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")
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Add a missing cast from Unsigned to UnsignedLongLong in the JVM

2012-01-17 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r51378:c59ec9806ac6
Date: 2012-01-14 20:15 +0100
http://bitbucket.org/pypy/pypy/changeset/c59ec9806ac6/

Log:Add a missing cast from Unsigned to UnsignedLongLong in the JVM
backend.

diff --git a/pypy/translator/jvm/metavm.py b/pypy/translator/jvm/metavm.py
--- a/pypy/translator/jvm/metavm.py
+++ b/pypy/translator/jvm/metavm.py
@@ -92,6 +92,7 @@
 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,
diff --git a/pypy/translator/oosupport/test_template/cast.py 
b/pypy/translator/oosupport/test_template/cast.py
--- a/pypy/translator/oosupport/test_template/cast.py
+++ b/pypy/translator/oosupport/test_template/cast.py
@@ -13,6 +13,9 @@
 def to_longlong(x):
 return r_longlong(x)
 
+def to_ulonglong(x):
+return r_ulonglong(x)
+
 def uint_to_int(x):
 return intmask(x)
 
@@ -56,6 +59,9 @@
 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)])
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Declare oo_primitives that should implement some rffi operations.

2012-01-17 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r51377:6b650a500d68
Date: 2012-01-14 19:04 +0100
http://bitbucket.org/pypy/pypy/changeset/6b650a500d68/

Log:Declare oo_primitives that should implement some rffi operations.

For now the actual implementations are missing, but once we get the
JVM backend to work in some way, this will have to be revisited.

diff --git a/pypy/rlib/longlong2float.py b/pypy/rlib/longlong2float.py
--- a/pypy/rlib/longlong2float.py
+++ b/pypy/rlib/longlong2float.py
@@ -79,19 +79,23 @@
 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")
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)
+_nowrapper=True, elidable_function=True, 
oo_primitive='pypy__rotateLeft') # TODO implement the oo_primitive
 # we expect the function _rotateLeft to be actually inlined
 
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Implemented float2longlong and longlong2float for the JVM.

2012-01-17 Thread benol
Author: Michal Bendowski 
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', (jStri

[pypy-commit] pypy jvm-improvements: Handle the 'jit_is_virtual' opcode by always returning False

2012-01-17 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r51379:e31e85a8d333
Date: 2012-01-14 19:01 +0100
http://bitbucket.org/pypy/pypy/changeset/e31e85a8d333/

Log:Handle the 'jit_is_virtual' opcode by always returning False

diff --git a/pypy/translator/jvm/opcodes.py b/pypy/translator/jvm/opcodes.py
--- a/pypy/translator/jvm/opcodes.py
+++ b/pypy/translator/jvm/opcodes.py
@@ -101,6 +101,7 @@
 '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,
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Simpler implementations of float2longlong and longlong2float.

2012-01-17 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r51381:79b2113c
Date: 2012-01-16 21:19 +0100
http://bitbucket.org/pypy/pypy/changeset/79b2113c/

Log:Simpler implementations of float2longlong and longlong2float.

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,7 +8,6 @@
 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
@@ -285,17 +284,11 @@
 }
 
 public double pypy__longlong2float(long l) {
-ByteBuffer buf = ByteBuffer.allocate(8);
-buf.putLong(l);
-buf.flip();
-return buf.getDouble();
+return Double.longBitsToDouble(l);
 }
 
 public long pypy__float2longlong(double d) {
-ByteBuffer buf = ByteBuffer.allocate(8);
-buf.putDouble(d);
-buf.flip();
-return buf.getLong();
+return Double.doubleToRawLongBits(d);
 }
 
 public double ooparse_float(String s) {
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Fix the implementation of compute_unique_id for _builtin_type.

2012-01-17 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r51382:259f2ab80ae4
Date: 2012-01-16 22:26 +0100
http://bitbucket.org/pypy/pypy/changeset/259f2ab80ae4/

Log:Fix the implementation of compute_unique_id for _builtin_type.

diff --git a/pypy/rpython/ootypesystem/ootype.py 
b/pypy/rpython/ootypesystem/ootype.py
--- a/pypy/rpython/ootypesystem/ootype.py
+++ b/pypy/rpython/ootypesystem/ootype.py
@@ -1378,7 +1378,7 @@
 return make_object(self)
 
 def _identityhash(self):
-return hash(self)
+return object.__hash__(self)
 
 class _string(_builtin_type):
 
diff --git a/pypy/rpython/test/test_rbuiltin.py 
b/pypy/rpython/test/test_rbuiltin.py
--- a/pypy/rpython/test/test_rbuiltin.py
+++ b/pypy/rpython/test/test_rbuiltin.py
@@ -477,6 +477,17 @@
 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):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Fix getattr on JvmInstanceWrapper

2012-06-06 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r55449:f98227092ae0
Date: 2012-06-05 23:02 +0200
http://bitbucket.org/pypy/pypy/changeset/f98227092ae0/

Log:Fix getattr on JvmInstanceWrapper

diff --git a/pypy/rlib/rjvm/api.py b/pypy/rlib/rjvm/api.py
--- a/pypy/rlib/rjvm/api.py
+++ b/pypy/rlib/rjvm/api.py
@@ -90,7 +90,7 @@
 const_cache[new_name] = 
JvmClassWrapper(getattr(self.__wrapped__, attr))
 return const_cache[new_name]
 else:
-raise TypeError("There is no class called %s in package %s" % 
(attr, self.__javaname__))
+raise AttributeError("There is no class called %s in package 
%s" % (attr, self.__javaname__))
 elif isinstance(getattr(self.__wrapped__, attr), jpype.JPackage):
 if new_name not in const_cache:
 const_cache[new_name] = JvmPackageWrapper(new_name)
@@ -184,7 +184,7 @@
 elif attr in self._static_field_names:
 return self._wrap_item(getattr(self.__wrapped__, attr))
 else:
-raise TypeError(
+raise AttributeError(
 "There's no static member called {member_name} in class 
{class_name}.".format(
 member_name=attr, class_name=self.__name__))
 
@@ -211,14 +211,12 @@
 self.__field_names = {str(f.getName()) for f in 
helpers._get_fields(refclass)}
 
 def __getattr__(self, attr):
-if attr == '__wrapped__':
-return self.__wrapped__
-elif attr in self.__method_names:
+if attr in self.__method_names:
 return JvmMethodWrapper(getattr(self.__wrapped__, attr))
 elif attr in self.__field_names:
 return self._wrap_item(getattr(self.__wrapped__, attr))
 else:
-raise TypeError(
+raise AttributeError(
 "No instance method called {method_name} found in class 
{class_name}".format(
 method_name=attr, class_name=self.__class_name))
 
diff --git a/pypy/rlib/rjvm/test/test_rjvm.py b/pypy/rlib/rjvm/test/test_rjvm.py
--- a/pypy/rlib/rjvm/test/test_rjvm.py
+++ b/pypy/rlib/rjvm/test/test_rjvm.py
@@ -29,11 +29,11 @@
 assert result == 32
 
 def test_invalid_static_member():
-with py.test.raises(TypeError):
+with py.test.raises(AttributeError):
 java.lang.Math.typo(42)
 
 def test_invalid_class_name():
-with py.test.raises(TypeError):
+with py.test.raises(AttributeError):
 java.lang.Typo()
 
 def test_class_instantiate():
@@ -54,7 +54,7 @@
 def test_invalid_method_name():
 al = java.util.ArrayList()
 al.add("test")
-with py.test.raises(TypeError):
+with py.test.raises(AttributeError):
 al.typo(0)
 
 def test_interpreted_reflection():
@@ -200,7 +200,7 @@
 sb = java.lang.StringBuilder()
 sb.foobar()
 
-with py.test.raises(TypeError):
+with py.test.raises(AttributeError):
 self.interpret(fn, [])
 
 def test_method_call_no_overload(self):
diff --git a/pypy/translator/jvm/rjvm_support/utils.py 
b/pypy/translator/jvm/rjvm_support/utils.py
--- a/pypy/translator/jvm/rjvm_support/utils.py
+++ b/pypy/translator/jvm/rjvm_support/utils.py
@@ -41,7 +41,7 @@
 elif self.static and name == 'class_':
 return 
ootypemodel.NativeRJvmInstance(helpers.RjvmJavaLangClassWrapper.java_lang_Class)._example()
 else:
-raise TypeError(
+raise AttributeError(
 "No method or field called %s found in %s." % (name, 
self.refclass.getName()))
 
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Enforce casting string arguments with rjvm.native_string

2012-06-06 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r55451:a5f570e4506b
Date: 2012-06-06 23:53 +0200
http://bitbucket.org/pypy/pypy/changeset/a5f570e4506b/

Log:Enforce casting string arguments with rjvm.native_string

diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -645,9 +645,6 @@
 if witness.contains(s_val):
 return T
 
-if isinstance(s_val, SomeString):
-return ootype.String
-
 if info is None:
 info = ''
 else:
diff --git a/pypy/module/jvm/interp_helpers.py 
b/pypy/module/jvm/interp_helpers.py
--- a/pypy/module/jvm/interp_helpers.py
+++ b/pypy/module/jvm/interp_helpers.py
@@ -2,7 +2,8 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.typedef import TypeDef
 from pypy.rlib import rjvm, rstring
-from pypy.rlib.rjvm import java
+from pypy.rlib.rjvm import java, native_string
+
 
 class W_JvmObject(Wrappable):
 """
@@ -124,8 +125,9 @@
 return str(b_type.getName())
 
 def class_for_name(space, class_name):
+b_class_name = native_string(class_name)
 try:
-return java.lang.Class.forName(class_name)
+return java.lang.Class.forName(b_class_name)
 except rjvm.ReflectionException:
 raise OperationError(space.w_TypeError,
  space.wrap("Class %s not found!" % class_name))
diff --git a/pypy/module/jvm/interp_level.py b/pypy/module/jvm/interp_level.py
--- a/pypy/module/jvm/interp_level.py
+++ b/pypy/module/jvm/interp_level.py
@@ -3,7 +3,7 @@
 from pypy.module.jvm import interp_helpers as helpers
 from pypy.module.jvm.interp_helpers import W_JvmObject
 from pypy.rlib import rjvm
-from pypy.rlib.rjvm import java
+from pypy.rlib.rjvm import java, native_string
 
 # == Interp-level module API ==
 
@@ -106,7 +106,7 @@
 b_java_class = helpers.class_for_name(space, class_name)
 
 try:
-b_meth = b_java_class.getMethod(method_name, types)
+b_meth = b_java_class.getMethod(native_string(method_name), types)
 except rjvm.ReflectionException:
 raise helpers.raise_type_error(space,
  "No method called %s found in class %s" % 
(method_name, str(b_java_class.getName(
@@ -126,9 +126,10 @@
 """
 b_java_class = helpers.class_for_name(space, class_name)
 args, types = helpers.get_args_types(space, args_w)
+b_method_name = native_string(method_name)
 
 try:
-b_meth = b_java_class.getMethod(method_name, types)
+b_meth = b_java_class.getMethod(b_method_name, types)
 except rjvm.ReflectionException:
 raise helpers.raise_type_error(space,
  "No method called %s found in class %s" % 
(method_name, str(b_java_class.getName(
@@ -308,8 +309,9 @@
 """
 The logic behind get_(static)_field_value.
 """
+b_field_name = native_string(field_name)
 try:
-b_field = b_class.getField(field_name)
+b_field = b_class.getField(b_field_name)
 except rjvm.ReflectionException:
 raise helpers.raise_type_error(space, "No field called %s in class %s" 
% (
 field_name, str(b_class.getName(
@@ -324,8 +326,9 @@
 """
 The logic behind set_(static)_field_value.
 """
+b_field_name = native_string(field_name)
 try:
-b_field = b_class.getField(field_name)
+b_field = b_class.getField(b_field_name)
 except rjvm.ReflectionException:
 msg = "No field called %s in class %s" % (field_name, 
str(b_class.getName()))
 raise helpers.raise_type_error(space, msg)
diff --git a/pypy/rlib/rjvm/api.py b/pypy/rlib/rjvm/api.py
--- a/pypy/rlib/rjvm/api.py
+++ b/pypy/rlib/rjvm/api.py
@@ -146,6 +146,8 @@
 return self._unwrap_item(item._array)
 elif isinstance(item, jvm_str):
 return str(item)
+elif isinstance(item, str):
+raise TypeError("You have to wrap strings using 
rjvm.native_string!")
 return item
 
 def __call__(self, *args):
diff --git a/pypy/rlib/rjvm/test/test_rjvm.py b/pypy/rlib/rjvm/test/test_rjvm.py
--- a/pypy/rlib/rjvm/test/test_rjvm.py
+++ b/pypy/rlib/rjvm/test/test_rjvm.py
@@ -2,7 +2,7 @@
 import pypy.annotation.model as annmodel
 import pypy.rlib.rjvm as rjvm
 from pypy.rlib import rstring, rarithmetic
-from pypy.rlib.rjvm import java
+from pypy.rlib.rjvm import java, native_string
 from pypy.rpython.test.tool import BaseRtypingTest, OORtypeMixin
 from pypy.annotation.annrpython import RPythonAnnotator
 import pypy.translator.jvm.rjvm_support as rjvm_support
@@ -40,7 +40,7 @@
 al = java.util.ArrayList()
 assert isinstance(al, rjvm.JvmInstanceWrapper)
 assert isinstance(al.add, rjvm.JvmMethodWrapper)
-al.add("test")
+al.add(native_string("test"))
 assert str(al.get(0)) == "test"
 
 def test_class_repr():
@@ -53,12 +53,12 @@
 
 def test_invalid_method_name():
 al = j

[pypy-commit] pypy jvm-improvements: Remove unncessary __eq__ from OOInstanceRepr

2012-06-06 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r55450:52ae99714cf8
Date: 2012-06-06 23:10 +0200
http://bitbucket.org/pypy/pypy/changeset/52ae99714cf8/

Log:Remove unncessary __eq__ from OOInstanceRepr

diff --git a/pypy/rpython/ootypesystem/rootype.py 
b/pypy/rpython/ootypesystem/rootype.py
--- a/pypy/rpython/ootypesystem/rootype.py
+++ b/pypy/rpython/ootypesystem/rootype.py
@@ -58,12 +58,6 @@
 def __init__(self, ootype):
 self.lowleveltype = ootype
 
-def __eq__(self, other):
-return self.lowleveltype == other.lowleveltype
-
-def __ne__(self, other):
-return not self.__eq__(other)
-
 def rtype_getattr(self, hop):
 attr = hop.args_s[1].const
 s_inst = hop.args_s[0]
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Native Java version of thread_get_ident -- just enough to compile ll_thread.

2012-07-31 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r56515:053913e841c7
Date: 2012-07-31 17:50 +0200
http://bitbucket.org/pypy/pypy/changeset/053913e841c7/

Log:Native Java version of thread_get_ident -- just enough to compile
ll_thread.

diff --git a/pypy/module/thread/ll_thread.py b/pypy/module/thread/ll_thread.py
--- a/pypy/module/thread/ll_thread.py
+++ b/pypy/module/thread/ll_thread.py
@@ -46,7 +46,8 @@
   # importantly, reacquire it
   # around the callback
 c_thread_get_ident = llexternal('RPyThreadGetIdent', [], rffi.LONG,
-_nowrapper=True)# always call directly
+_nowrapper=True,# always call directly
+oo_primitive="pypy__thread_get_ident")
 
 TLOCKP = rffi.COpaquePtr('struct RPyOpaque_ThreadLock',
   compilation_info=eci)
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
@@ -287,6 +287,10 @@
 return Double.longBitsToDouble(l);
 }
 
+public long pypy__thread_get_ident() {
+return Thread.currentThread().getId();
+}
+
 public long pypy__float2longlong(double d) {
 return Double.doubleToRawLongBits(d);
 }
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Detect missing oo_primitive during RTyping.

2012-08-01 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r56528:41d2ef9fed11
Date: 2012-08-01 17:23 +0200
http://bitbucket.org/pypy/pypy/changeset/41d2ef9fed11/

Log:Detect missing oo_primitive during RTyping.

diff --git a/pypy/rpython/rpbc.py b/pypy/rpython/rpbc.py
--- a/pypy/rpython/rpbc.py
+++ b/pypy/rpython/rpbc.py
@@ -5,7 +5,7 @@
 from pypy.annotation import description
 from pypy.objspace.flow.model import Constant
 from pypy.rpython.lltypesystem.lltype import \
- typeOf, Void, Bool, nullptr, frozendict, Ptr, Struct, malloc
+ typeOf, Void, Bool, nullptr, frozendict, Ptr, Struct, malloc, FuncType
 from pypy.rpython.error import TyperError
 from pypy.rpython.rmodel import Repr, inputconst, CanBeNull, \
 mangle, inputdesc, warning, impossible_repr
@@ -322,6 +322,14 @@
 args = bk.build_args(opname, hop.args_s[1:])
 s_pbc = hop.args_s[0]   # possibly more precise than self.s_pbc
 descs = list(s_pbc.descriptions)
+
+try:
+s_pbc.const._ptr._obj.external
+# This is an rffi call
+self.rtyper.type_system.check_rffi_call(s_pbc.const)
+except AttributeError:
+pass
+
 vfcs = description.FunctionDesc.variant_for_call_site
 shape, index = vfcs(bk, self.callfamily, descs, args, hop.spaceop)
 row_of_graphs = self.callfamily.calltables[shape][index]
diff --git a/pypy/rpython/typesystem.py b/pypy/rpython/typesystem.py
--- a/pypy/rpython/typesystem.py
+++ b/pypy/rpython/typesystem.py
@@ -101,6 +101,11 @@
 from pypy.rpython.normalizecalls import perform_normalizations
 perform_normalizations(rtyper)
 
+def check_rffi_call(self, func):
+"""Check if the rffi primitive is correct. Raise a TypeError otherwise.
+"""
+pass
+
 class LowLevelTypeSystem(TypeSystem):
 name = "lltypesystem"
 callable_trait = (lltype.FuncType, lltype.functionptr)
@@ -181,6 +186,11 @@
 v_list = hop.inputargs(robj1, robj2)
 return hop.genop('oois', v_list, resulttype=lltype.Bool)
 
+def check_rffi_call(self, func):
+if not hasattr(func._ptr._obj, 'oo_promitive'):
+raise TyperError(
+"Calling {func_name} via rffi, but it has no OO primitive 
assigned.".format(func_name=func.func_name))
+
 # All typesystems are singletons
 LowLevelTypeSystem.instance = LowLevelTypeSystem()
 ObjectOrientedTypeSystem.instance = ObjectOrientedTypeSystem()
diff --git a/pypy/translator/oosupport/test_template/builtin.py 
b/pypy/translator/oosupport/test_template/builtin.py
--- a/pypy/translator/oosupport/test_template/builtin.py
+++ b/pypy/translator/oosupport/test_template/builtin.py
@@ -2,6 +2,7 @@
 import errno
 import stat
 from py.builtin import sorted
+from py.test import raises
 from pypy.tool import udir
 from pypy.rpython.test.test_rbuiltin import BaseTestRbuiltin
 from pypy.rpython.module.test.test_ll_time import BaseTestTime as 
llBaseTestTime
@@ -227,6 +228,23 @@
 assert res == ord('a')
 
 
+def test_rffi_missing_primitive(self):
+from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
+eci = ExternalCompilationInfo(
+includes = ['ctype.h']
+)
+
+tolower_no_oo_primitive = rffi.llexternal('tolower', [lltype.Signed], 
lltype.Signed,
+  compilation_info=eci)
+
+def fn(n):
+return tolower_no_oo_primitive(n)
+
+with raises(TypeError):
+self.interpret(fn, ord('A'))
+
+
 def test_rlocale(self):
 from pypy.rlib.rlocale import isupper, islower, isalpha, isalnum, 
tolower
 def fn():
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jvm-improvements: Fix a typo from the last commit.

2012-08-01 Thread benol
Author: Michal Bendowski 
Branch: jvm-improvements
Changeset: r56529:66ec0e8549af
Date: 2012-08-01 21:22 +0200
http://bitbucket.org/pypy/pypy/changeset/66ec0e8549af/

Log:Fix a typo from the last commit.

diff --git a/pypy/rpython/typesystem.py b/pypy/rpython/typesystem.py
--- a/pypy/rpython/typesystem.py
+++ b/pypy/rpython/typesystem.py
@@ -187,7 +187,7 @@
 return hop.genop('oois', v_list, resulttype=lltype.Bool)
 
 def check_rffi_call(self, func):
-if not hasattr(func._ptr._obj, 'oo_promitive'):
+if not hasattr(func._ptr._obj, 'oo_primitive'):
 raise TyperError(
 "Calling {func_name} via rffi, but it has no OO primitive 
assigned.".format(func_name=func.func_name))
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit