[pypy-svn] r36474 - in pypy/dist/pypy/translator: jvm jvm/src jvm/test oosupport
niko at codespeak.net
niko at codespeak.net
Thu Jan 11 13:45:47 CET 2007
Author: niko
Date: Thu Jan 11 13:45:45 2007
New Revision: 36474
Modified:
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
pypy/dist/pypy/translator/jvm/test/runtest.py
pypy/dist/pypy/translator/jvm/typesystem.py
pypy/dist/pypy/translator/oosupport/constant.py
pypy/dist/pypy/translator/oosupport/metavm.py
Log:
(antocuni, niko)
1. fix boxing in constant preparation
2. char dump and quoting
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 13:45:45 2007
@@ -248,7 +248,7 @@
ootype.Float:jvmgen.DOUBLETOSTRINGD,
ootype.Bool:jvmgen.PYPYDUMPBOOLEAN,
ootype.Void:jvmgen.PYPYDUMPVOID,
- ootype.Char:jvmgen.CHARTOSTRINGC,
+ ootype.Char:jvmgen.PYPYESCAPEDCHAR,
ootype.String:jvmgen.PYPYESCAPEDSTRING,
}
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 13:45:45 2007
@@ -7,7 +7,7 @@
JvmType, jString, jInt, jLong, jDouble, jBool, jString, \
jPyPy, jVoid, jMath, desc_for_method, jPrintStream, jClass, jChar, \
jObject, jByteArray, jPyPyExcWrap, jIntegerClass, jLongClass, \
- jDoubleClass, jCharClass, jStringBuilder
+ jDoubleClass, jCharClass, jStringBuilder, JvmScalarType
# ___________________________________________________________________________
# Miscellaneous helper functions
@@ -359,6 +359,7 @@
PYPYDUMPBOOLEAN = Method.s(jPyPy, 'dump_boolean', (jBool,), jString)
PYPYDUMPUINT = Method.s(jPyPy, 'dump_uint', (jInt,), jString)
PYPYDUMPVOID = Method.s(jPyPy, 'dump_void', (), jString)
+PYPYESCAPEDCHAR = Method.s(jPyPy, 'escaped_char', (jChar,), jString)
PYPYESCAPEDSTRING = Method.s(jPyPy, 'escaped_string', (jString,), jString)
PYPYDUMPEXCWRAPPER = Method.s(jPyPy, 'dump_exc_wrapper', (jObject,), jVoid)
PYPYRUNTIMENEW = Method.s(jPyPy, 'RuntimeNew', (jClass,), jObject)
@@ -658,6 +659,11 @@
jtype, jidx = self.curfunc.function_arguments[index]
self.load_jvm_var(jtype, jidx)
+ def prepare_generic_argument(self, ITEMTYPE):
+ jty = self.db.lltype_to_cts(ITEMTYPE)
+ if isinstance(jty, JvmScalarType):
+ self.box_value(jty)
+
def box_value(self, jscalartype):
""" Assuming that an value of type jscalartype is on the stack,
boxes it into an Object. """
@@ -715,6 +721,7 @@
# wrapped Python object
self.mark(catch)
EXCWRAPOBJ.load(self)
+ self.emit(CHECKCAST, excclsty)
def end_catch(self):
"""
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 13:45:45 2007
@@ -223,12 +223,12 @@
else:
# the exception value is on the stack, store it in the proper place
if isinstance(link.last_exception, flowmodel.Variable):
- self.ilasm.dup(jObject)
+ self.ilasm.emit(jvmgen.DUP)
self.ilasm.store(link.last_exc_value)
fld = jvmgen.Field(
- self.db.lltype_to_cts(rclass.CLASSTYPE).name,
+ self.db.lltype_to_cts(rclass.OBJECT).name,
'meta',
- self.db.lltype_to_cts(rclass.OBJECT),
+ self.db.lltype_to_cts(rclass.CLASSTYPE),
False,
rclass.OBJECT)
self.ilasm.emit(fld)
@@ -476,7 +476,9 @@
genprint = self._print
# Start the dump
- genprint("InstanceWrapper([")
+ genprint("InstanceWrapper(")
+ genprint("'" + self.OOCLASS._name + "', ")
+ genprint("[")
for fieldnm, (FIELDOOTY, fielddef) in self.OOCLASS._fields.iteritems():
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 13:45:45 2007
@@ -221,6 +221,14 @@
sb.append(c);
}
+ public static String escaped_char(char c) {
+ StringBuffer sb = new StringBuffer();
+ sb.append('"');
+ _append_char(sb, c);
+ sb.append('"');
+ return sb.toString();
+ }
+
public static String escaped_string(String b) {
StringBuffer sb = new StringBuffer();
sb.append('"');
Modified: pypy/dist/pypy/translator/jvm/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/test/runtest.py (original)
+++ pypy/dist/pypy/translator/jvm/test/runtest.py Thu Jan 11 13:45:45 2007
@@ -48,12 +48,13 @@
return 'ExceptionWrapper(%s)' % repr(self.class_name)
class InstanceWrapper:
- def __init__(self, fields):
+ def __init__(self, class_name, fields):
+ self.class_name = class_name
# fields is a list of (name, value) tuples
self.fields = fields
def __repr__(self):
- return 'InstanceWrapper(%s)' % repr(self.fields)
+ return 'InstanceWrapper(%s, %r)' % (self.class_name, self.fields)
# CLI could-be duplicate
class JvmGeneratedSourceWrapper(object):
Modified: pypy/dist/pypy/translator/jvm/typesystem.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/typesystem.py (original)
+++ pypy/dist/pypy/translator/jvm/typesystem.py Thu Jan 11 13:45:45 2007
@@ -146,7 +146,9 @@
jIntegerClass = JvmClassType('java.lang.Integer')
jLongClass = JvmClassType('java.lang.Long')
jDoubleClass = JvmClassType('java.lang.Double')
-jCharClass = JvmClassType('java.lang.Char')
+jByteClass = JvmClassType('java.lang.Byte')
+jCharClass = JvmClassType('java.lang.Character')
+jBoolClass = JvmClassType('java.lang.Boolean')
jThrowable = JvmClassType('java.lang.Throwable')
jObject = JvmClassType('java.lang.Object')
jString = JvmClassType('java.lang.String')
@@ -179,10 +181,10 @@
jVoid = JvmScalarType('V', None, None)
jInt = JvmScalarType('I', jIntegerClass, 'intValue')
jLong = JvmScalarType('J', jLongClass, 'longValue')
-jBool = JvmScalarType('Z', jIntegerClass, 'intValue')
+jBool = JvmScalarType('Z', jBoolClass, 'booleanValue')
jDouble = JvmScalarType('D', jDoubleClass, 'doubleValue')
-jByte = JvmScalarType('B', jIntegerClass, 'intValue')
-jChar = JvmScalarType('C', jIntegerClass, 'intValue')
+jByte = JvmScalarType('B', jByteClass, 'byteValue')
+jChar = JvmScalarType('C', jCharClass, 'charValue')
class JvmArrayType(JvmType):
"""
Modified: pypy/dist/pypy/translator/oosupport/constant.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/constant.py (original)
+++ pypy/dist/pypy/translator/oosupport/constant.py Thu Jan 11 13:45:45 2007
@@ -590,6 +590,7 @@
gen.dup(SELFTYPE)
push_constant(self.db, ootype.Signed, idx, gen)
push_constant(self.db, ITEMTYPE, item, gen)
+ gen.prepare_generic_argument(ITEMTYPE)
gen.call_method(SELFTYPE, 'll_setitem_fast')
# ______________________________________________________________________
Modified: pypy/dist/pypy/translator/oosupport/metavm.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/metavm.py (original)
+++ pypy/dist/pypy/translator/oosupport/metavm.py Thu Jan 11 13:45:45 2007
@@ -156,6 +156,14 @@
Stack: argN...arg2, arg1, arg0, ... -> ret, ... """
raise NotImplementedError
+ def prepare_generic_argument(self, ITEMTYPE):
+ """
+ Invoked after a generic argument has been pushed onto the stack.
+ May not need to do anything, but some backends, *cough*Java*cough*,
+ require boxing etc.
+ """
+ return # by default do nothing
+
def call_method(self, OOCLASS, method_name):
""" Invokes the given method on the object on the stack. The
this ptr and all arguments have already been pushed.
More information about the Pypy-commit
mailing list