[pypy-svn] r36471 - in pypy/dist/pypy/translator/jvm: . src test
niko at codespeak.net
niko at codespeak.net
Thu Jan 11 13:15:18 CET 2007
Author: niko
Date: Thu Jan 11 13:15:17 2007
New Revision: 36471
Added:
pypy/dist/pypy/translator/jvm/test/test_list.py
pypy/dist/pypy/translator/jvm/test/test_pbc.py
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/metavm.py
pypy/dist/pypy/translator/jvm/node.py
pypy/dist/pypy/translator/jvm/opcodes.py
pypy/dist/pypy/translator/jvm/src/PyPy.java
pypy/dist/pypy/translator/jvm/typesystem.py
Log:
(antocuni, niko)
progress towards test_pbc working: implemented lists, toString(),
generic support, and some other stuff
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 13:15:17 2007
@@ -2,9 +2,7 @@
from pypy.translator.jvm import generator as jvmgen
from pypy.rpython.ootypesystem import ootype
from pypy.translator.jvm.typesystem import \
- jInt, jVoid, jStringBuilder, jString, jPyPy, jChar
-
-jStringBuilder = jvmtype.jStringBuilder
+ jInt, jVoid, jStringBuilder, jString, jPyPy, jChar, jArrayList, jObject
# ______________________________________________________________________
# Mapping of built-in OOTypes to JVM types
@@ -81,6 +79,10 @@
jvmgen.PYPYJAVA, "ll_build", (jStringBuilder,), jOOString)
built_in_methods = {
+
+ # Note: String and StringBuilder are rebound in ootype, and thus
+ # .__class__ is required
+
(ootype.StringBuilder.__class__, "ll_allocate"):
jvmgen.Method.v(jStringBuilder, "ensureCapacity", (jInt,), jVoid),
@@ -91,6 +93,25 @@
jvmgen.Method.s(jPyPy, "ll_append", (jStringBuilder, jString), jVoid),
(ootype.StringBuilder.__class__, "ll_build"):
- _ll_build_method()
-
+ _ll_build_method(),
+
+ (ootype.List, "ll_length"):
+ jvmgen.Method.v(jArrayList, "size", (), jInt),
+
+ (ootype.List, "ll_getitem_fast"):
+ jvmgen.Method.v(jArrayList, "get", (jInt,), jObject),
+
+ (ootype.List, "ll_setitem_fast"):
+ jvmgen.Method.s(jPyPy, "ll_setitem_fast",
+ (jArrayList, jInt, jObject), jVoid),
+
+ (ootype.List, "_ll_resize_ge"):
+ jvmgen.Method.s(jPyPy, "_ll_resize_ge", (jArrayList, jInt), jVoid),
+
+ (ootype.List, "_ll_resize_le"):
+ jvmgen.Method.s(jPyPy, "_ll_resize_le", (jArrayList, jInt), jVoid),
+
+ (ootype.List, "_ll_resize"):
+ jvmgen.Method.s(jPyPy, "_ll_resize", (jArrayList, jInt), jVoid),
+
}
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:15:17 2007
@@ -241,39 +241,32 @@
# Returns a method that prints details about the value out to
# stdout. Should generalize to make it allow for stderr as well.
- _type_printing_methods = {
- ootype.Signed:jvmgen.PYPYDUMPINT,
+ _toString_methods = {
+ ootype.Signed:jvmgen.INTTOSTRINGI,
ootype.Unsigned:jvmgen.PYPYDUMPUINT,
- ootype.SignedLongLong:jvmgen.PYPYDUMPLONG,
- ootype.Float:jvmgen.PYPYDUMPDOUBLE,
+ ootype.SignedLongLong:jvmgen.LONGTOSTRINGL,
+ ootype.Float:jvmgen.DOUBLETOSTRINGD,
ootype.Bool:jvmgen.PYPYDUMPBOOLEAN,
- ootype.Class:jvmgen.PYPYDUMPOBJECT,
- ootype.String:jvmgen.PYPYDUMPSTRING,
- ootype.StringBuilder:jvmgen.PYPYDUMPOBJECT,
ootype.Void:jvmgen.PYPYDUMPVOID,
- ootype.Char:jvmgen.PYPYDUMPCHAR
+ ootype.Char:jvmgen.CHARTOSTRINGC,
+ ootype.String:jvmgen.PYPYESCAPEDSTRING,
}
- def generate_dump_method_for_ootype(self, OOTYPE):
+ def generate_toString_method_for_ootype(self, OOTYPE):
"""
Assuming than an instance of type OOTYPE is pushed on the
- stack, returns a Method object that you can invoke. This
- method will require that you also push an integer (usually 0)
- that represents the indentation, and then invoke it. i.e., you
- can do something like:
+ stack, returns a Method object that you can invoke. This method
+ will return a string representing the contents of that type.
+ Do something like:
+
> gen.load(var)
- > mthd = db.generate_dump_method_for_ootype(var.concretetype)
- > gen.emit(jvmgen.ICONST, 0)
+ > mthd = db.generate_toString_method_for_ootype(var.concretetype)
> mthd.invoke(gen)
to print the value of 'var'.
"""
- if OOTYPE in self._type_printing_methods:
- return self._type_printing_methods[OOTYPE]
- pclass = self.pending_class(OOTYPE)
- assert hasattr(pclass, 'dump_method'), "No dump_method for %r" % (OOTYPE, )
- return pclass.dump_method.method()
+ return self._toString_methods.get(OOTYPE, jvmgen.OBJTOSTRING)
# _________________________________________________________________
# Type translation functions
@@ -310,7 +303,8 @@
# will return a JvmBuiltInType based on the value
ootype_to_builtin = {
ootype.String: jvmtype.jString,
- ootype.StringBuilder: jvmtype.jStringBuilder
+ ootype.StringBuilder: jvmtype.jStringBuilder,
+ ootype.List: jvmtype.jArrayList
}
def lltype_to_cts(self, OOT):
@@ -324,6 +318,9 @@
return jObject
if OOT in self.ootype_to_builtin:
return JvmBuiltInType(self, self.ootype_to_builtin[OOT], OOT)
+ if OOT.__class__ in self.ootype_to_builtin:
+ return JvmBuiltInType(
+ self, self.ootype_to_builtin[OOT.__class__], OOT)
# Handle non-built-in-types:
if isinstance(OOT, ootype.Instance):
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:15:17 2007
@@ -6,7 +6,8 @@
from pypy.translator.jvm.typesystem import \
JvmType, jString, jInt, jLong, jDouble, jBool, jString, \
jPyPy, jVoid, jMath, desc_for_method, jPrintStream, jClass, jChar, \
- jObject, jByteArray, jPyPyExcWrap
+ jObject, jByteArray, jPyPyExcWrap, jIntegerClass, jLongClass, \
+ jDoubleClass, jCharClass, jStringBuilder
# ___________________________________________________________________________
# Miscellaneous helper functions
@@ -320,12 +321,19 @@
self.descriptor = desc_for_method(argtypesdesc, rettypedesc)
def invoke(self, gen):
gen._instr(self.opcode, self)
+ def is_static(self):
+ return self.opcode == INVOKESTATIC
def jasmin_syntax(self):
return "%s/%s%s" % (self.class_name.replace('.','/'),
self.method_name,
self.descriptor)
OBJHASHCODE = Method.v(jObject, 'hashCode', (), jInt)
+OBJTOSTRING = Method.v(jObject, 'toString', (), jString)
+INTTOSTRINGI = Method.s(jIntegerClass, 'toString', (jInt,), jString)
+LONGTOSTRINGL = Method.s(jLongClass, 'toString', (jLong,), jString)
+DOUBLETOSTRINGD = Method.s(jDoubleClass, 'toString', (jDouble,), jString)
+CHARTOSTRINGC = Method.s(jCharClass, 'toString', (jChar,), jString)
MATHIABS = Method.s(jMath, 'abs', (jInt,), jInt)
MATHLABS = Method.s(jMath, 'abs', (jLong,), jLong)
MATHDABS = Method.s(jMath, 'abs', (jDouble,), jDouble)
@@ -333,6 +341,8 @@
PRINTSTREAMPRINTSTR = Method.v(jPrintStream, 'print', (jString,), jVoid)
CLASSFORNAME = Method.s(jClass, 'forName', (jString,), jClass)
CLASSISASSIGNABLEFROM = Method.v(jClass, 'isAssignableFrom', (jClass,), jBool)
+PYPYAPPEND = Method.s(jPyPy, 'append',
+ (jStringBuilder, jString), jVoid)
PYPYUINTCMP = Method.s(jPyPy, 'uint_cmp', (jInt,jInt,), jInt)
PYPYULONGCMP = Method.s(jPyPy, 'ulong_cmp', (jLong,jLong), jInt)
PYPYUINTTODOUBLE = Method.s(jPyPy, 'uint_to_double', (jInt,), jDouble)
@@ -345,16 +355,11 @@
PYPYSTRTOBOOL = Method.s(jPyPy, 'str_to_bool', (jString,), jBool)
PYPYSTRTODOUBLE = Method.s(jPyPy, 'str_to_double', (jString,), jDouble)
PYPYSTRTOCHAR = Method.s(jPyPy, 'str_to_char', (jString,), jChar)
-PYPYDUMPINDENTED = Method.s(jPyPy, 'dump_indented', (jInt,jString,), jVoid)
-PYPYDUMPINT = Method.s(jPyPy, 'dump_int', (jInt,jInt), jVoid)
-PYPYDUMPCHAR = Method.s(jPyPy, 'dump_char', (jChar,jInt), jVoid)
-PYPYDUMPUINT = Method.s(jPyPy, 'dump_uint', (jInt,jInt), jVoid)
-PYPYDUMPLONG = Method.s(jPyPy, 'dump_long', (jLong,jInt), jVoid)
-PYPYDUMPDOUBLE = Method.s(jPyPy, 'dump_double', (jDouble,jInt), jVoid)
-PYPYDUMPSTRING = Method.s(jPyPy, 'dump_string', (jString,jInt), jVoid)
-PYPYDUMPBOOLEAN = Method.s(jPyPy, 'dump_boolean', (jBool,jInt), jVoid)
-PYPYDUMPOBJECT = Method.s(jPyPy, 'dump_object', (jObject,jInt,), jVoid)
-PYPYDUMPVOID = Method.s(jPyPy, 'dump_void', (jInt,), jVoid)
+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)
+PYPYESCAPEDSTRING = Method.s(jPyPy, 'escaped_string', (jString,), jString)
PYPYDUMPEXCWRAPPER = Method.s(jPyPy, 'dump_exc_wrapper', (jObject,), jVoid)
PYPYRUNTIMENEW = Method.s(jPyPy, 'RuntimeNew', (jClass,), jObject)
PYPYSTRING2BYTES = Method.s(jPyPy, 'string2bytes', (jString,), jByteArray)
@@ -653,6 +658,21 @@
jtype, jidx = self.curfunc.function_arguments[index]
self.load_jvm_var(jtype, jidx)
+ def box_value(self, jscalartype):
+ """ Assuming that an value of type jscalartype is on the stack,
+ boxes it into an Object. """
+ jclasstype = jscalartype.box_type
+ jmethod = Method.s(jclasstype, 'valueOf', (jscalartype,), jclasstype)
+ self.emit(jmethod)
+
+ def unbox_value(self, jscalartype):
+ """ Assuming that a boxed value of type jscalartype is on the stack,
+ unboxes it. """
+ jclasstype = jscalartype.box_type
+ jmethod = Method.v(
+ jclasstype, jscalartype.unbox_method, (), jscalartype)
+ self.emit(jmethod)
+
# __________________________________________________________________
# Exception Handling
@@ -732,6 +752,9 @@
if isinstance(instr, Method):
return instr.invoke(self)
+ if isinstance(instr, Field):
+ return instr.load(self)
+
raise Exception("Unknown object in call to emit(): "+repr(instr))
def _var_data(self, v):
@@ -774,6 +797,9 @@
def downcast(self, TYPE):
jtype = self.db.lltype_to_cts(TYPE)
+ self.downcast_jtype(jtype)
+
+ def downcast_jtype(self, jtype):
self._instr(CHECKCAST, jtype)
def instanceof(self, TYPE):
Modified: pypy/dist/pypy/translator/jvm/metavm.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/metavm.py (original)
+++ pypy/dist/pypy/translator/jvm/metavm.py Thu Jan 11 13:15:17 2007
@@ -1,5 +1,5 @@
from pypy.translator.oosupport.metavm import MicroInstruction
-
+from pypy.translator.jvm.typesystem import JvmScalarType, JvmClassType
class _IndirectCall(MicroInstruction):
def render(self, gen, op):
@@ -8,3 +8,52 @@
gen.emit(method)
IndirectCall = _IndirectCall()
+class _JvmCallMethod(MicroInstruction):
+
+ def _invoke_method(self, gen, db, jmethod, jactargs, args, jactres, res):
+ for arg, jmthdty in zip(args, jactargs):
+ jargty = db.lltype_to_cts(arg.concretetype)
+
+ # Load the argument on the stack:
+ gen.load(arg)
+
+ # Perform any boxing required:
+ if (isinstance(jargty, JvmScalarType) and
+ not isinstance(jmthdty, JvmScalarType)):
+ gen.box_value(jargty)
+
+ gen.emit(jmethod)
+
+ jresty = db.lltype_to_cts(res.concretetype)
+
+ if (isinstance(jresty, JvmScalarType) and
+ not isinstance(jactres, JvmScalarType)):
+ # Perform any un-boxing required:
+ gen.downcast_jtype(jresty.box_type)
+ gen.unbox_value(jresty)
+ elif jresty != jactres:
+ # Perform any casting required:
+ gen.downcast(res.concretetype)
+
+ def render(self, gen, op):
+
+ method = op.args[0] # a FlowConstant string...
+ this = op.args[1]
+
+ # Locate the java method we will be invoking:
+ thisjtype = gen.db.lltype_to_cts(this.concretetype)
+ jmethod = thisjtype.lookup_method(method.value)
+
+ # Ugly: if jmethod ends up being a static method, then
+ # peel off the first argument
+ jactargs = jmethod.argument_types
+ if jmethod.is_static():
+ jactargs = jactargs[1:]
+
+ # Iterate through the arguments, inserting casts etc as required
+ gen.load(this)
+ self._invoke_method(gen, gen.db, jmethod,
+ jactargs, op.args[2:],
+ jmethod.return_type, op.result)
+
+JvmCallMethod = _JvmCallMethod()
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:15:17 2007
@@ -14,11 +14,12 @@
"""
+from pypy.objspace.flow import model as flowmodel
from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.ootypesystem import ootype
+from pypy.rpython.ootypesystem import ootype, rclass
from pypy.translator.jvm.typesystem import \
JvmClassType, jString, jStringArray, jVoid, jThrowable, jInt, jPyPyMain, \
- jObject, JvmType
+ jObject, JvmType, jStringBuilder
from pypy.translator.jvm.opcodes import opcodes
from pypy.translator.jvm.option import getoption
from pypy.translator.oosupport.function import Function as OOFunction
@@ -112,15 +113,15 @@
#
if self.print_result:
done_printing = gen.unique_label('done_printing')
- gen.emit(jvmgen.ICONST, 0)
RESOOTYPE = self.graph.getreturnvar().concretetype
- dumpmethod = self.db.generate_dump_method_for_ootype(RESOOTYPE)
- dumpmethod.invoke(gen)
+ dumpmethod = self.db.generate_toString_method_for_ootype(RESOOTYPE)
+ gen.emit(dumpmethod) # generate the string
+ gen.emit(jvmgen.PYPYDUMP) # dump to stdout
gen.goto(done_printing)
gen.end_try()
gen.begin_catch(jObject)
- gen.emit(jvmgen.PYPYDUMPEXCWRAPPER)
+ gen.emit(jvmgen.PYPYDUMPEXCWRAPPER) # dumps to stdout
gen.end_catch()
gen.mark(done_printing)
@@ -204,13 +205,37 @@
self.ilasm.end_try()
def begin_catch(self, llexitcase):
- unimplemented
-
- def end_catch(self, llexitcase):
- unimplemented
+ ll_meta_exc = llexitcase
+ ll_exc = ll_meta_exc._inst.class_._INSTANCE
+ cts_exc = self.cts.lltype_to_cts(ll_exc)
+ self.ilasm.begin_catch(cts_exc)
+
+ def end_catch(self, exit_lbl):
+ self.ilasm.goto(exit_lbl)
+ self.ilasm.end_catch()
def store_exception_and_link(self, link):
- unimplemented
+ if self._is_raise_block(link.target):
+ # the exception value is on the stack, use it as the 2nd target arg
+ assert len(link.args) == 2
+ assert len(link.target.inputargs) == 2
+ self.ilasm.store(link.target.inputargs[1])
+ 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.store(link.last_exc_value)
+ fld = jvmgen.Field(
+ self.db.lltype_to_cts(rclass.CLASSTYPE).name,
+ 'meta',
+ self.db.lltype_to_cts(rclass.OBJECT),
+ False,
+ rclass.OBJECT)
+ self.ilasm.emit(fld)
+ self.ilasm.store(link.last_exception)
+ else:
+ self.ilasm.store(link.last_exc_value)
+ self._setup_link(link)
def render_return_block(self, block):
return_var = block.inputargs[0]
@@ -414,57 +439,45 @@
self.db = db
self.OOCLASS = OOCLASS
self.clsobj = clsobj
- self.name = "_pypy_dump"
- self.jargtypes = [clsobj, jInt]
- self.jrettype = jVoid
-
- def method(self):
- """ Returns a jvmgen.Method that can invoke this function """
- return jvmgen.Method.v(
- self.clsobj, self.name, self.jargtypes[1:], self.jrettype)
-
- def _increase_indent(self, gen):
- gen.load_jvm_var(jInt, 1)
- gen.emit(jvmgen.ICONST, 2)
- gen.emit(jvmgen.IADD)
- gen.store_jvm_var(jInt, 1)
-
- def _print_field_value(self, gen, fieldnm, FIELDOOTY):
- gen.load_this_ptr()
+ self.name = "toString"
+ self.jargtypes = [clsobj]
+ self.jrettype = jString
+
+ def _print_field_value(self, fieldnm, FIELDOOTY):
+ self.gen.emit(jvmgen.DUP)
+ self.gen.load_this_ptr()
fieldobj = self.clsobj.lookup_field(fieldnm)
- fieldobj.load(gen)
- gen.load_jvm_var(jInt, 1)
- dumpmethod = self.db.generate_dump_method_for_ootype(FIELDOOTY)
- gen.emit(dumpmethod)
+ fieldobj.load(self.gen)
+ dumpmethod = self.db.generate_toString_method_for_ootype(FIELDOOTY)
+ self.gen.emit(dumpmethod)
+ self.gen.emit(jvmgen.PYPYAPPEND)
+
+ def _print(self, str):
+ self.gen.emit(jvmgen.DUP)
+ self.gen.load_string(str)
+ self.gen.emit(jvmgen.PYPYAPPEND)
def render(self, gen):
+ self.gen = gen
gen.begin_function(
self.name, (), self.jargtypes, self.jrettype, static=False)
- def genprint(str, unoffset=0):
- gen.load_jvm_var(jInt, 1)
- if unoffset:
- gen.emit(jvmgen.ICONST, unoffset)
- gen.emit(jvmgen.ISUB)
- gen.load_string(str)
- jvmgen.PYPYDUMPINDENTED.invoke(gen)
-
- self._render_guts(gen, genprint)
-
- gen.emit(jvmgen.RETURN.for_type(jVoid))
+ gen.new_with_jtype(jStringBuilder)
+ self._render_guts(gen)
+ gen.emit(jvmgen.OBJTOSTRING)
+ gen.emit(jvmgen.RETURN.for_type(jString))
gen.end_function()
+ self.gen = None
class InstanceDumpMethod(BaseDumpMethod):
- def _render_guts(self, gen, genprint):
+ def _render_guts(self, gen):
clsobj = self.clsobj
+ genprint = self._print
# Start the dump
genprint("InstanceWrapper([")
- # Increment the indent
- self._increase_indent(gen)
-
for fieldnm, (FIELDOOTY, fielddef) in self.OOCLASS._fields.iteritems():
if FIELDOOTY is ootype.Void: continue
@@ -475,24 +488,31 @@
print "fieldnm=%r fieldty=%r" % (fieldnm, FIELDOOTY)
# Print the value of the field:
- self._print_field_value(gen, fieldnm, FIELDOOTY)
+ self._print_field_value(fieldnm, FIELDOOTY)
genprint(")")
- # Decrement indent and dump close
- genprint("])", 2)
+ # Dump close
+ genprint("])")
class RecordDumpMethod(BaseDumpMethod):
- def _render_guts(self, gen, genprint):
+ def _render_guts(self, gen):
clsobj = self.clsobj
+ genprint = self._print
+
+ # We only render records that represent tuples:
+ # In that case, the field names look like item0, item1, etc
+ # Otherwise, we just do nothing... this is because we
+ # never return records that do not represent tuples from
+ # a testing function
+ for f_name in self.OOCLASS._fields:
+ if not f_name.startswith('item'):
+ return
# Start the dump
genprint("StructTuple((")
- # Increment the indent
- self._increase_indent(gen)
-
numfields = len(self.OOCLASS._fields)
for i in range(numfields):
f_name = 'item%d' % i
@@ -501,11 +521,11 @@
continue
# Print the value of the field:
- self._print_field_value(gen, f_name, FIELD_TYPE)
+ self._print_field_value(f_name, FIELD_TYPE)
genprint(',')
# Decrement indent and dump close
- genprint("))", 2)
+ genprint("))")
class ConstantStringDumpMethod(BaseDumpMethod):
""" Just prints out a string """
@@ -514,5 +534,6 @@
BaseDumpMethod.__init__(self, None, None, clsobj)
self.constant_string = str
- def _render_guts(self, gen, genprint):
+ def _render_guts(self, gen):
+ genprint = self._print
genprint("'" + self.constant_string + "'")
Modified: pypy/dist/pypy/translator/jvm/opcodes.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/opcodes.py (original)
+++ pypy/dist/pypy/translator/jvm/opcodes.py Thu Jan 11 13:15:17 2007
@@ -7,9 +7,9 @@
from pypy.translator.oosupport.metavm import \
PushArg, PushAllArgs, StoreResult, InstructionList, New, DoNothing, Call,\
- SetField, GetField, CallMethod, DownCast, RuntimeNew, OOString, CastTo
+ SetField, GetField, DownCast, RuntimeNew, OOString, CastTo
from pypy.translator.jvm.metavm import \
- IndirectCall
+ IndirectCall, JvmCallMethod
import pypy.translator.jvm.generator as jvmgen
def _check_zer(op):
@@ -28,7 +28,7 @@
'runtimenew': [RuntimeNew, StoreResult],
'oosetfield': [SetField],
'oogetfield': [GetField, StoreResult],
- 'oosend': [CallMethod, StoreResult],
+ 'oosend': [JvmCallMethod, StoreResult],
'ooupcast': DoNothing,
'oodowncast': [DownCast, StoreResult],
'oois': 'ref_is_eq',
@@ -51,6 +51,8 @@
#'gc__collect': 'call void class [mscorlib]System.GC::Collect()',
#'resume_point': Ignore,
+ 'debug_assert': [], # TODO: implement?
+
# __________ numeric operations __________
'bool_not': 'logical_not',
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:15:17 2007
@@ -188,47 +188,30 @@
// Used in testing:
- public static void dump_indented(int indent, String text) {
- for (int i = 0; i < indent; i++)
- System.out.print(" ");
+ public static void dump(String text) {
System.out.println(text);
}
- public static void dump_void(int indent) {
+ public static String dump_void() {
+ return "None";
}
- public static void dump_int(int i, int indent) {
- dump_indented(indent, Integer.toString(i));
- }
-
- public static void dump_char(char c, int indent) {
- dump_indented(indent, "'"+c+"'");
- }
-
- public static void dump_uint(int i, int indent) {
+ public static String dump_uint(int i) {
if (i >= 0)
- dump_indented(indent, Integer.toString(i));
+ return Integer.toString(i);
else {
int loword = i & 0xFFFF;
int hiword = i >>> 16;
long res = loword + (hiword*0xFFFF);
- dump_indented(indent, Long.toString(res));
+ return Long.toString(res);
}
}
- public static void dump_boolean(boolean l, int indent) {
+ public static String dump_boolean(boolean l) {
if (l)
- dump_indented(indent, "True");
+ return "True";
else
- dump_indented(indent, "False");
- }
-
- public static void dump_long(long l, int indent) {
- dump_indented(indent, Long.toString(l));
- }
-
- public static void dump_double(double d, int indent) {
- dump_indented(indent, Double.toString(d));
+ return "False";
}
public static void _append_char(StringBuffer sb, char c) {
@@ -238,17 +221,6 @@
sb.append(c);
}
- public static void dump_string(byte[] b, int indent) {
- StringBuffer sb = new StringBuffer();
- sb.append('"');
- for (byte _c : b) {
- char c = (char)_c;
- _append_char(sb, c);
- }
- sb.append('"');
- dump_indented(indent, sb.toString());
- }
-
public static String escaped_string(String b) {
StringBuffer sb = new StringBuffer();
sb.append('"');
@@ -260,14 +232,6 @@
return sb.toString();
}
- public static void dump_string(String b, int indent) {
- dump_indented(indent, escaped_string(b));
- }
-
- public static void dump_object(Object o, int indent) {
- dump_indented(indent, o.toString());
- }
-
// used in running unit tests
// not really part of the dump_XXX set of objects, hence the lack
// of an indent parameter
@@ -277,7 +241,7 @@
sb.append("ExceptionWrapper(");
sb.append(escaped_string(clnm));
sb.append(")");
- dump_indented(0, sb.toString());
+ dump(sb.toString());
}
// ----------------------------------------------------------------------
@@ -330,6 +294,11 @@
return s.getBytes();
}
+ public static void append(StringBuilder sb, String s) {
+ // avoid the annoying return value of StringBuilder.append
+ sb.append(s);
+ }
+
// ----------------------------------------------------------------------
// OOString support
@@ -395,6 +364,34 @@
*/
// ----------------------------------------------------------------------
+ // Lists
+
+ public static void ll_setitem_fast(ArrayList self, int index, Object val)
+ {
+ // need a wrapper because set returns the old value
+ self.set(index, val);
+ }
+
+ public static void _ll_resize_ge(ArrayList self, int length) {
+ while (self.size() < length) {
+ self.add(null);
+ }
+ }
+
+ public static void _ll_resize_le(ArrayList self, int length) {
+ while (self.size() > length) {
+ self.remove(self.size()-1);
+ }
+ }
+
+ public static void _ll_resize(ArrayList self, int length) {
+ if (length > self.size())
+ _ll_resize_ge(self, length);
+ else if (length < self.size())
+ _ll_resize_le(self, length);
+ }
+
+ // ----------------------------------------------------------------------
// Self Test
public static int __counter = 0, __failures = 0;
Added: pypy/dist/pypy/translator/jvm/test/test_list.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/jvm/test/test_list.py Thu Jan 11 13:15:17 2007
@@ -0,0 +1,10 @@
+import py
+from pypy.translator.jvm.test.runtest import JvmTest
+from pypy.rpython.test.test_rlist import BaseTestRlist
+
+class TestJvmList(JvmTest, BaseTestRlist):
+ #def test_recursive(self):
+ # py.test.skip("JVM doesn't support recursive lists")
+ #
+ def test_getitem_exc(self):
+ py.test.skip('fixme!')
Added: pypy/dist/pypy/translator/jvm/test/test_pbc.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/jvm/test/test_pbc.py Thu Jan 11 13:15:17 2007
@@ -0,0 +1,6 @@
+import py
+from pypy.translator.jvm.test.runtest import JvmTest
+from pypy.rpython.test.test_rpbc import BaseTestRPBC
+
+class TestCliPBC(JvmTest, BaseTestRPBC):
+ pass
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:15:17 2007
@@ -128,24 +128,6 @@
def __repr__(self):
return "%s<%s>" % (self.__class__.__name__, self.descriptor)
-class JvmScalarType(JvmType):
- """
- Subclass used for all scalar type instances.
- """
- def __init__(self, descrstr):
- JvmType.__init__(self, JvmTypeDescriptor(descrstr))
- def lookup_field(self, fieldnm):
- raise KeyError(fieldnm) # Scalar objects have no fields
- def lookup_method(self, methodnm):
- raise KeyError(methodnm) # Scalar objects have no methods
-
-jVoid = JvmScalarType('V')
-jInt = JvmScalarType('I')
-jLong = JvmScalarType('J')
-jBool = JvmScalarType('Z')
-jDouble = JvmScalarType('D')
-jByte = JvmScalarType('B')
-jChar = JvmScalarType('C')
class JvmClassType(JvmType):
"""
Base class used for all class instances. Kind of an abstract class;
@@ -161,6 +143,10 @@
def lookup_method(self, methodnm):
raise KeyError(fieldnm) # we treat as opaque type
+jIntegerClass = JvmClassType('java.lang.Integer')
+jLongClass = JvmClassType('java.lang.Long')
+jDoubleClass = JvmClassType('java.lang.Double')
+jCharClass = JvmClassType('java.lang.Char')
jThrowable = JvmClassType('java.lang.Throwable')
jObject = JvmClassType('java.lang.Object')
jString = JvmClassType('java.lang.String')
@@ -172,11 +158,32 @@
jPrintStream = JvmClassType('java.io.PrintStream')
jMath = JvmClassType('java.lang.Math')
jList = JvmClassType('java.util.List')
+jArrayList = JvmClassType('java.util.ArrayList')
jPyPy = JvmClassType('pypy.PyPy')
jPyPyExcWrap = JvmClassType('pypy.ExceptionWrapper')
jPyPyConst = JvmClassType('pypy.Constant')
jPyPyMain = JvmClassType('pypy.Main')
+class JvmScalarType(JvmType):
+ """
+ Subclass used for all scalar type instances.
+ """
+ def __init__(self, descrstr, boxtype, unboxmethod):
+ JvmType.__init__(self, JvmTypeDescriptor(descrstr))
+ self.box_type = boxtype
+ self.unbox_method = unboxmethod
+ def lookup_field(self, fieldnm):
+ raise KeyError(fieldnm) # Scalar objects have no fields
+ def lookup_method(self, methodnm):
+ raise KeyError(methodnm) # Scalar objects have no methods
+jVoid = JvmScalarType('V', None, None)
+jInt = JvmScalarType('I', jIntegerClass, 'intValue')
+jLong = JvmScalarType('J', jLongClass, 'longValue')
+jBool = JvmScalarType('Z', jIntegerClass, 'intValue')
+jDouble = JvmScalarType('D', jDoubleClass, 'doubleValue')
+jByte = JvmScalarType('B', jIntegerClass, 'intValue')
+jChar = JvmScalarType('C', jIntegerClass, 'intValue')
+
class JvmArrayType(JvmType):
"""
Subclass used for all array instances.
More information about the Pypy-commit
mailing list