[pypy-svn] r36566 - in pypy/dist/pypy: config translator translator/jvm translator/jvm/src/pypy

antocuni at codespeak.net antocuni at codespeak.net
Fri Jan 12 13:45:54 CET 2007


Author: antocuni
Date: Fri Jan 12 13:45:53 2007
New Revision: 36566

Modified:
   pypy/dist/pypy/config/translationoption.py
   pypy/dist/pypy/translator/driver.py
   pypy/dist/pypy/translator/jvm/generator.py
   pypy/dist/pypy/translator/jvm/node.py
   pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
   pypy/dist/pypy/translator/jvm/typesystem.py
Log:
(antocuni, niko)

Add jvm backend to translate.py.
Fix bugs in the standalone entrypoint of jvm backend.



Modified: pypy/dist/pypy/config/translationoption.py
==============================================================================
--- pypy/dist/pypy/config/translationoption.py	(original)
+++ pypy/dist/pypy/config/translationoption.py	Fri Jan 12 13:45:53 2007
@@ -11,13 +11,14 @@
     ChoiceOption("type_system", "Type system to use when RTyping",
                  ["lltype", "ootype"], cmdline=None),
     ChoiceOption("backend", "Backend to use for code generation",
-                 ["c", "llvm", "cli", "js", "squeak", "cl"],
+                 ["c", "llvm", "cli", "jvm", "js", "squeak", "cl"],
                  requires={
                      "c":      [("translation.type_system", "lltype")],
                      "llvm":   [("translation.type_system", "lltype"),
                                 ("translation.gc", "boehm"),
                                 ("translation.backendopt.raisingop2direct_call", True)],
                      "cli":    [("translation.type_system", "ootype")],
+                     "jvm":    [("translation.type_system", "ootype")],
                      "js":     [("translation.type_system", "ootype")],
                      "squeak": [("translation.type_system", "ootype")],
                      "cl":     [("translation.type_system", "ootype")],

Modified: pypy/dist/pypy/translator/driver.py
==============================================================================
--- pypy/dist/pypy/translator/driver.py	(original)
+++ pypy/dist/pypy/translator/driver.py	Fri Jan 12 13:45:53 2007
@@ -620,7 +620,29 @@
         pass
     task_run_cli = taskdef(task_run_cli, ['compile_cli'],
                               'XXX')
+    
+    def task_source_jvm(self):
+        from pypy.translator.jvm.genjvm import GenJvm
+        from pypy.translator.jvm.node import EntryPoint
+
+        entry_point_graph = self.translator.graphs[0]
+        entry_point = EntryPoint(entry_point_graph, False, False)
+        self.gen = GenJvm(udir, self.translator, entry_point)
+        self.jvmsource = self.gen.generate_source()
+        self.log.info("Wrote JVM code")
+    task_source_jvm = taskdef(task_source_jvm, ["?" + OOBACKENDOPT, OOTYPE],
+                             'Generating JVM source')
+
+    def task_compile_jvm(self):
+        self.jvmsource.compile()
+        self.log.info("Compiled JVM source")
+    task_compile_jvm = taskdef(task_compile_jvm, ['source_jvm'],
+                              'Compiling JVM source')
 
+    def task_run_jvm(self):
+        pass
+    task_run_jvm = taskdef(task_run_jvm, ['compile_jvm'],
+                           'XXX')
 
     def proceed(self, goals):
         if not goals:

Modified: pypy/dist/pypy/translator/jvm/generator.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/generator.py	(original)
+++ pypy/dist/pypy/translator/jvm/generator.py	Fri Jan 12 13:45:53 2007
@@ -9,7 +9,8 @@
      JvmType, jString, jInt, jLong, jDouble, jBool, jString, \
      jPyPy, jVoid, jMath, desc_for_method, jPrintStream, jClass, jChar, \
      jObject, jByteArray, jPyPyExcWrap, jIntegerClass, jLongClass, \
-     jDoubleClass, jCharClass, jStringBuilder, JvmScalarType
+     jDoubleClass, jCharClass, jStringBuilder, JvmScalarType, jArrayList, \
+     jObjectArray
 
 # ___________________________________________________________________________
 # Miscellaneous helper functions
@@ -370,6 +371,7 @@
 PYPYDUMPEXCWRAPPER =    Method.s(jPyPy, 'dump_exc_wrapper', (jObject,), jVoid)
 PYPYRUNTIMENEW =        Method.s(jPyPy, 'RuntimeNew', (jClass,), jObject)
 PYPYSTRING2BYTES =      Method.s(jPyPy, 'string2bytes', (jString,), jByteArray)
+PYPYARRAYTOLIST =       Method.s(jPyPy, 'array_to_list', (jObjectArray,), jArrayList)
 OBJECTGETCLASS =        Method.v(jObject, 'getClass', (), jClass)
 CLASSGETNAME =          Method.v(jClass, 'getName', (), jString)
 EXCWRAPWRAP =           Method.s(jPyPyExcWrap, 'wrap', (jObject,), jPyPyExcWrap)

Modified: pypy/dist/pypy/translator/jvm/node.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/node.py	(original)
+++ pypy/dist/pypy/translator/jvm/node.py	Fri Jan 12 13:45:53 2007
@@ -111,8 +111,8 @@
             # python method expects
             arg0 = self.graph.getargs()[0]
             assert isinstance(arg0.concretetype, ootype.List), str(arg0.concretetype)
-            assert arg0._ITEMTYPE is ootype.String
-            gen.load_jvm_var(0)
+            assert arg0.concretetype._ITEMTYPE is ootype.String
+            gen.load_jvm_var(jStringArray, 0)
             gen.emit(jvmgen.PYPYARRAYTOLIST)
 
         # Generate a call to this method

Modified: pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
==============================================================================
--- pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java	(original)
+++ pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java	Fri Jan 12 13:45:53 2007
@@ -3,6 +3,7 @@
 import java.util.List;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Arrays;
 
 /**
  * Class with a number of utility routines.
@@ -115,14 +116,6 @@
         return ~value;
     }
 
-    public static List<?> array_to_list(Object[] array) {
-        List l = new ArrayList();
-        for (Object o : array) {
-            l.add(o);
-        }
-        return l;
-    }
-
     public static int str_to_int(String s) {
         try {
             return Integer.parseInt(s);
@@ -430,6 +423,11 @@
         sb.append(s);
     }
 
+    public static ArrayList array_to_list(Object[] array)
+    {
+        return new ArrayList(java.util.Arrays.asList(array));
+    }
+
     // ----------------------------------------------------------------------
     // OOString support
     
@@ -573,4 +571,4 @@
         
         System.out.println("Total Failures: "+__failures);
     }
-}
\ No newline at end of file
+}

Modified: pypy/dist/pypy/translator/jvm/typesystem.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/typesystem.py	(original)
+++ pypy/dist/pypy/translator/jvm/typesystem.py	Fri Jan 12 13:45:53 2007
@@ -154,6 +154,7 @@
 jString = JvmClassType('java.lang.String')
 jCharSequence = JvmClassType('java.lang.CharSequence')
 jArrayList = JvmClassType('java.util.ArrayList')
+jArrays = JvmClassType('java.util.Arrays')
 jHashMap = JvmClassType('java.util.HashMap')
 jIterator = JvmClassType('java.util.Iterator')
 jClass = JvmClassType('java.lang.Class')



More information about the Pypy-commit mailing list