[pypy-svn] r36479 - in pypy/dist/pypy/translator/jvm: . src

niko at codespeak.net niko at codespeak.net
Thu Jan 11 15:03:32 CET 2007


Author: niko
Date: Thu Jan 11 15:03:32 2007
New Revision: 36479

Modified:
   pypy/dist/pypy/translator/jvm/builtin.py
   pypy/dist/pypy/translator/jvm/generator.py
   pypy/dist/pypy/translator/jvm/genjvm.py
   pypy/dist/pypy/translator/jvm/metavm.py
   pypy/dist/pypy/translator/jvm/node.py
   pypy/dist/pypy/translator/jvm/src/PyPy.java
Log:
(antocuni,niko) fix a variety of errors in test_list

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:03:32 2007
@@ -2,7 +2,8 @@
 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, jArrayList, jObject
+     jInt, jVoid, jStringBuilder, jString, jPyPy, jChar, jArrayList, jObject, \
+     jBool
 
 # ______________________________________________________________________
 # Mapping of built-in OOTypes to JVM types
@@ -59,25 +60,18 @@
         # Lookup the generic method by name.
         GENMETH = self.OOTYPE._GENERIC_METHODS[methodnm]
 
-        # Create an array with the Java version of each type in the
-        # argument list and return type.
-        jargtypes = [self._map(P) for P in GENMETH.ARGS]
+        # By default, we assume it is a static method on the PyPy
+        # object, that takes an instance of this object as the first
+        # argument.  The other arguments we just convert to java versions,
+        # except for generics.
+        jargtypes = [self] + [self._map(P) for P in GENMETH.ARGS]
         jrettype = self._map(GENMETH.RESULT)
-        return jvmgen.Method.v(self, methodnm, jargtypes, jrettype)
+        return jvmgen.Method.s(jPyPy, methodnm, jargtypes, jrettype)
 
 # When we lookup a method on a  BuiltInClassNode, we first check
 # the 'built_in_methods' table.  This allows us to redirect to other
 # methods if we like.
 
