[pypy-svn] r36488 - in pypy/dist/pypy/translator/jvm: . src
niko at codespeak.net
niko at codespeak.net
Thu Jan 11 15:42:19 CET 2007
Author: niko
Date: Thu Jan 11 15:42:18 2007
New Revision: 36488
Modified:
pypy/dist/pypy/translator/jvm/builtin.py
pypy/dist/pypy/translator/jvm/database.py
pypy/dist/pypy/translator/jvm/generator.py
pypy/dist/pypy/translator/jvm/node.py
pypy/dist/pypy/translator/jvm/src/PyPy.java
Log:
(antocuni,niko) fix remaining errors in test_pbc (we hope)
Modified: pypy/dist/pypy/translator/jvm/builtin.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/builtin.py (original)
+++ pypy/dist/pypy/translator/jvm/builtin.py Thu Jan 11 15:42:18 2007
@@ -33,6 +33,12 @@
if hasattr(self.OOTYPE, param):
self.generics[getattr(self.OOTYPE, param)] = ootype.ROOT
+ def __eq__(self, other):
+ return isinstance(other, JvmBuiltInType) and other.name == self.name
+
+ def __hash__(self):
+ return hash(self.name)
+
def lookup_field(self, fieldnm):
""" Given a field name, returns a jvmgen.Field object """
_, FIELDTY = self.OOTYPE._lookup_field(fieldnm)
@@ -86,6 +92,9 @@
(ootype.String.__class__, "ll_streq"):
jvmgen.Method.v(jString, "equals", (jObject,), jBool),
+ (ootype.String.__class__, "ll_strlen"):
+ jvmgen.Method.v(jString, "length", (), jInt),
+
(ootype.List, "ll_length"):
jvmgen.Method.v(jArrayList, "size", (), jInt),
Modified: pypy/dist/pypy/translator/jvm/database.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/database.py (original)
+++ pypy/dist/pypy/translator/jvm/database.py Thu Jan 11 15:42:18 2007
@@ -243,11 +243,11 @@
_toString_methods = {
ootype.Signed:jvmgen.INTTOSTRINGI,
- ootype.Unsigned:jvmgen.PYPYDUMPUINT,
+ ootype.Unsigned:jvmgen.PYPYSERIALIZEUINT,
ootype.SignedLongLong:jvmgen.LONGTOSTRINGL,
ootype.Float:jvmgen.DOUBLETOSTRINGD,
- ootype.Bool:jvmgen.PYPYDUMPBOOLEAN,
- ootype.Void:jvmgen.PYPYDUMPVOID,
+ ootype.Bool:jvmgen.PYPYSERIALIZEBOOLEAN,
+ ootype.Void:jvmgen.PYPYSERIALIZEVOID,
ootype.Char:jvmgen.PYPYESCAPEDCHAR,
ootype.String:jvmgen.PYPYESCAPEDSTRING,
}
@@ -266,7 +266,7 @@
to print the value of 'var'.
"""
- return self._toString_methods.get(OOTYPE, jvmgen.OBJTOSTRING)
+ return self._toString_methods.get(OOTYPE, jvmgen.PYPYSERIALIZEOBJECT)
# _________________________________________________________________
# Type translation functions
Modified: pypy/dist/pypy/translator/jvm/generator.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/generator.py (original)
+++ pypy/dist/pypy/translator/jvm/generator.py Thu Jan 11 15:42:18 2007
@@ -358,11 +358,12 @@
PYPYSTRTODOUBLE = Method.s(jPyPy, 'str_to_double', (jString,), jDouble)
PYPYSTRTOCHAR = Method.s(jPyPy, 'str_to_char', (jString,), jChar)
PYPYDUMP = Method.s(jPyPy, 'dump', (jString,), jVoid)
-PYPYDUMPBOOLEAN = Method.s(jPyPy, 'dump_boolean', (jBool,), jString)
-PYPYDUMPUINT = Method.s(jPyPy, 'dump_uint', (jInt,), jString)
-PYPYDUMPVOID = Method.s(jPyPy, 'dump_void', (), jString)
+PYPYSERIALIZEBOOLEAN = Method.s(jPyPy, 'serialize_boolean', (jBool,), jString)
+PYPYSERIALIZEUINT = Method.s(jPyPy, 'serialize_uint', (jInt,), jString)
+PYPYSERIALIZEVOID = Method.s(jPyPy, 'serialize_void', (), jString)
PYPYESCAPEDCHAR = Method.s(jPyPy, 'escaped_char', (jChar,), jString)
PYPYESCAPEDSTRING = Method.s(jPyPy, 'escaped_string', (jString,), jString)
+PYPYSERIALIZEOBJECT = Method.s(jPyPy, 'serializeObject', (jObject,), jString)
PYPYDUMPEXCWRAPPER = Method.s(jPyPy, 'dump_exc_wrapper', (jObject,), jVoid)
PYPYRUNTIMENEW = Method.s(jPyPy, 'RuntimeNew', (jClass,), jObject)
PYPYSTRING2BYTES = Method.s(jPyPy, 'string2bytes', (jString,), jByteArray)
@@ -922,15 +923,18 @@
elif TYPE is ootype.Float:
self._push_double_constant(float(value))
elif TYPE is ootype.String:
- self.load_string(str(value._str))
+ if value == ootype.null(ootype.String):
+ self.emit(ACONST_NULL)
+ else:
+ self.load_string(str(value._str))
def _push_long_constant(self, value):
if value == 0:
- gen.emit(LCONST_0)
+ self.emit(LCONST_0)
elif value == 1:
- gen.emit(LCONST_1)
+ self.emit(LCONST_1)
else:
- gen.emit(LDC2, value)
+ self.emit(LDC2, value)
def _push_double_constant(self, value):
if _isnan(value):
@@ -939,11 +943,11 @@
if value > 0: DOUBLEPOSINF.load(self)
else: DOUBLENEGINF.load(self)
elif value == 0.0:
- gen.emit(DCONST_0)
+ self.emit(DCONST_0)
elif value == 1.0:
- gen.emit(DCONST_1)
+ self.emit(DCONST_1)
else:
- gen.emit(LDC2, self.value)
+ self.emit(LDC2, value)
# __________________________________________________________________
# Methods invoked directly by strings in jvm/opcode.py
Modified: pypy/dist/pypy/translator/jvm/node.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/node.py (original)
+++ pypy/dist/pypy/translator/jvm/node.py Thu Jan 11 15:42:18 2007
@@ -115,6 +115,8 @@
done_printing = gen.unique_label('done_printing')
RESOOTYPE = self.graph.getreturnvar().concretetype
dumpmethod = self.db.generate_toString_method_for_ootype(RESOOTYPE)
+ gen.add_comment('Invoking dump method for result of type '
+ +str(RESOOTYPE))
gen.emit(dumpmethod) # generate the string
gen.emit(jvmgen.PYPYDUMP) # dump to stdout
gen.goto(done_printing)
@@ -356,8 +358,7 @@
if not i: continue # skip the this ptr
gen.load_function_argument(i)
gen.emit(self.impl_method)
- if self.super_class.java_return_type is not jVoid:
- gen.return_val(self.super_class.java_return_type)
+ gen.return_val(self.super_class.java_return_type)
gen.end_function()
gen.end_class()
Modified: pypy/dist/pypy/translator/jvm/src/PyPy.java
==============================================================================
--- pypy/dist/pypy/translator/jvm/src/PyPy.java (original)
+++ pypy/dist/pypy/translator/jvm/src/PyPy.java Thu Jan 11 15:42:18 2007
@@ -192,11 +192,11 @@
System.out.println(text);
}
- public static String dump_void() {
+ public static String serialize_void() {
return "None";
}
- public static String dump_uint(int i) {
+ public static String serialize_uint(int i) {
if (i >= 0)
return Integer.toString(i);
else {
@@ -207,7 +207,7 @@
}
}
- public static String dump_boolean(boolean l) {
+ public static String serialize_boolean(boolean l) {
if (l)
return "True";
else
@@ -230,6 +230,8 @@
}
public static String escaped_string(String b) {
+ if (b == null)
+ return "None";
StringBuffer sb = new StringBuffer();
sb.append('"');
for (int i = 0; i < b.length(); i++) {
@@ -252,6 +254,12 @@
dump(sb.toString());
}
+ public static String serializeObject(Object o) {
+ if (o == null)
+ return "None";
+ return o.toString();
+ }
+
// ----------------------------------------------------------------------
// String
More information about the Pypy-commit
mailing list