-def _ll_build_method():
-    # Choose an appropriate ll_build depending on what representation
-    # we are using for ootype.String:
-    if True: # XXX db.using_byte_array...
-        return jvmgen.Method.v(
-            jStringBuilder, "toString", (),jString)
-    return jvmgen.Method.s(
-        jvmgen.PYPYJAVA, "ll_build", (jStringBuilder,), jOOString)
-
 built_in_methods = {
 
     # Note: String and StringBuilder are rebound in ootype, and thus
@@ -86,14 +80,11 @@
     (ootype.StringBuilder.__class__, "ll_allocate"):
     jvmgen.Method.v(jStringBuilder, "ensureCapacity", (jInt,), jVoid),
     
-    (ootype.StringBuilder.__class__, "ll_append_char"):
-    jvmgen.Method.s(jPyPy, "ll_append_char", (jStringBuilder, jChar), jVoid),
-    
-    (ootype.StringBuilder.__class__, "ll_append"):
-    jvmgen.Method.s(jPyPy, "ll_append", (jStringBuilder, jString), jVoid),
-
     (ootype.StringBuilder.__class__, "ll_build"):
-     _ll_build_method(),
+    jvmgen.Method.v(jStringBuilder, "toString", (), jString),
+
+    (ootype.String.__class__, "ll_streq"):
+    jvmgen.Method.v(jString, "equals", (jObject,), jBool),
 
     (ootype.List, "ll_length"):
     jvmgen.Method.v(jArrayList, "size", (), jInt),
@@ -101,17 +92,4 @@
     (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/generator.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/generator.py	(original)
+++ pypy/dist/pypy/translator/jvm/generator.py	Thu Jan 11 15:03:32 2007
@@ -2,7 +2,9 @@
 from pypy.objspace.flow import model as flowmodel
 from pypy.translator.oosupport.metavm import Generator
 from pypy.rpython.ootypesystem import ootype
+from pypy.rlib.objectmodel import CDefinedIntSymbolic
 from pypy.translator.oosupport.constant import push_constant
+import pypy.translator.jvm.typesystem as jvmtype
 from pypy.translator.jvm.typesystem import \
      JvmType, jString, jInt, jLong, jDouble, jBool, jString, \
      jPyPy, jVoid, jMath, desc_for_method, jPrintStream, jClass, jChar, \
@@ -320,7 +322,7 @@
         rettypedesc = rettype.descriptor
         self.descriptor = desc_for_method(argtypesdesc, rettypedesc)  
     def invoke(self, gen):
-        gen._instr(self.opcode, self)
+        gen._instr(self.opcode, self)        
     def is_static(self):
         return self.opcode == INVOKESTATIC
     def jasmin_syntax(self):
@@ -661,9 +663,23 @@
 
     def prepare_generic_argument(self, ITEMTYPE):
         jty = self.db.lltype_to_cts(ITEMTYPE)
-        if isinstance(jty, JvmScalarType):
+        if jty is jvmtype.jVoid:
+            self.emit(ACONST_NULL)
+        elif isinstance(jty, JvmScalarType):
             self.box_value(jty)
 
+    def prepare_generic_result(self, ITEMTYPE):
+        jresty = self.db.lltype_to_cts(ITEMTYPE)
+        if jresty is jvmtype.jVoid:
+            self.emit(POP)
+        elif isinstance(jresty, JvmScalarType):
+            # Perform any un-boxing required:
+            self.downcast_jtype(jresty.box_type)
+            self.unbox_value(jresty)
+        elif jresty != jactres:
+            # Perform any casting required:
+            self.downcast(ITEMTYPE)
+
     def box_value(self, jscalartype):
         """ Assuming that an value of type jscalartype is on the stack,
         boxes it into an Object. """
@@ -839,14 +855,15 @@
 
     def call_oostring(self, OOTYPE):
         cts_type = self.db.lltype_to_cts(OOTYPE)
-        if cts_type != jByteArray:
-            mthd = Method.s(jPyPy, 'oostring', [cts_type, jInt], jString)
-            self.emit(mthd)
-            if self.db.using_byte_array:
-                self.emit(PYPYSTRING2BYTES)
-        else:
-            mthd = Method.s(jPyPy, 'oostring',
-                            [jByteArray, jInt], jByteArray)
+
+        # treat all objects the same:
+        if isinstance(cts_type, jvmtype.JvmClassType):
+            cts_type = jObject
+            
+        mthd = Method.s(jPyPy, 'oostring', [cts_type, jInt], jString)
+        self.emit(mthd)
+        if self.db.using_byte_array:
+            self.emit(PYPYSTRING2BYTES)
         
     def new(self, TYPE):
         jtype = self.db.lltype_to_cts(TYPE)
@@ -883,9 +900,13 @@
     def push_null(self, OOTYPE):
         self.emit(ACONST_NULL)
 
+    DEFINED_INT_SYMBOLICS = {'MALLOC_ZERO_FILLED':1}
+                            
     def push_primitive_constant(self, TYPE, value):
         if TYPE is ootype.Void:
             return
+        elif isinstance(value, CDefinedIntSymbolic):
+            self.emit(ICONST, self.DEFINED_INT_SYMBOLICS[value.expr])
         elif TYPE in (ootype.Bool, ootype.Signed):
             self.emit(ICONST, int(value))
         elif TYPE is ootype.Unsigned:
@@ -901,7 +922,7 @@
         elif TYPE is ootype.Float:
             self._push_double_constant(float(value))
         elif TYPE is ootype.String:
-            self.load_string(str(value))
+            self.load_string(str(value._str))
 
     def _push_long_constant(self, value):
         if value == 0:

Modified: pypy/dist/pypy/translator/jvm/genjvm.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/genjvm.py	(original)
+++ pypy/dist/pypy/translator/jvm/genjvm.py	Thu Jan 11 15:03:32 2007
@@ -114,9 +114,9 @@
         Compiles the .java sources into .class files, ready for execution.
         """
         jascmd = [getoption('jasmin'), '-d', str(self.javadir)]
-        for jasfile in self.jasmin_files:
-            print "Invoking jasmin on %s" % jasfile
-            self._invoke(jascmd+[jasfile], False)
+
+        print "Invoking jasmin on %s" % self.jasmin_files
+        self._invoke(jascmd+list(self.jasmin_files), False)
                            
         self.compiled = True
         self._compile_helper('PyPy')

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 15:03:32 2007
@@ -1,5 +1,7 @@
 from pypy.translator.oosupport.metavm import MicroInstruction
 from pypy.translator.jvm.typesystem import JvmScalarType, JvmClassType
+import pypy.translator.jvm.generator as jvmgen
+import pypy.translator.jvm.typesystem as jvmtype
 
 class _IndirectCall(MicroInstruction):
     def render(self, gen, op):
@@ -12,28 +14,20 @@
 
     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)
+            jargty = db.lltype_to_cts(arg.concretetype)
+            if jargty != jmthdty:
+                gen.prepare_generic_argument(arg.concretetype)
                 
         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)
+        # Perform any unboxing required:
+        jresty = db.lltype_to_cts(res.concretetype)
+        if jresty != jactres:
+            gen.prepare_generic_result(res.concretetype)
     
     def render(self, gen, op):
 

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:03:32 2007
@@ -249,15 +249,31 @@
         self.ilasm.load(exc)
         self.ilasm.throw()
 
+    def _trace(self, str):
+        jvmgen.SYSTEMERR.load(self.generator)
+        self.generator.load_string(str)
+        jvmgen.PRINTSTREAMPRINTSTR.invoke(self.generator)
+
     def _render_op(self, op):
         self.generator.add_comment(str(op))
         
         if getoption('trace'):
+            self._trace(str(op)+"\n")
+
+        OOFunction._render_op(self, op)
+
+        if (getoption('trace')
+            and op.result
+            and op.result.concretetype is not ootype.Void):
+            self._trace("  Result: ")
+            res = op.result
+            jmethod = self.db.generate_toString_method_for_ootype(
+                res.concretetype)
             jvmgen.SYSTEMERR.load(self.generator)
-            self.generator.load_string(str(op) + "\n")
+            self.generator.load(res)
+            self.generator.emit(jmethod)
             jvmgen.PRINTSTREAMPRINTSTR.invoke(self.generator)
-            
-        OOFunction._render_op(self, op)
+            self._trace("\n")
 
 class StaticMethodInterface(Node, JvmClassType):
     """

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:03:32 2007
@@ -253,6 +253,13 @@
     }
 
     // ----------------------------------------------------------------------
+    // String
+
+    public static String ll_strconcat(String str1, String str2) {
+        return str1 + str2;
+    }
+
+    // ----------------------------------------------------------------------
     // StringBuffer
 
     public static void ll_append_char(StringBuilder sb, char c) {
@@ -326,7 +333,11 @@
 
     public static String oostring(Object obj, int base_)
     {
-        return String.format("<%s object>", new Object[] { obj.getClass().getName() });
+        String clnm = obj.getClass().getName();
+        int underscore = clnm.lastIndexOf('_');
+        // strip "pypy." from the start, and _NN from the end
+        clnm = clnm.substring(5, underscore);
+        return String.format("<%s object>", new Object[] { clnm });
     }
 
     public static String oostring(char ch, int base_)



More information about the Pypy-commit mailing list